Ejemplo n.º 1
0
    def __runDemo():
        if not Cli.cocoscats.isWorkflowDemoEnabled() or \
            Cli.cocoscats.getWorkflowDemoPluginCount() < 1:
            return
        Msg.show("Execute: Demo Stage")
        choices = Cli.cocoscats.getWorkflowDemoPluginChoices()
        menu = """-----------------------------------------------
Please make a selection to run demo or 'x' to exit.\n"""
        i = 1
        for choice in choices:
            menu = """{0}
[{1}]: {2}::{3}()""".format(menu, i, choice["Name"], choice["Method"])
            i += 1
        menu = """{0}
[x]: Exit
""".format(menu)
        errMsg = "Error: Valid options are: [1-{0}]".format(i - 1)
        while True:
            Msg.showRaw(menu)
            response = input()
            if response == "x" or response == "X":
                break
            if not Text.isInt(response):
                Msg.showRaw(errMsg)
                continue
            response = int(response)
            if response < 1 or response >= i:
                Msg.showRaw(errMsg)
                continue
            j = response - 1
            ret = Cli.cocoscats.runDemo(choices[j]["Name"],
                                        choices[j]["Method"])
            if ret:
                Msg.showWarning("Demo returned an error")
Ejemplo n.º 2
0
 def show(self):
     if self.cfg is None or self.cfgPath is None:
         Msg.showWarning(
             "No information found for cfg file. Did you load it?")
         return
     pprint(self.cfg)
     Msg.flush()
Ejemplo n.º 3
0
 def handleException(msg, showStackTraceFlag=True, abortFlag=True):
     Msg.showError(str(msg))
     if showStackTraceFlag:
         traceback.print_exc()
     if abortFlag:
         sys.stderr.flush()
         sys.exit(1)
Ejemplo n.º 4
0
 def __handleException(self, msg, abortFlag=True):
     messagebox.showerror("COCOSCATS", msg)
     Msg.showError(msg)
     if abortFlag:
         self.__root.destroy()
         sys.stderr.flush()
         sys.exit(1)
Ejemplo n.º 5
0
 def showPluginFiles(pluginDirName):
     print("\n[{0}]".format(pluginDirName))
     plugins = Framework.getPluginFiles(pluginDirName)
     if plugins is None:
         Msg.showWarning("Can't find an plugins")
         return
     for plugin in plugins:
         print("  {0}".format(plugin["Name"]))
Ejemplo n.º 6
0
 def __runTranslator():
     Msg.show("Execute: Translation Stage")
     content = Cli.cocoscats.runTranslator()
     if Cli.cocoscats.isWorkflowEditTrue("Translator"):
         Cli.__runEditor(Cli.cocoscats.frameworkParams["translatorPath"],
                         Cli.cocoscats.frameworkParams["translatorPath"])
     if Cli.cocoscats.isWorkflowDebugTrue("Translator"):
         Msg.showRaw(content)
Ejemplo n.º 7
0
 def __runOutput():
     Msg.show("Execute: Output Stage")
     content = Cli.cocoscats.runOutput()
     if Cli.cocoscats.isWorkflowEditTrue("Output"):
         Cli.__runEditor(Cli.cocoscats.frameworkParams["outputPath"],
                         Cli.cocoscats.frameworkParams["outputPath"])
     if Cli.cocoscats.isWorkflowDebugTrue("Output"):
         Msg.showRaw(content)
Ejemplo n.º 8
0
 def __runAnalyzer():
     Msg.show("Execute: Analyzer Stage")
     content = Cli.cocoscats.runAnalyzer()
     if Cli.cocoscats.isWorkflowEditTrue("Analyzer"):
         Cli.__runEditor(Cli.cocoscats.frameworkParams["analyzerPath"],
                         Cli.cocoscats.frameworkParams["analyzerPath"])
     if Cli.cocoscats.isWorkflowDebugTrue("Analyzer"):
         Msg.showRaw(content)
Ejemplo n.º 9
0
    def run(cocoscats):
        Web.cocoscats = cocoscats
        Web.useHttps = Text.isTrue(Web.cocoscats.cfg["Web"]["UseHttps"])
        Web.useAuthentication = Text.isTrue(
            Web.cocoscats.cfg["Web"]["UseAuthentication"])
        sessionOptions = {
            "session.type": "memory",
            "session.cookie_expires": 300,
            "session.auto": True
        }

        if Text.isTrue(Web.cocoscats.cfg["Web"]["Debug"]):
            WebSecurity.getSubresourceIntegrityHashes(True)

        Web.setupPassword()
        Web.setupCertificate()

        if Web.useHttps:
            Web.scheme = "https"
            Web.url = "{0}://{1}:{2}/".format(Web.scheme,
                                              Web.cocoscats.cfg["Web"]["Host"],
                                              Web.cocoscats.cfg["Web"]["Port"])
            server = WebSecurity(host=Web.cocoscats.cfg["Web"]["Host"],
                                 port=Web.cocoscats.cfg["Web"]["Port"])

            threading.Thread(target=bottle.run,
                             kwargs=dict(
                                 app=SessionMiddleware(bottle.app(),
                                                       sessionOptions),
                                 debug=Text.toTrueOrFalse(
                                     Web.cocoscats.cfg["Web"]["Debug"]),
                                 reloader=Text.toTrueOrFalse(
                                     Web.cocoscats.cfg["Web"]["Reloader"]),
                                 server=server)).start()
        else:
            Web.scheme = "http"
            Web.url = "{0}://{1}:{2}/".format(Web.scheme,
                                              Web.cocoscats.cfg["Web"]["Host"],
                                              Web.cocoscats.cfg["Web"]["Port"])
            threading.Thread(
                target=bottle.run,
                kwargs=dict(
                    app=SessionMiddleware(bottle.app(), sessionOptions),
                    debug=Text.toTrueOrFalse(
                        Web.cocoscats.cfg["Web"]["Debug"]),
                    host=Web.cocoscats.cfg["Web"]["Host"],
                    port=Web.cocoscats.cfg["Web"]["Port"],
                    reloader=Text.toTrueOrFalse(
                        Web.cocoscats.cfg["Web"]["Reloader"]))).start()
        Msg.flush()
        for client in Web.cocoscats.cfg["Web"]["Browser"]:
            if Text.isNothing(client) or client.lower() == "default":
                if webbrowser.open(Web.url):
                    break
            else:
                if webbrowser.get(client).open(Web.url):
                    break
