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:
commit
d74cc9fec9
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
__pycache__
|
2
.idea/.gitignore
generated
vendored
Normal file
2
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/workspace.xml
|
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal 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
8
.idea/linux-tools.iml
generated
Normal 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
7
.idea/misc.xml
generated
Normal 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
8
.idea/modules.xml
generated
Normal 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
6
.idea/vcs.xml
generated
Normal 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
18
CommandRunner.py
Normal 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
8
IModule.py
Normal 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
29
main.py
@ -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)
|
5
modules/sample/__init__.py
Normal file
5
modules/sample/__init__.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from .sampleModule import SampleModule
|
||||||
|
|
||||||
|
|
||||||
|
def get_module():
|
||||||
|
return SampleModule()
|
14
modules/sample/sampleModule.py
Normal file
14
modules/sample/sampleModule.py
Normal 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"
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user