From a1eba51d453eb9894745aef44084e53db70b21b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ata=20Hak=C3=A7=C4=B1l?= Date: Sun, 27 Jun 2021 16:48:10 +0300 Subject: [PATCH] Fix duplicated model zip releases and rename finished.mdl --- .github/workflows/build.yml | 1 + Markopy/src/CLI/markopy.py | 246 +++++++++---------- models/trained/{finished.mdl => trained.mdl} | Bin 3 files changed, 124 insertions(+), 123 deletions(-) rename models/trained/{finished.mdl => trained.mdl} (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6fc17130..5f695220 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -178,6 +178,7 @@ jobs: asset_content_type: application/zip - name: Upload Models + if: matrix.python-version == '38' id: upload-release-asset-models uses: actions/upload-release-asset@v1 env: diff --git a/Markopy/src/CLI/markopy.py b/Markopy/src/CLI/markopy.py index e1a8cc52..f58cd859 100644 --- a/Markopy/src/CLI/markopy.py +++ b/Markopy/src/CLI/markopy.py @@ -1,124 +1,124 @@ -""" @package markopy - @file markopy_cli.py - @namespace Python::Markopy::ModelMatrix - @brief Command line class for ModelMatrix - @authors Ata Hakçıl -""" - -from importlib.util import spec_from_loader, module_from_spec -from importlib.machinery import SourceFileLoader, ExtensionFileLoader -import os -import sys - -ext = "so" -if os.name == 'nt': - ext="pyd" -try: - spec = spec_from_loader("markopy", ExtensionFileLoader("markopy", os.path.abspath(f"markopy.{ext}"))) - markopy = module_from_spec(spec) - spec.loader.exec_module(markopy) -except ImportError as e: - print(f"({__file__}) Working in development mode. Trying to load markopy.{ext} from ../../../out/") - if(os.path.exists("../../../out/lib/markopy.so")): - spec = spec_from_loader("markopy", ExtensionFileLoader("markopy", os.path.abspath(f"../../../out/lib/markopy.{ext}"))) - markopy = module_from_spec(spec) - spec.loader.exec_module(markopy) - else: - raise e - -try: - from base import BaseCLI - from mp import MarkovPasswordsCLI - from mmx import ModelMatrixCLI - -except ModuleNotFoundError as e: - print("Working in development mode. Trying to load markopy.py from ../../../Markopy/") - if(os.path.exists("../../../Markopy/src/CLI/base.py")): - sys.path.insert(1, '../../../Markopy/src/CLI/') - from base import BaseCLI - from mp import MarkovPasswordsCLI - from mmx import ModelMatrixCLI - else: - raise e - - -from termcolor import colored -from abc import abstractmethod - -class MarkopyCLI(BaseCLI): - def __init__(self, add_help=False): - super().__init__(add_help) - self.args = None - self.parser.epilog = f""" - {colored("Sample runs:", "yellow")} - {__file__.split("/")[-1]} -mt MP generate trained.mdl -n 500 -w output.txt - Import trained.mdl, and generate 500 lines to output.txt - - {__file__.split("/")[-1]} -mt MMX generate trained.mdl -n 500 -w output.txt - Import trained.mdl, and generate 500 lines to output.txt - """ - - def add_arguments(self): - self.parser.add_argument("-mt", "--model_type", default="_MMX", help="Model type to use. Accepted values: MP, MMX") - self.parser.add_argument("-h", "--help", action="store_true", help="Model type to use. Accepted values: MP, MMX") - self.parser.print_help = self.help - - @abstractmethod - def help(self): - self.parser.print_help = self.stub - self.args = self.parser.parse_known_args()[0] - if(self.args.model_type!="_MMX"): - if(self.args.model_type=="MP"): - mp = MarkovPasswordsCLI() - mp.add_arguments() - mp.parser.print_help() - elif(self.args.model_type=="MMX"): - mp = ModelMatrixCLI() - mp.add_arguments() - mp.parser.print_help() - else: - print(colored("Model Mode selection choices:", "green")) - self.print_help() - print(colored("Following are applicable for -mt MP mode:", "green")) - mp = MarkovPasswordsCLI() - mp.add_arguments() - mp.parser.print_help() - print(colored("Following are applicable for -mt MMX mode:", "green")) - mp = ModelMatrixCLI() - mp.add_arguments() - mp.parser.print_help() - - exit() - - - @abstractmethod - def parse(self): - self.add_arguments() - self.parse_arguments() - self.init_post_arguments() - if(self.args.model_type == "MP"): - self.cli = MarkovPasswordsCLI() - elif(self.args.model_type == "MMX" or self.args.model_type == "_MMX"): - self.cli = ModelMatrixCLI() - else: - self.parse_fail() - - if(self.args.help): return self.help() - self.cli.parse() - - @abstractmethod - def parse_fail(self): - print("Unrecognized model type.") - exit() - - def process(self): - return self.cli.process() - - def stub(self): - return - - -if __name__ == "__main__": - mp = MarkopyCLI() - mp.parse() +""" @package markopy + @file markopy_cli.py + @namespace Python::Markopy::ModelMatrix + @brief Command line class for ModelMatrix + @authors Ata Hakçıl +""" + +from importlib.util import spec_from_loader, module_from_spec +from importlib.machinery import SourceFileLoader, ExtensionFileLoader +import os +import sys + +ext = "so" +if os.name == 'nt': + ext="pyd" +try: + spec = spec_from_loader("markopy", ExtensionFileLoader("markopy", os.path.abspath(f"markopy.{ext}"))) + markopy = module_from_spec(spec) + spec.loader.exec_module(markopy) +except ImportError as e: + print(f"({__file__}) Working in development mode. Trying to load markopy.{ext} from ../../../out/") + if(os.path.exists("../../../out/lib/markopy.so")): + spec = spec_from_loader("markopy", ExtensionFileLoader("markopy", os.path.abspath(f"../../../out/lib/markopy.{ext}"))) + markopy = module_from_spec(spec) + spec.loader.exec_module(markopy) + else: + raise e + +try: + from base import BaseCLI + from mp import MarkovPasswordsCLI + from mmx import ModelMatrixCLI + +except ModuleNotFoundError as e: + print("Working in development mode. Trying to load markopy.py from ../../../Markopy/") + if(os.path.exists("../../../Markopy/src/CLI/base.py")): + sys.path.insert(1, '../../../Markopy/src/CLI/') + from base import BaseCLI + from mp import MarkovPasswordsCLI + from mmx import ModelMatrixCLI + else: + raise e + + +from termcolor import colored +from abc import abstractmethod + +class MarkopyCLI(BaseCLI): + def __init__(self, add_help=False): + super().__init__(add_help) + self.args = None + self.parser.epilog = f""" + {colored("Sample runs:", "yellow")} + {__file__.split("/")[-1]} -mt MP generate trained.mdl -n 500 -w output.txt + Import trained.mdl, and generate 500 lines to output.txt + + {__file__.split("/")[-1]} -mt MMX generate trained.mdl -n 500 -w output.txt + Import trained.mdl, and generate 500 lines to output.txt + """ + + def add_arguments(self): + self.parser.add_argument("-mt", "--model_type", default="_MMX", help="Model type to use. Accepted values: MP, MMX") + self.parser.add_argument("-h", "--help", action="store_true", help="Model type to use. Accepted values: MP, MMX") + self.parser.print_help = self.help + + @abstractmethod + def help(self): + self.parser.print_help = self.stub + self.args = self.parser.parse_known_args()[0] + if(self.args.model_type!="_MMX"): + if(self.args.model_type=="MP"): + mp = MarkovPasswordsCLI() + mp.add_arguments() + mp.parser.print_help() + elif(self.args.model_type=="MMX"): + mp = ModelMatrixCLI() + mp.add_arguments() + mp.parser.print_help() + else: + print(colored("Model Mode selection choices:", "green")) + self.print_help() + print(colored("Following are applicable for -mt MP mode:", "green")) + mp = MarkovPasswordsCLI() + mp.add_arguments() + mp.parser.print_help() + print(colored("Following are applicable for -mt MMX mode:", "green")) + mp = ModelMatrixCLI() + mp.add_arguments() + mp.parser.print_help() + + exit() + + + @abstractmethod + def parse(self): + self.add_arguments() + self.parse_arguments() + self.init_post_arguments() + if(self.args.model_type == "MP"): + self.cli = MarkovPasswordsCLI() + elif(self.args.model_type == "MMX" or self.args.model_type == "_MMX"): + self.cli = ModelMatrixCLI() + else: + self.parse_fail() + + if(self.args.help): return self.help() + self.cli.parse() + + @abstractmethod + def parse_fail(self): + print("Unrecognized model type.") + exit() + + def process(self): + return self.cli.process() + + def stub(self): + return + + +if __name__ == "__main__": + mp = MarkopyCLI() + mp.parse() mp.process() \ No newline at end of file diff --git a/models/trained/finished.mdl b/models/trained/trained.mdl similarity index 100% rename from models/trained/finished.mdl rename to models/trained/trained.mdl