示例#1
0
    def prepare_to_run_command(self, cmd):
        # Check for config
        if not os.path.exists(constants.REPOS_CONFIG_FILE):
            print(f"{constants.REPOS_CONFIG_FILE} not found.")

            if not os.path.exists(constants.WORK_DIR):
                os.makedirs(constants.WORK_DIR)

            with open(constants.REPOS_CONFIG_FILE, "wb") as conf_file:
                remote_file = requests.get(constants.DEFAULT_CONFIG_URL)
                conf_file.write(remote_file.content)

                print("Generated default config")

        _ = ConfigFactory.get_instance()
示例#2
0
    def take_action(self, parsed_args):
        repo_name = parsed_args.repo if parsed_args.repo else constants.DEFAULT_REPO_NAME
        artifact_name = parsed_args.artifact
        repo = ConfigFactory.get_instance().get_repo(repo_name)

        repo_url, catalog_name = repo["url"], repo["catalog"]
        artifact_url = f"{repo_url}/catalogs/{catalog_name}/{artifact_name}.tar.gz"

        artifact = requests.get(artifact_url)
        with open(f"{os.getcwd()}/{artifact_name}", "wb") as artifact_archive:
            artifact_archive.write(artifact.content)

        artifact_file = tarfile.open(f"{os.getcwd()}/{artifact_name}", "r:gz")
        try:
            artifact_file.extractall()
        finally:
            artifact_file.close()