Exemplo n.º 1
0
 def certsAndKeysExist():
     for path in [
             Security.__privateKeyPath, Security.__publicKeyPath,
             Security.__certificatePemPath
     ]:
         if not File.exists(path):
             return False
     if Security.hasOpenSSL():
         return File.exists(Security.__certificateCrtPath)
     return True
Exemplo n.º 2
0
 def getCredentials(self):
     stack = inspect.stack()
     className = str(stack[1][0].f_locals["self"].__class__.__name__)
     path = "{0}/{1}.json".format(Framework.getVaultDir(), className)
     if not File.exists(path):
         self.raiseException(
             "Missing {0} credentials file".format(className))
     return File.getContent(path, asJson=True)
Exemplo n.º 3
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()
Exemplo n.º 4
0
 def hasPasswordFile():
     return File.exists(Security.__passwordPath)