示例#1
0
def deleteSafe():
    try:
        for path in [
                "./", "./Core", "./Plugin", "./Plugin/Analyzer",
                "./Plugin/Demo", "./Plugin/IO", "./Plugin/Test",
                "./Plugin/Translator"
        ]:
            Directory.delete("{0}/__pycache__".format(path))
            for path in glob.glob("./Test/Tmp/*"):
                File.delete(File.getCanonicalPath(path))
    except Exception as e:
        Error.handleException(e, True)
示例#2
0
def deleteProtected(cfgPath):
    try:
        cfg = Cfg(cfgPath)
        cfg.load()
        for path in [
                "./Database/{0}.db".format(cfg.cfg["Database"]["Name"]),
                "./Database/CocoscatsTest.db", "./Vault/Certificate.pem",
                "./Vault/Password.json", "./Vault/PrivateKey.pem",
                "./Vault/PublicKey.pem"
        ]:
            File.delete(path)
    except Exception as e:
        Error.handleException(e, True)
示例#3
0
 def testCocoscatsOutputPlugins(self):
     File.delete(self.databasePath)
     plugins = []
     plugins.append(
         {
             "ProjectID": "TestTextFileOutput",
             "InputSource": "{0}/house.txt".format(self.testDir),
             "Database":
             {
                 "Name": self.databaseName,
                 "Enable": True,
                 "Debug": False,
                 "Rebuild": False
             },
             "Workflow":
             {
                 "Plugin": "TextFile",
                 "Method": "runOutput",
                 "Target": "{0}/Tmp/houseResults.txt".format(self.testDir),
                 "Edit": False,
                 "Debug": False
             }
         }
     )
     plugins.append(
         {
             "ProjectID": "TestHtmlFileOutput",
             "InputSource": "{0}/house.txt".format(self.testDir),
             "Database":
             {
                 "Name": self.databaseName,
                 "Enable": True,
                 "Debug": False,
                 "Rebuild": False
             },
             "Workflow":
             {
                 "Plugin": "HtmlFile",
                 "Method": "runOutput",
                 "Target": "{0}/Tmp/houseResults.html".format(self.testDir),
                 "Edit": False,
                 "Debug": False
             }
         }
     )
     plugins.append(
         {
             "ProjectID": "TestJsonFileOutput",
             "InputSource": "{0}/house.txt".format(self.testDir),
             "Database":
             {
                 "Name": self.databaseName,
                 "Enable": True,
                 "Debug": False,
                 "Rebuild": False
             },
             "Workflow":
             {
                 "Plugin": "JsonFile",
                 "Method": "runOutput",
                 "Target": "{0}/Tmp/houseResults.json".format(self.testDir),
                 "Edit": False,
                 "Debug": False
             }
         }
     )
     for plugin in plugins:
         cfgEditor = CfgEditor()
         cfgEditor.loadCfg(self.cfgPath)
         cfgEditor.setDatabase(plugin["Database"])
         cfgEditor.setProjectID(plugin["ProjectID"])
         cfgEditor.setWorkflowInputSource(plugin["InputSource"])
         cfgEditor.setWorkflowPlugin("Output", plugin["Workflow"])
         cfgEditor.saveCfg(self.tmpCfgPath)
         cocoscats = Cocoscats(self.tmpCfgPath)
         cocoscats.initialize()
         Cli.run(cocoscats)
示例#4
0
 def purgeContentByTypes(self, contentTypes):
     for contentType in contentTypes:
         File.delete(self.frameworkParams[contentType])
示例#5
0
    def initialize(self, params):
        self.__PARAMS = params
        self.__ASSETS_DIR = "{0}/__YouTube".format(
            os.path.dirname(os.path.realpath(__file__)).replace('\\', '/'))
        self.__CLIENT_API_CAPTIONS_FILE = "{0}/youtube-v3-api-captions.json".format(
            self.__ASSETS_DIR)
        if not os.path.isfile(self.__CLIENT_API_CAPTIONS_FILE):
            raise Exception(
                "Missing YouTube API file file. Download it from Google and put in this path: {0}"
                .format(self.__CLIENT_API_CAPTIONS_FILE))
        self.__DOWNLOADED_PATH = "{0}/downloadedCaptions.srt".format(
            self.__ASSETS_DIR)
        self.__TRANSLATED_PATH = "{0}/translatedCaptions.txt".format(
            self.__ASSETS_DIR)
        self.__CLIENT_SECRETS_FILE = "{0}/client_secrets.json".format(
            self.__PARAMS["VaultPath"])
        if not os.path.isfile(self.__CLIENT_SECRETS_FILE):
            raise Exception(
                "Missing client_secrets.json file. Download it from your Google account and put under the Cocoscat's Vault directory"
            )
        self.__CLIENT_OAUTH2_ACCESS_TOKEN_FILE = "{0}/client_secrets_oauth2.json".format(
            self.__PARAMS["VaultPath"])
        parser = argparse.ArgumentParser(parents=[argparser])
        parser.add_argument(
            "--videoid",
            help="ID for video for which the caption track will be uploaded.",
            default=self.__PARAMS["URL"]["VideoID"])
        parser.add_argument("--name",
                            help="Caption track name",
                            default=self.__PARAMS["CaptionName"])
        parser.add_argument("--file", help="Captions track file to upload")
        parser.add_argument("--language",
                            help="Caption track language",
                            default=self.__PARAMS["L1"])
        parser.add_argument(
            "--captionid",
            help="Required; ID of the caption track to be processed")
        parser.add_argument("--action", help="Action", default="all")

        # Using argsparse is dumb idea in a class but it's not my design. I need to include main client's args
        # until I can figure a better way here to do this here
        parser.add_argument("-c",
                            "--cfg",
                            metavar="'cfg'",
                            type=str,
                            default="cfg.json",
                            help="JSON configuration file")
        parser.add_argument("-C",
                            "--cli",
                            action="store_true",
                            help="Run command line interface")
        parser.add_argument("-W",
                            "--web",
                            action="store_true",
                            help="Run web interface")

        self.__ARGS_PARSER = parser

        if Text.isTrue(self.__PARAMS["RefreshOAUTH2AccessToken"]):
            File.delete(self.__CLIENT_OAUTH2_ACCESS_TOKEN_FILE)

        if not File.exists(self.__CLIENT_OAUTH2_ACCESS_TOKEN_FILE):
            self.generateOAUTH2AccessToken()
示例#6
0
 def deleteCfg(self):
     if Text.isNone(self.cfgPath):
         return
     File.delete(self.cfgPath)
示例#7
0
 def deletePassword():
     File.delete(Security.__passwordPath)