Added python class scan

This commit is contained in:
Sven Heidemann 2022-01-16 00:52:25 +01:00
parent 156ad6f8b3
commit 2be818fcc1
6 changed files with 90 additions and 2 deletions

View File

@ -5,9 +5,11 @@ from cpl_core.configuration import ConfigurationABC, ConsoleArgument
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
from cpl_core.environment import ApplicationEnvironment from cpl_core.environment import ApplicationEnvironment
from py_to_uxf_core.abc.class_scanner_abc import ClassScannerABC
from py_to_uxf_core.abc.file_scanner_abc import FileScannerABC from py_to_uxf_core.abc.file_scanner_abc import FileScannerABC
from py_to_uxf_core.abc.python_parser_abc import PythonParserABC from py_to_uxf_core.abc.python_parser_abc import PythonParserABC
from py_to_uxf_core.abc.umlet_creator_abc import UmletCreatorABC from py_to_uxf_core.abc.umlet_creator_abc import UmletCreatorABC
from py_to_uxf_core.service.class_scanner_service import ClassScannerService
from py_to_uxf_core.service.file_scanner_service import FileScannerService from py_to_uxf_core.service.file_scanner_service import FileScannerService
from py_to_uxf_core.service.python_parser_service import PythonParserService from py_to_uxf_core.service.python_parser_service import PythonParserService
from py_to_uxf_core.service.umlet_creator_service import UmletCreatorService from py_to_uxf_core.service.umlet_creator_service import UmletCreatorService
@ -26,6 +28,7 @@ class Startup(StartupABC):
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC: def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
services.add_transient(FileScannerABC, FileScannerService) services.add_transient(FileScannerABC, FileScannerService)
services.add_transient(ClassScannerABC, ClassScannerService)
services.add_singleton(PythonParserABC, PythonParserService) services.add_singleton(PythonParserABC, PythonParserService)
services.add_singleton(UmletCreatorABC, UmletCreatorService) services.add_singleton(UmletCreatorABC, UmletCreatorService)

View File

@ -0,0 +1,15 @@
from abc import ABC, abstractmethod
from typing import Optional
from cpl_query.extension import List
from py_to_uxf_core.model.python_class import PythonClass
class ClassScannerABC(ABC):
@abstractmethod
def __init__(self): pass
@abstractmethod
def scan_line_for_classes(self, line: str) -> Optional[PythonClass]: pass

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
py_to_uxf
~~~~~~~~~~~~~~~~~~~
:copyright: (c)
:license:
"""
__title__ = 'py_to_uxf_core.model'
__author__ = ''
__license__ = ''
__copyright__ = 'Copyright (c) '
__version__ = '0.0.0'
from collections import namedtuple
# imports
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='0', minor='0', micro='0')

View File

@ -0,0 +1,8 @@
class PythonClass:
def __init__(self, name):
self._name = name
@property
def name(self) -> str:
return self._name

View File

@ -0,0 +1,23 @@
from typing import Optional
from cpl_query.extension import List
from py_to_uxf_core.abc.class_scanner_abc import ClassScannerABC
from py_to_uxf_core.model.python_class import PythonClass
class ClassScannerService(ClassScannerABC):
def __init__(self):
ClassScannerABC.__init__(self)
def scan_line_for_classes(self, line: str) -> Optional[PythonClass]:
if 'class' in line:
name = line.split(' ')[1]
if '(' in name:
name = name.split('(')[0]
else:
name = name.split(':')[0]
return PythonClass(name)
return None

View File

@ -1,16 +1,30 @@
from typing import Optional
from cpl_core.console import Console from cpl_core.console import Console
from py_to_uxf_core.abc.class_scanner_abc import ClassScannerABC
from py_to_uxf_core.abc.file_scanner_abc import FileScannerABC from py_to_uxf_core.abc.file_scanner_abc import FileScannerABC
from py_to_uxf_core.abc.python_parser_abc import PythonParserABC from py_to_uxf_core.abc.python_parser_abc import PythonParserABC
from py_to_uxf_core.model.python_class import PythonClass
class PythonParserService(PythonParserABC): class PythonParserService(PythonParserABC):
def __init__(self, file_scanner: FileScannerABC): def __init__(self, file_scanner: FileScannerABC, class_scanner: ClassScannerABC):
PythonParserABC.__init__(self) PythonParserABC.__init__(self)
self._file_scanner = file_scanner self._file_scanner = file_scanner
self._class_scanner = class_scanner
def parse(self): def parse(self):
files = self._file_scanner.scan_files() files = self._file_scanner.scan_files()
files.for_each(lambda f: Console.write_line(f)) for file in files:
Console.write_line('f:', file)
with open(file, 'r') as file_content:
cls: Optional[PythonClass] = None
for line in file_content.readlines():
if cls is None:
cls = self._class_scanner.scan_line_for_classes(line)
continue
Console.write_line('c:', cls.name)