Change from dynamic to explicit module loading
dynamic loading was removed to have an overall better flow control, Remove Abstract Module, clear out module __init__.py
This commit is contained in:
parent
8bdef1d4e8
commit
6061a7d224
@ -1,12 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class AbstractModule(ABC):
|
||||
"""docstring for Module."""
|
||||
|
||||
def __init__(self):
|
||||
super(AbstractModule, self).__init__()
|
||||
|
||||
@abstractmethod
|
||||
def run(self):
|
||||
pass
|
27
main.py
27
main.py
@ -1,20 +1,17 @@
|
||||
import importlib
|
||||
import os
|
||||
import fire
|
||||
|
||||
from modules.helloworld.HelloWorld import HelloWorld
|
||||
from modules.install.ToolsInstaller import ToolsInstaller
|
||||
from modules.swap.SwapModule import SwapModule
|
||||
from modules.systemupdate.Systemupdate import Systemupdate
|
||||
from modules.vim.VimModule import VimModule
|
||||
|
||||
def load_modules():
|
||||
print("Loading modules")
|
||||
loaded_modules = {}
|
||||
for folder in os.listdir("./modules"):
|
||||
try:
|
||||
curr_module = importlib.import_module('.' + folder, package="modules")
|
||||
loaded_modules[folder] = curr_module.get_module()
|
||||
except AttributeError:
|
||||
pass
|
||||
print("Modules loaded successfully.\n")
|
||||
return loaded_modules
|
||||
modules = {
|
||||
"helloworld": HelloWorld,
|
||||
"install": ToolsInstaller,
|
||||
"swap": SwapModule,
|
||||
"update": Systemupdate,
|
||||
"vim": VimModule
|
||||
}
|
||||
|
||||
|
||||
modules = load_modules()
|
||||
fire.Fire(modules)
|
||||
|
@ -1,12 +1,6 @@
|
||||
from AbstractModule import AbstractModule
|
||||
|
||||
|
||||
class HelloWorld(AbstractModule):
|
||||
class HelloWorld:
|
||||
"""docstring for SampleModule."""
|
||||
|
||||
def __init__(self):
|
||||
super(HelloWorld, self).__init__()
|
||||
|
||||
def run(self):
|
||||
print("This shows that your installation is working correctly.")
|
||||
print("You can now start using the tool.")
|
@ -1,5 +0,0 @@
|
||||
from .helloWorld import HelloWorld
|
||||
|
||||
|
||||
def get_module():
|
||||
return HelloWorld()
|
@ -1,17 +1,14 @@
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
from AbstractModule import AbstractModule
|
||||
|
||||
|
||||
class CmdToolsModule(AbstractModule):
|
||||
class ToolsInstaller:
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
with open("modules/program-installer/programs.json") as config_file:
|
||||
with open("modules/install/programs.json") as config_file:
|
||||
self.programs_json = json.load(config_file)
|
||||
|
||||
def run(self):
|
||||
def basic_tools(self):
|
||||
"""Install the most basic tools!"""
|
||||
print("Try to install basic Command-line tools")
|
||||
|
0
modules/install/__init__.py
Normal file
0
modules/install/__init__.py
Normal file
@ -1,5 +0,0 @@
|
||||
from .module import CmdToolsModule
|
||||
|
||||
|
||||
def get_module():
|
||||
return CmdToolsModule()
|
@ -1,7 +1,6 @@
|
||||
import subprocess
|
||||
from typing import List
|
||||
|
||||
from AbstractModule import AbstractModule
|
||||
from PyInquirer import prompt
|
||||
|
||||
|
||||
@ -9,10 +8,7 @@ def _run_shell_command(cmd: List[str]) -> str:
|
||||
return subprocess.check_output(cmd).decode("UTF-8").strip()
|
||||
|
||||
|
||||
class SwapModule(AbstractModule):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
class SwapModule:
|
||||
|
||||
def run(self):
|
||||
actions = {
|
@ -1,5 +0,0 @@
|
||||
from .module import SwapModule
|
||||
|
||||
|
||||
def get_module():
|
||||
return SwapModule()
|
@ -1,9 +1,7 @@
|
||||
import subprocess
|
||||
|
||||
from AbstractModule import AbstractModule
|
||||
|
||||
|
||||
class Systemupdate(AbstractModule):
|
||||
class Systemupdate:
|
||||
|
||||
def run(self):
|
||||
print("Running update")
|
@ -1,5 +0,0 @@
|
||||
from .systemupdate import Systemupdate
|
||||
|
||||
|
||||
def get_module():
|
||||
return Systemupdate()
|
@ -5,10 +5,8 @@ from pathlib import Path
|
||||
|
||||
from PyInquirer import prompt
|
||||
|
||||
from AbstractModule import AbstractModule
|
||||
|
||||
|
||||
class VimModule(AbstractModule):
|
||||
class VimModule:
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self._debugFlag = False
|
@ -1,5 +0,0 @@
|
||||
from .module import VimModule
|
||||
|
||||
|
||||
def get_module():
|
||||
return VimModule()
|
Loading…
Reference in New Issue
Block a user