Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
    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))
Ejemplo n.º 4
0
    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))
Ejemplo n.º 5
0
    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))
Ejemplo n.º 6
0
    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))
Ejemplo n.º 7
0
    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))
Ejemplo n.º 8
0
Archivo: show.py Proyecto: sjl421/pycr
    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
Ejemplo n.º 9
0
    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
Ejemplo n.º 10
0
Archivo: show.py Proyecto: sjl421/pycr
    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))
Ejemplo n.º 11
0
    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))
Ejemplo n.º 12
0
    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))
Ejemplo n.º 13
0
    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))
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
    def raw_str(self):
        """
        Return a simple string (no formatting).

        RETURNS
            the non-decorated version of __str__
        """

        return Formatter.raw_format(self.tokenize())
Ejemplo n.º 16
0
    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))
Ejemplo n.º 17
0
    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))
Ejemplo n.º 18
0
 def __str__(self):
     return Formatter.format(self.tokenize())
Ejemplo n.º 19
0
    def raw_str(self):
        """Return a simple string (no formatting)

        :rtype: str
        """
        return Formatter.raw_format(self.tokenize())
Ejemplo n.º 20
0
 def __str__(self):
     return Formatter.format(self.tokenize())
Ejemplo n.º 21
0
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
Ejemplo n.º 22
0
    def raw_str(self):
        """Return a simple string (no formatting)

        :rtype: str
        """
        return Formatter.raw_format(self.tokenize())