def rm(self, uuid): artifact_cache = ArtifactCache() try: artifact_cache.delete(uuid) click.echo("Artifact with UUID '{}' removed".format(uuid)) except Exception: # pylint: disable=broad-except click.secho("Artifact with UUID '{}' doesn't exists in the cache".format(uuid), fg='yellow') sys.exit(1)
def run(self): tools.cfg = tools.get_cfg(self.args.config) if self.args.verbose: logger.setLevel(logging.DEBUG) else: logger.setLevel(logging.INFO) if self.args.work_dir: tools.cfg['common']['work_dir'] = self.args.work_dir if self.args.cmd == 'add': artifact_cache = ArtifactCache() resource = {} resource['url'] = self.args.url for alg in SUPPORTED_HASH_ALGORITHMS: val = getattr(self.args, alg) if val: resource[alg] = val artifact = Resource(resource) if artifact_cache.is_cached(artifact): print('Artifact is already cached!') sys.exit(0) try: artifact_id = artifact_cache.add(artifact) if self.args.verbose: print(artifact_id) except Exception as ex: if self.args.verbose: traceback.print_exc() else: print(ex) sys.exit(1) if self.args.cmd == 'ls': self.list() if self.args.cmd == 'rm': try: artifact_cache = ArtifactCache() artifact_cache.delete(self.args.uuid) print("Artifact removed") except Exception: print("Artifact doesn't exists") sys.exit(1) sys.exit(0)