Ejemplo n.º 10
0
 def createPassword():
     Security.deletePassword()
     p = Security.promptForPassword(True)
     Msg.flush()
     Msg.show("Thanks ... please wait")
     Msg.flush()
     h = Security.hashAndSaltPassword(p)
     File.setContent(Security.__passwordPath, {"Password": h}, asJson=True)
Ejemplo n.º 11
0
    def updateDatabase(self):
        #Database.connect()
        #projects = Database.getProject("MyProjectID")
        #print(projects)
        #Database.disconnect()
        #sys.exit()
        if not Text.isTrue(self.cfg["Database"]["Enable"]):
            Msg.showWarning("Database is NOT enabled in {0}".format(
                self.cfgPath))
            return
        Database.connect()
        Database.setDebug(Text.toTrueOrFalse(self.cfg["Database"]["Debug"]))
        with Database.ORM.db_session:
            records = Database.Table.Project.get(ID=self.getProjectID())
            if records is not None:
                records.delete()
                Database.commit()

            projectTable = Database.Table.Project(
                ID=self.getProjectID(),
                Title=Database.sanitize(self.cfg["Title"]),
                Description=Database.sanitize(self.cfg["Description"]),
                DateTime=self.frameworkParams["dateTime"],
                Workflow=self.cfg["Workflow"])

            inputTable = Database.Table.Input(
                ProjectID=projectTable,
                Content=Database.sanitize(
                    File.getContent(self.frameworkParams["inputPath"])),
                Source=Database.sanitize(
                    self.cfg["Workflow"]["Input"]["Source"]),
                PluginName=Database.sanitize(
                    self.cfg["Workflow"]["Input"]["Plugin"]),
                PluginMethod=Database.sanitize(
                    self.cfg["Workflow"]["Input"]["Method"]),
                Plugin=self.cfg["Workflow"]["Input"])

            analyzerTable = Database.Table.Analyzer(
                ProjectID=projectTable,
                Content=Database.sanitize(
                    File.getContent(self.frameworkParams["analyzerPath"])),
                PluginName=Database.sanitize(
                    self.cfg["Workflow"]["Analyzer"]["Plugin"]),
                PluginMethod=Database.sanitize(
                    self.cfg["Workflow"]["Analyzer"]["Method"]),
                Plugin=self.cfg["Workflow"]["Analyzer"])

            content = Database.sanitize(
                File.getContent(self.frameworkParams["translatorPath"]))
            translatorTable = Database.Table.Translator(
                ProjectID=projectTable,
                Content=content,
                ContentParsed=Result.parseTranslatorContent(content),
                PluginName=Database.sanitize(
                    self.cfg["Workflow"]["Translator"]["Plugin"]),
                PluginMethod=Database.sanitize(
                    self.cfg["Workflow"]["Translator"]["Method"]),
                Plugin=self.cfg["Workflow"]["Translator"])

            outputTable = Database.Table.Output(
                ProjectID=projectTable,
                Content=Database.sanitize(
                    File.getContent(self.frameworkParams["outputPath"])),
                Target=Database.sanitize(
                    self.cfg["Workflow"]["Output"]["Target"]),
                PluginName=Database.sanitize(
                    self.cfg["Workflow"]["Output"]["Plugin"]),
                PluginMethod=Database.sanitize(
                    self.cfg["Workflow"]["Output"]["Method"]),
                Plugin=self.cfg["Workflow"]["Output"])

        Database.disconnect()
Ejemplo n.º 12
0
 def showAllPluginFiles():
     Msg.show("Plugins")
     Framework.showPluginFiles("IO")
     Framework.showPluginFiles("Analyzer")
     Framework.showPluginFiles("Translator")
Ejemplo n.º 13
0
 def handleError(msg, abortFlag=True):
     Msg.showError(str(msg))
     if abortFlag:
         sys.stderr.flush()
         sys.exit(1)
Ejemplo n.º 14
0
 def __abort(self, event=None):
     Msg.showAbort("Script did not complete execution.")
     sys.exit(1)
Ejemplo n.º 15
0
 def show(self):
     Msg.showRaw("Configuration")
     Msg.showPretty(self.__cfg)
     Msg.showRaw("Plugin Parameters")
     Msg.showPretty(self.__pluginParams)
     Msg.showRaw("Framework Parameters")
     Msg.showPretty(self.__frameworkParams)