def main(argv=None): # parse the command line (parser, options, args) = parse_args(argv) # initialize client(may exit early for those no-arg commands) client = init_client(options) # prepare operations if len(args) == 0: parser.error("missing arguments") action, args, extra_args = get_action(client, parser, options, args) # begin operations operate = getattr(client, action) errors = 0 for arg in args: try: if isinstance(arg, basestring): result = operate(arg, *extra_args) # elif all(isinstance(i, basestring) for i in arg): else: result = operate(*(list(arg) + extra_args)) if result is not None: sys.stdout.write("{}\n".format(stringify(result))) sys.stdout.write("action {} on {} succeeded\n".format( action, stringify(arg))) except Exception as e: errors += 1 sys.stdout.write("action {} on {} failed\n".format( action, stringify(arg))) logger.exception(u"error: {}\n".format(e)) if errors > 0: sys.stderr.write("encountered {} error(s)\n".format(errors)) return 1 return 0
def main(argv=None): # parse the command line (parser, options, args) = parse_args(argv) # initialize client(may exit early for those no-arg commands) client = init_client(options) # prepare operations if len(args) == 0: parser.error("no arguments for the given option") action, args, extra_args = get_action(client, parser, options, args) # begin operations operate = getattr(client, action) errors = 0 for arg in args: try: if isinstance(arg, basestring): result = operate(arg, *extra_args) #elif all(isinstance(i, basestring) for i in arg): else: result = operate(*(list(arg) + extra_args)) if result is not None: print stringify(result) print "action {} on {} succeeded".format(action, stringify(arg)) except Exception as e: errors += 1 print "action {} on {} failed".format(action, stringify(arg)) sys.stderr.write("error: {}\n".format(e)) logger.exception(e) if errors > 0: sys.stderr.write("encountered {} error(s)\n".format(errors)) return 1 return 0
def _log_response(response): """Log response""" logger.debug("response: {}".format(stringify(response)))