Added python file scanner

This commit is contained in:
Sven Heidemann 2022-01-16 00:36:37 +01:00
parent d4d5b0b9cb
commit 156ad6f8b3
6 changed files with 60 additions and 1 deletions

View File

@ -3,6 +3,8 @@ from cpl_core.configuration import ConfigurationABC
from cpl_core.console import Console from cpl_core.console import Console
from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.dependency_injection import ServiceProviderABC
from py_to_uxf_core.abc.python_parser_abc import PythonParserABC
class Application(ApplicationABC): class Application(ApplicationABC):
@ -10,6 +12,7 @@ class Application(ApplicationABC):
ApplicationABC.__init__(self, config, services) ApplicationABC.__init__(self, config, services)
self._path = config.get_configuration('path') self._path = config.get_configuration('path')
self._parser = services.get_service(PythonParserABC)
def configure(self): def configure(self):
pass pass
@ -21,3 +24,4 @@ class Application(ApplicationABC):
return return
Console.write_line(f'Found path:', self._path) Console.write_line(f'Found path:', self._path)
self._parser.parse()

View File

@ -5,8 +5,10 @@ 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.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.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
@ -23,6 +25,8 @@ class Startup(StartupABC):
return configuration return configuration
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_singleton(PythonParserABC, PythonParserService) services.add_singleton(PythonParserABC, PythonParserService)
services.add_singleton(UmletCreatorABC, UmletCreatorService) services.add_singleton(UmletCreatorABC, UmletCreatorService)

View File

@ -0,0 +1,12 @@
from abc import ABC, abstractmethod
from cpl_query.extension import List
class FileScannerABC(ABC):
@abstractmethod
def __init__(self): pass
@abstractmethod
def scan_files(self) -> List[str]: pass

View File

@ -5,3 +5,6 @@ class PythonParserABC(ABC):
@abstractmethod @abstractmethod
def __init__(self): pass def __init__(self): pass
@abstractmethod
def parse(self): pass

View File

@ -0,0 +1,27 @@
import os
from cpl_core.configuration import ConfigurationABC
from cpl_core.console import Console
from cpl_query.extension import List
from py_to_uxf_core.abc.file_scanner_abc import FileScannerABC
class FileScannerService(FileScannerABC):
def __init__(self, config: ConfigurationABC):
FileScannerABC.__init__(self)
self._config = config
self._path = config.get_configuration('path')
def scan_files(self) -> List[str]:
files = List(str)
for r, d, f in os.walk(self._path):
for file_name in f:
if file_name.endswith('.py'):
relative_path = os.path.relpath(r)
file_path = os.path.join(relative_path, os.path.relpath(file_name))
files.append(os.path.relpath(file_path))
return files

View File

@ -1,7 +1,16 @@
from cpl_core.console import Console
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
class PythonParserService(PythonParserABC): class PythonParserService(PythonParserABC):
def __init__(self): def __init__(self, file_scanner: FileScannerABC):
PythonParserABC.__init__(self) PythonParserABC.__init__(self)
self._file_scanner = file_scanner
def parse(self):
files = self._file_scanner.scan_files()
files.for_each(lambda f: Console.write_line(f))