From 9ba7bea6e9af96bc733559196a14ffbe2dcb8da3 Mon Sep 17 00:00:00 2001 From: Adrian Damian Date: Wed, 31 Jan 2024 10:13:23 -0800 Subject: [PATCH] Rework after code review --- vos/vos/commands/vchmod.py | 4 ++-- vos/vos/commands/vrm.py | 6 +++--- vos/vos/commands/vtag.py | 16 ++++++++-------- vos/vos/vos.py | 28 ---------------------------- 4 files changed, 13 insertions(+), 41 deletions(-) diff --git a/vos/vos/commands/vchmod.py b/vos/vos/commands/vchmod.py index c8ac4233..10e7b78a 100755 --- a/vos/vos/commands/vchmod.py +++ b/vos/vos/commands/vchmod.py @@ -202,11 +202,11 @@ def vchmod(): successes, failures = client.update(node, opt.recursive) if opt.recursive: if failures: - sys.stderr.write('WARN. updated count: {}, failed count: {}\n'. + logging.error('WARN. updated count: {}, failed count: {}\n'. format(successes, failures)) sys.exit(-1) else: - sys.stdout.write('DONE. updated count: {}\n'.format(successes)) + logging.info('DONE. updated count: {}\n'.format(successes)) except Exception as ex: exit_on_exception(ex) diff --git a/vos/vos/commands/vrm.py b/vos/vos/commands/vrm.py index cedbe6c5..601de71a 100755 --- a/vos/vos/commands/vrm.py +++ b/vos/vos/commands/vrm.py @@ -84,7 +84,7 @@ def vrm(): parser = CommonParser(description=DESCRIPTION) parser.add_argument( - "-r", "--recursive", action="store_true", + "-R", "--recursive", action="store_true", help="Delete a file or directory even if it's not empty.", default=False) parser.add_argument('node', @@ -106,11 +106,11 @@ def vrm(): if args.recursive: successes, failures = client.recursive_delete(node) if failures: - sys.stderr.write('WARN. deleted count: {}, failed count: ' + logging.error('WARN. deleted count: {}, failed count: ' '{}\n'.format(successes, failures)) sys.exit(-1) else: - sys.stdout.write( + logging.info( 'DONE. deleted count: {}\n'.format(successes)) else: if not node.endswith('/'): diff --git a/vos/vos/commands/vtag.py b/vos/vos/commands/vtag.py index 443addaa..633e5ad7 100755 --- a/vos/vos/commands/vtag.py +++ b/vos/vos/commands/vtag.py @@ -71,6 +71,7 @@ The tag system is meant to allow tags, in addition to the standard node properties. """ +import logging import pprint import sys from ..commonparser import CommonParser, set_logging_level_from_args, \ @@ -111,8 +112,7 @@ def vtag(): parser.add_option('-R', '--recursive', action="store_true", help='perform the operation recursively on all the descendants') - opt = parser.parse_args() - args = opt + args = parser.parse_args() set_logging_level_from_args(args) # the node should be the first argument, the rest should contain @@ -131,9 +131,9 @@ def vtag(): try: client = vos.Client( - vospace_certfile=opt.certfile, - vospace_token=opt.token, - insecure=opt.insecure) + vospace_certfile=args.certfile, + vospace_token=args.token, + insecure=args.insecure) node = client.get_node(node_arg) if len(props) == 0: # print all properties @@ -147,14 +147,14 @@ def vtag(): value = None node.props[key] = value successes, failures = client.add_props(node, recursive=True) - if opt.recursive: + if args.recursive: if failures: - sys.stderr.write( + logging.error( 'WARN. updated count: {}, failed count: {}\n'. format(successes, failures)) sys.exit(-1) else: - sys.stdout.write( + logging.info( 'DONE. updated count: {}\n'.format(successes)) else: changed = False diff --git a/vos/vos/vos.py b/vos/vos/vos.py index 72ea18cf..5b0140bc 100644 --- a/vos/vos/vos.py +++ b/vos/vos/vos.py @@ -2715,34 +2715,6 @@ def update(self, node, recursive=False): + response.status_code) return self._run_recursive_job(session, response.headers['location']) - # else: - # # TODO this is deprecated and should be removed soon - # try: - # property_url = endpoints.properties - # except KeyError as ex: - # logger.debug('Endpoint does not exist: {0}'.format(str(ex))) - # raise Exception('Operation not supported') - # - # logger.debug("prop URL: {0}".format(property_url)) - # try: - # resp = session.post( - # property_url, allow_redirects=False, data=str(node), - # headers={'Content-type': 'text/xml'}) - # except Exception as ex: - # logger.error(str(ex)) - # raise ex - # if resp is None: - # raise OSError(errno.EFAULT, "Failed to connect VOSpace") - # logger.debug("Got prop-update response: {0}".format(resp.content)) - # transfer_url = resp.headers.get('Location', None) - # logger.debug("Got job status redirect: {0}".format(transfer_url)) - # # Start the job - # session.post( - # transfer_url + "/phase", - # allow_redirects=False, - # data="PHASE=RUN", - # headers={'Content-type': "application/x-www-form-urlencoded"}) - # self.get_transfer_error(transfer_url, node.uri) else: resp = session.post(url, data=str(node), allow_redirects=False) logger.debug("update response: {0}".format(resp.content))