Esempio n. 1
0
 def __parseContentForOutputSRT(self, rawContent):
     tc = self.getTranslatorContentAsJson()
     counters = []
     markers = []
     subtitles = []
     for token in rawContent.split("\n"):
         token = token.strip()
         if Text.isNothing(token):
             continue
         if token.isdigit():
             counters.append(token)
         elif re.search("-->", token):
             markers.append(token)
     tc["L1L2"] = tc["L1L2"].strip()
     subtitle = ""
     for token in tc["L1L2"].split("\n"):
         token = token.strip()
         if Text.isNothing(token):
             subtitles.append(subtitle)
             subtitle = ""
         else:
             subtitle = "{0}\n{1}".format(subtitle, token)
     subtitles.append(subtitle)
     content = ""
     for i in range(0, len(counters)):
         content = "{0}\n{1}\n{2}{3}\n".format(content, counters[i],
                                               markers[i], subtitles[i])
     content = content.lstrip()
     return content
Esempio n. 2
0
 def verify(self):
     for name, value in self.cfg.items():
         if name == "ProjectID":
             if len(value) > 256 or Text.isNothing(value):
                 Error.raiseException(
                     "{0} can only be 256 characters or less: {1}".format(
                         name, value))
             if re.search(r'[^A-Za-z0-9_\-\\]', value):
                 Error.raiseException(
                     "{0} contains invalid characters: {1}".format(
                         name, value))
         if Text.isNothing(value):
             Error.raiseException("Missing '{0}' value in {1}".format(
                 name, self.cfgPath))
     pluginLookupMap = []
     for plugin in self.cfg["Plugin"]:
         pluginMethods = self.getPluginMethods(plugin["Type"],
                                               plugin["Name"])
         for pluginMethod in pluginMethods["Method"]:
             if not Framework.hasPluginClassMethod(
                     plugin["Type"], plugin["Name"], pluginMethod["Name"]):
                 Error.raiseException("Can't find {0}::{1}::{2}()".format(
                     plugin["Type"], plugin["Name"], pluginMethod["Name"]))
             pluginLookupMap.append("{0}{1}{2}".format(
                 plugin["Type"], plugin["Name"], pluginMethod["Name"]))
     if len(self.cfg["Workflow"]["Demo"]["Plugin"]) != len(
             self.cfg["Workflow"]["Demo"]["Method"]):
         Error.raiseException(
             "Mismatched number of demo plugins and methods")
     workflowPluginLookupMap = []
     for workflowPluginType, workflowPluginCfg in self.cfg[
             "Workflow"].items():
         pluginType = self.pluginTypeAlias[workflowPluginType]
         if pluginType != "Demo":
             workflowPluginLookupMap.append("{0}{1}{2}".format(
                 pluginType, workflowPluginCfg["Plugin"],
                 workflowPluginCfg["Method"]))
         else:
             for i in range(0, len(workflowPluginCfg["Plugin"])):
                 key = "{0}{1}{2}".format(pluginType,
                                          workflowPluginCfg["Plugin"][i],
                                          workflowPluginCfg["Method"][i])
                 if key not in pluginLookupMap:
                     Error.raiseException(
                         "Can't find workflow plugin {0}::{1}::{2}()".
                         format(workflowPluginType,
                                workflowPluginCfg["Plugin"][i],
                                workflowPluginCfg["Method"][i]))
Esempio n. 3
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
Esempio n. 4
0
 def __parseContentForInputSRT(self, rawContent):
     content = []
     newLineTracker = 0
     for token in rawContent.split("\n"):
         token = token.strip()
         if re.search("-->",
                      token) or token.isdigit() or Text.isNothing(token):
             if newLineTracker < 1:
                 content.append("")
             newLineTracker += 1
         else:
             content.append(token)
             newLineTracker = 0
     content = "\n".join(content).strip()
     return content
Esempio n. 5
0
 def getWorkflowInputSource(self):
     source = self.getWorkflowPlugin("Input")["Source"]
     if Text.isNothing(source):
         return None
     return source
Esempio n. 6
0
 def getWorkflowTargetPath(self):
     if Text.isNothing(self.cfg["Workflow"]["Output"]["Target"]):
         return None
     return self.cfg["Workflow"]["Output"]["Target"]
Esempio n. 7
0
 def getWorkflowSourcePath(self):
     if Text.isNothing(self.cfg["Workflow"]["Input"]["Source"]):
         return None
     return self.cfg["Workflow"]["Input"]["Source"]
Esempio n. 8
0
 def getWorkflowOutputTarget(self):
     target = self.getWorkflowPlugin("Output")["Target"]
     if Text.isNothing(target):
         return None
     return target