Merge branch '9-create-main-py-function-to-start-the-script' into 'master'

Resolve "Create main.py function to start the script"

Closes #9

See merge request icaotix/linux-tools!2
This commit is contained in:
Marcel Schwarz 2019-12-14 03:29:16 +00:00
commit d74cc9fec9
12 changed files with 112 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__

2
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

8
.idea/linux-tools.iml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

7
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/linux-tools.iml" filepath="$PROJECT_DIR$/.idea/linux-tools.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

18
CommandRunner.py Normal file
View File

@ -0,0 +1,18 @@
class CommandRunner(object):
"""docstring for CommandRunner."""
def __init__(self):
super(CommandRunner).__init__()
def run(self, module):
print("REAL RUNNER")
print("Commands should be executed as subprocess.")
class CommandRunnerDebug(object):
def __init__(self):
super(CommandRunnerDebug).__init__()
def run(self, module):
print("DEBUG RUNNER")
print(module.get_command())

8
IModule.py Normal file
View File

@ -0,0 +1,8 @@
class IModule(object):
"""docstring for Module."""
def __init__(self):
super(IModule, self).__init__()
def get_command(self):
raise NotImplementedError

29
main.py
View File

@ -0,0 +1,29 @@
from CommandRunner import CommandRunnerDebug as Runner
import importlib
import os
def get_modules():
modules = []
for folder in os.listdir("./modules"):
# skipping sample module
if folder == "sample":
continue
print("Module found: " + folder)
curr_module = importlib.import_module('.' + folder, package="modules")
print("Try to load module: " + folder)
modules.append(curr_module.get_module())
print("Module loaded successfully: " + folder)
return modules
print("Loading modules: \n")
modules = get_modules()
print("\nRunning all modules \n")
cmdRunner = Runner()
for module in modules:
cmdRunner.run(module)

View File

@ -0,0 +1,5 @@
from .sampleModule import SampleModule
def get_module():
return SampleModule()

View File

@ -0,0 +1,14 @@
from IModule import IModule
class SampleModule(IModule):
"""docstring for SampleModule."""
def __init__(self):
super(SampleModule, self).__init__()
def get_command(self):
return [
"command 1",
"command 2"
]