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 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): 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): 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 load(cls, filename, quiet=False): """Parse a configuration file and extract this script's configuration :param filename: the path to the config file :type filename: str """ if not os.path.isfile(filename): if not quiet: warn('{}: No such file or directory'.format(filename)) return parser = SafeConfigParser() try: with open(filename, 'r') as config: parser.readfp(config, filename) except ParsingError as why: fail('failed to parse configuration: {}'.format(config), why) cls._store_config(parser)
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} PARAMETERS change_list: list of string RETURNS a tuple with a list of ChangeInfo, and a list of unknown changes """ 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(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