def run(self, arguments, *args, **kwargs): account_id = self.parse_command_line(arguments) try: account = Gerrit.get_account(account_id or 'self') emails = Gerrit.get_emails(account_id or 'self') except PyCRError as why: fail('cannot list account emails', why) table = PrettyTable(['Email', 'Preferred', 'Confirmed']) table.align = 'l' for email in emails: table.add_row([ email.email, checkmark(True) if email.preferred else '', 'No' if email.pending_confirmation else 'Yes' ]) with Pager(command=self.name): print 'Account: {}'.format(account.username) if emails: print table else: print 'No email address'
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): account_id = self.parse_command_line(arguments) try: account = Gerrit.get_account(account_id or 'self') keys = Gerrit.get_ssh_keys(account_id or 'self') except PyCRError as why: fail('cannot list account SSH keys', why) table = PrettyTable( ['Id', 'Algorithm', 'Comment', 'Valid', 'Encoded key']) table.align = 'l' for key in keys: table.add_row([ key.seq, key.algorithm, key.comment, checkmark(key.valid), key.encoded_key ]) with Pager(command=self.name): print 'Account: {}'.format(account.username) if keys: print table else: print 'No SSH keys'
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 parse_command_line(arguments): """Parse the LIST command command-line arguments :param arguments: a list of command-line arguments to parse :type arguments: list[str] :rtype: str, str, bool """ parser = argparse.ArgumentParser( description='List changes by owner and status') parser.add_argument( '--status', default='open', choices=Gerrit.get_all_statuses(), help='the status of the changes (default: open)') exclusive = parser.add_mutually_exclusive_group() exclusive.add_argument( '--owner', default='self', help='the owner of the changes (default: self)') exclusive.add_argument( '--watched', default=False, action='store_true', help='list only watched changes') cmdline = parser.parse_args(arguments) # Fetch changes details return cmdline.owner, cmdline.status, cmdline.watched
def parse_command_line(arguments): """Parse the LIST command command-line arguments :param arguments: a list of command-line arguments to parse :type arguments: list[str] :rtype: str, str, bool """ parser = argparse.ArgumentParser( description='List changes by owner and status') parser.add_argument('--status', default='open', choices=Gerrit.get_all_statuses(), help='the status of the changes (default: open)') exclusive = parser.add_mutually_exclusive_group() exclusive.add_argument('--owner', default='self', help='the owner of the changes (default: self)') exclusive.add_argument('--watched', default=False, action='store_true', help='list only watched changes') cmdline = parser.parse_args(arguments) # Fetch changes details return cmdline.owner, cmdline.status, cmdline.watched
def fetch_change_list(change_list): """Convert a list of changes or change ranges into a list of ChangeInfo The input list accepts the following string elements: - a change number: POSITIVE - a range of change numbers: POSITIVE..POSITIVE - a change-id: I[0-9a-f]{8,40} :param change_list: the list of changes :type change_list: list[str] :rtype: list[ChangeInfo] """ change_ids = [] for change in change_list: if CHANGE_ID.match(change) or LEGACY_CHANGE_ID.match(change): change_ids.append(change) elif LEGACY_CHANGE_ID_RANGE.match(change): change_ids.extend([str(i) for i in expand_change_range(change)]) else: warn('invalid Change-Id: %s' % change) change_infos = [] for change_id in change_ids: try: change_infos.append(Gerrit.get_change(change_id)) except NoSuchChangeError: pass return change_infos
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 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): account_id = self.parse_command_line(arguments) try: account = Gerrit.get_account(account_id or 'self') prefs = Gerrit.get_diff_prefs(account_id or 'self') except PyCRError as why: fail('cannot list account diff preferences', why) table = PrettyTable(['Preference', 'Value']) table.align['Preference'] = 'l' table.align['Value'] = 'c' table.add_row(['Context', prefs.context]) table.add_row( ['Expand all comments', checkmark(prefs.expand_all_comments)]) table.add_row(['Ignore whitespace', prefs.ignore_whitespace]) table.add_row( ['Intraline difference', checkmark(prefs.intraline_difference)]) table.add_row(['Line length', prefs.line_length]) table.add_row(['Manual review', checkmark(prefs.manual_review)]) table.add_row(['Retain header', checkmark(prefs.retain_header)]) table.add_row( ['Show line endings', checkmark(prefs.show_line_endings)]) table.add_row(['Show tabs', checkmark(prefs.show_tabs)]) table.add_row([ 'Show whitespace errors', checkmark(prefs.show_whitespace_errors) ]) table.add_row(['Skip deleted', checkmark(prefs.skip_deleted)]) table.add_row(['Skip uncommented', checkmark(prefs.skip_uncommented)]) table.add_row( ['Syntax highlighting', checkmark(prefs.syntax_highlighting)]) table.add_row(['Tab size', prefs.tab_size]) with Pager(command=self.name): print 'Account: {}'.format(account.username) print table
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 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 run(self, arguments, *args, **kwargs): account_id = self.parse_command_line(arguments) try: account = Gerrit.get_account(account_id or 'self') prefs = Gerrit.get_diff_prefs(account_id or 'self') except PyCRError as why: fail('cannot list account diff preferences', why) table = PrettyTable(['Preference', 'Value']) table.align['Preference'] = 'l' table.align['Value'] = 'c' table.add_row(['Context', prefs.context]) table.add_row(['Expand all comments', checkmark(prefs.expand_all_comments)]) table.add_row(['Ignore whitespace', prefs.ignore_whitespace]) table.add_row(['Intraline difference', checkmark(prefs.intraline_difference)]) table.add_row(['Line length', prefs.line_length]) table.add_row(['Manual review', checkmark(prefs.manual_review)]) table.add_row(['Retain header', checkmark(prefs.retain_header)]) table.add_row(['Show line endings', checkmark(prefs.show_line_endings)]) table.add_row(['Show tabs', checkmark(prefs.show_tabs)]) table.add_row(['Show whitespace errors', checkmark(prefs.show_whitespace_errors)]) table.add_row(['Skip deleted', checkmark(prefs.skip_deleted)]) table.add_row(['Skip uncommented', checkmark(prefs.skip_uncommented)]) table.add_row(['Syntax highlighting', checkmark(prefs.syntax_highlighting)]) table.add_row(['Tab size', prefs.tab_size]) with Pager(command=self.name): print 'Account: {}'.format(account.username) print table
def run(self, arguments, *args, **kwargs): account_id = self.parse_command_line(arguments) try: account = Gerrit.get_account(account_id or 'self') keys = Gerrit.get_ssh_keys(account_id or 'self') except PyCRError as why: fail('cannot list account SSH keys', why) table = PrettyTable( ['Id', 'Algorithm', 'Comment', 'Valid', 'Encoded key']) table.align = 'l' for key in keys: table.add_row([key.seq, key.algorithm, key.comment, checkmark(key.valid), key.encoded_key]) with Pager(command=self.name): print 'Account: {}'.format(account.username) if keys: print table else: print 'No SSH keys'
def run(self, arguments, *args, **kwargs): account_id = self.parse_command_line(arguments) try: account = Gerrit.get_account(account_id or 'self') capabilities = Gerrit.get_capabilities(account_id or 'self') except PyCRError as why: fail('cannot list account capabilities', why) table = PrettyTable(['Capability', 'Value']) table.align['Capability'] = 'l' table.align['Value'] = 'c' table.add_row(['Administrate server', checkmark(capabilities.administrate_server)]) table.add_row(['Min Query limit', capabilities.query_limit.min]) table.add_row(['Max Query limit', capabilities.query_limit.max]) table.add_row(['Create account', checkmark(capabilities.create_account)]) table.add_row(['Create group', checkmark(capabilities.create_group)]) table.add_row(['Create project', checkmark(capabilities.create_project)]) table.add_row(['Email reviewers', checkmark(capabilities.email_reviewers)]) table.add_row(['Kill task', checkmark(capabilities.kill_task)]) table.add_row(['View caches', checkmark(capabilities.view_caches)]) table.add_row(['Flush caches', checkmark(capabilities.flush_caches)]) table.add_row(['View connections', checkmark(capabilities.view_connections)]) table.add_row(['View queue', checkmark(capabilities.view_queue)]) table.add_row(['Run GC', checkmark(capabilities.run_gc)]) with Pager(command=self.name): print 'Account: {}'.format(account.username) print table
def run(self, arguments, *args, **kwargs): account_id = self.parse_command_line(arguments) try: account = Gerrit.get_account(account_id or 'self') emails = Gerrit.get_emails(account_id or 'self') except PyCRError as why: fail('cannot list account emails', why) table = PrettyTable(['Email', 'Preferred', 'Confirmed']) table.align = 'l' for email in emails: table.add_row([email.email, checkmark(True) if email.preferred else '', 'No' if email.pending_confirmation else 'Yes']) with Pager(command=self.name): print 'Account: {}'.format(account.username) if emails: print table else: print 'No email address'
def run_get(arguments, *args, **kwargs): """???""" del args, kwargs parser = argparse.ArgumentParser(description='Display ssh key') parser.add_argument('account', type=str, help='account ID') parser.add_argument('uuid', type=int, help='SSH key ID') cmdline = parser.parse_args(arguments) try: key = Gerrit.get_ssh_key(cmdline.account, cmdline.uuid) except PyCRError as why: fail('cannot list account SSH keys', why) print key.ssh_public_key.strip()
def run(self, arguments, *args, **kwargs): account_ids = self.parse_command_line(arguments) try: accounts = (Gerrit.get_account(a) for a in account_ids or ['self']) except PyCRError as why: fail('cannot list accounts', why) table = PrettyTable(['Username', 'Name', 'Email']) table.align = 'l' for account in set(accounts): table.add_row([account.username, account.name, account.email]) with Pager(command=self.name): print table
def run(self, arguments, *args, **kwargs): account_id = self.parse_command_line(arguments) try: groups = Gerrit.get_groups(account_id or 'self') except PyCRError as why: fail('cannot list account groups', why) table = PrettyTable(['Group', 'Description', 'Visible to all']) table.align = 'l' table.align['Visible to all'] = 'c' for group in groups: table.add_row([group.name, group.description or '', checkmark(group.options.visible_to_all)]) with Pager(command=self.name): print table
def run(self, arguments, *args, **kwargs): account_id = self.parse_command_line(arguments) try: groups = Gerrit.get_groups(account_id or 'self') except PyCRError as why: fail('cannot list account groups', why) table = PrettyTable(['Group', 'Description', 'Visible to all']) table.align = 'l' table.align['Visible to all'] = 'c' for group in groups: table.add_row([ group.name, group.description or '', checkmark(group.options.visible_to_all) ]) with Pager(command=self.name): print table