Added python class scan
This commit is contained in:
parent
156ad6f8b3
commit
2be818fcc1
@ -5,9 +5,11 @@ from cpl_core.configuration import ConfigurationABC, ConsoleArgument
|
||||
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
|
||||
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.python_parser_abc import PythonParserABC
|
||||
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.python_parser_service import PythonParserService
|
||||
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:
|
||||
services.add_transient(FileScannerABC, FileScannerService)
|
||||
services.add_transient(ClassScannerABC, ClassScannerService)
|
||||
|
||||
services.add_singleton(PythonParserABC, PythonParserService)
|
||||
services.add_singleton(UmletCreatorABC, UmletCreatorService)
|
||||
|
15
src/py_to_uxf_core/abc/class_scanner_abc.py
Normal file
15
src/py_to_uxf_core/abc/class_scanner_abc.py
Normal 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
|
25
src/py_to_uxf_core/model/__init__.py
Normal file
25
src/py_to_uxf_core/model/__init__.py
Normal 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')
|
8
src/py_to_uxf_core/model/python_class.py
Normal file
8
src/py_to_uxf_core/model/python_class.py
Normal file
@ -0,0 +1,8 @@
|
||||
class PythonClass:
|
||||
|
||||
def __init__(self, name):
|
||||
self._name = name
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
23
src/py_to_uxf_core/service/class_scanner_service.py
Normal file
23
src/py_to_uxf_core/service/class_scanner_service.py
Normal 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
|
@ -1,16 +1,30 @@
|
||||
from typing import Optional
|
||||
|
||||
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.python_parser_abc import PythonParserABC
|
||||
from py_to_uxf_core.model.python_class import PythonClass
|
||||
|
||||
|
||||
class PythonParserService(PythonParserABC):
|
||||
|
||||
def __init__(self, file_scanner: FileScannerABC):
|
||||
def __init__(self, file_scanner: FileScannerABC, class_scanner: ClassScannerABC):
|
||||
PythonParserABC.__init__(self)
|
||||
|
||||
self._file_scanner = file_scanner
|
||||
self._class_scanner = class_scanner
|
||||
|
||||
def parse(self):
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user