def run(self, arguments, *args, **kwargs): change_id, score, message, label = self.parse_command_line(arguments) try: change = Gerrit.get_change(change_id) if message is None: initial_content = [ '', ('# Please enter the comment message for your review. ' 'Lines starting'), "# with '#' will be ignored.", '#' ] initial_content.extend( ['# %s' % line for line in change.raw_str().splitlines()]) initial_content.append('#') message = raw_input_editor(os.linesep.join(initial_content)) message = strip_comments(message) if score is None: score = ask('Please enter your review score', Gerrit.SCORES) review = Gerrit.set_review(score, message, change.uuid, label) except NoSuchChangeError as why: self.log.debug(str(why)) fail('invalid change') except PyCRError as why: fail('cannot post review', why) print Formatter.format(self.tokenize(change, review))
def run(self, arguments, *args, **kwargs): changes, to_add, to_del = self.parse_command_line(arguments) assert changes, 'unexpected empty list' for idx, change in enumerate(changes): added = [] deleted = [] # Add reviewers for account_id in to_add: try: reviewers = Gerrit.add_reviewer(change.uuid, account_id) if reviewers: added.extend(reviewers) except PyCRError as why: warn('{}: cannot assign reviewer {}'.format( change.change_id[:9], account_id), why) # Delete reviewers for account_id in to_del: try: review = Gerrit.delete_reviewer(change.uuid, account_id) if review: deleted.append(review.reviewer) except PyCRError as why: warn('{}: cannot delete reviewer {}'.format( change.change_id[:9], account_id), why) print Formatter.format(self.tokenize(idx, change, added, deleted))
def run(self, arguments, *args, **kwargs): """ The entry point for the SUBMIT command. Rebase revision. PARAMETERS arguments: a list of command-line arguments to parse """ change_id = Submit.parse_command_line(arguments) try: change = Gerrit.get_change(change_id) if not Gerrit.submit(change.uuid): fail('submit could not be merged') except NoSuchChangeError as why: self.log.debug(str(why)) fail('invalid change') except PyCRError as why: fail('cannot submit', why) print Formatter.format(Submit.tokenize(change))
def run(self, arguments, *args, **kwargs): changes, to_add, to_del = self.parse_command_line(arguments) assert changes, 'unexpected empty list' for idx, change in enumerate(changes): added = [] deleted = [] # Add reviewers for account_id in to_add: try: reviewers = Gerrit.add_reviewer(change.uuid, account_id) if reviewers: added.extend(reviewers) except PyCRError as why: warn( '{}: cannot assign reviewer {}'.format( change.change_id[:9], account_id), why) # Delete reviewers for account_id in to_del: try: review = Gerrit.delete_reviewer(change.uuid, account_id) if review: deleted.append(review.reviewer) except PyCRError as why: warn( '{}: cannot delete reviewer {}'.format( change.change_id[:9], account_id), why) print Formatter.format(self.tokenize(idx, change, added, deleted))
def run(self, arguments, *args, **kwargs): account_id = self.parse_command_line(arguments) try: changes = Gerrit.get_starred_changes(account_id or 'self') except PyCRError as why: fail('cannot list account starred changes', why) with Pager(command=self.name): for idx, change in enumerate(changes): print Formatter.format(self.tokenize(idx, change))
def run(self, arguments, *args, **kwargs): change_id = self.parse_command_line(arguments) try: change = Gerrit.rebase(change_id) except NoSuchChangeError as why: self.log.debug(str(why)) fail('invalid change') except PyCRError as why: fail('cannot rebase', why) print Formatter.format(self.tokenize(change))
def tokenize(idx, change, reviews, patch): """Token generator for the output. Yields a stream of tokens: tuple of (Token, string). :param idx: index of the change in the list of changes to fetch :type idx: int :param change: the change :type change: ChangeInfo :param reviews: the reviews attached to the change :type reviews: list[ReviewInfo] :param patch: the patch to display along the change :type patch: str :yield: tuple[Token, str] """ if idx: yield NEW_LINE for token in change.tokenize(): yield token yield NEW_LINE for review in reviews: yield NEW_LINE for token in review.tokenize(): yield token yield NEW_LINE yield NEW_LINE for token in Formatter.tokenize_diff(patch): yield token
def run(self, arguments, *args, **kwargs): changes = self.parse_command_line(arguments) assert changes, 'unexpected empty list' with Pager(command=self.name): for idx, change in enumerate(changes): try: reviews = Gerrit.get_reviews(change.uuid) patch = Gerrit.get_patch(change.uuid) except PyCRError as why: warn('%s: cannot list reviewers' % change.change_id[:9], why) continue print Formatter.format( self.tokenize(idx, change, reviews, patch))
def run(self, arguments, *args, **kwargs): change_id = self.parse_command_line(arguments) try: change = Gerrit.get_change(change_id) if not Gerrit.submit(change.uuid): fail('change could not be merged') except NoSuchChangeError as why: self.log.debug(str(why)) fail('invalid change') except PyCRError as why: fail('cannot submit', why) print Formatter.format(self.tokenize(change))
def build_cmdline_parser(): """ Build and return the command-line parser to use. RETURNS argparse.ArgumentParser """ # Create the parser object parser = argparse.ArgumentParser( description='Gerrit Code Review Command-line.') parser.add_argument( '--version', action='version', version='%(prog)s version ' + get_version()) # Activate debug logging. Do not provide this option in usage message parser.add_argument( '--debug', default=False, action='store_true', help=argparse.SUPPRESS) # Whether to use HTTP instead of HTTPS to connect to the remote parser.add_argument( '--unsecure', default=False, action='store_true', help='prefer HTTP over HTTPS (disabled by default)') # Username to use for authentication. # If provided, override the configuration file's value(s) and reset the # password to None (the user will be prompted the password at runtime). parser.add_argument( '--username', default=None, help='Gerrit Code Review HTTP digest authentication') # Hidden argument to select a custom Pygments formatter. # This is not a very user-friendly feature so do not litter the usage # message with it. parser.add_argument( '--formatter', default='terminal256', choices=sum([f.aliases for f in Formatter.get_all()], []), help=argparse.SUPPRESS) # Register builtins actions = parser.add_subparsers(dest='builtins', help='available builtins') # HELP command cl_help = actions.add_parser( 'help', help='display help information about %(prog)s builtins') cl_help.add_argument( 'builtin', nargs='?', help='display help for that builtin') # Register all builtins for cmd_class in get_all_subclasses(Builtin): cmd = cmd_class() subparser = actions.add_parser(cmd.name, add_help=False, help=cmd.description) subparser.set_defaults(command=cmd) return parser
def raw_str(self): """ Return a simple string (no formatting). RETURNS the non-decorated version of __str__ """ return Formatter.raw_format(self.tokenize())
def run(self, arguments, *args, **kwargs): owner, status, watched = self.parse_command_line(arguments) try: if watched: changes = Gerrit.list_watched_changes(status=status) else: changes = Gerrit.list_changes(status=status, owner=owner) except QueryError as why: # No result, not an error self.log.debug(str(why)) return except PyCRError as why: fail('cannot list changes', why) with Pager(command=self.name): for idx, change in enumerate(changes): print Formatter.format(self.tokenize(idx, change))
def __str__(self): return Formatter.format(self.tokenize())
def raw_str(self): """Return a simple string (no formatting) :rtype: str """ return Formatter.raw_format(self.tokenize())
def build_cmdline_parser(builtin_type): """Build and return the command-line parser to use :param builtin_type: the type of Builtin to look for :type builtin_type: Builtin :rtype: argparse.ArgumentParser """ # Create the parser object parser = argparse.ArgumentParser( description='Gerrit Code Review command line tools') parser.add_argument('--version', action='version', version='%(prog)s version ' + get_version()) # Activate debug logging. Do not provide this option in usage message parser.add_argument('--debug', default=False, action='store_true', help=argparse.SUPPRESS) # Whether to use HTTP instead of HTTPS to connect to the remote parser.add_argument('--unsecure', default=False, action='store_true', help='prefer HTTP over HTTPS (disabled by default)') # Username to use for authentication. # If provided, override the configuration file's value(s) and reset the # password to None (the user will be prompted the password at runtime). parser.add_argument('--username', default=None, help='Gerrit Code Review HTTP digest authentication') # Hidden argument to select a custom Pygments formatter. # This is not a very user-friendly feature so do not litter the usage # message with it. parser.add_argument('--formatter', default='terminal256', choices=sum([f.aliases for f in Formatter.get_all()], []), help=argparse.SUPPRESS) # Register builtins actions = parser.add_subparsers(dest='builtins', help='available builtins') # HELP command cl_help = actions.add_parser( 'help', help='display help information about %(prog)s builtins') cl_help.add_argument('builtin', nargs='?', help='display help for that builtin') # Register all builtins for cmd_class in get_all_subclasses(builtin_type): cmd = cmd_class() subparser = actions.add_parser(cmd.name, add_help=False, help=cmd.description) subparser.set_defaults(command=cmd) return parser