How to use the rbtools.commands.Command.server_options function in RBTools

To help you get started, we’ve selected a few RBTools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github reviewboard / rbtools / rbtools / commands / publish.py View on Github external
from __future__ import print_function

from rbtools.api.errors import APIError
from rbtools.commands import Command, CommandError
from rbtools.utils.commands import get_review_request


class Publish(Command):
    """Publish a specific review request from a draft."""
    name = "publish"
    author = "The Review Board Project"
    args = ""
    option_list = [
        Command.server_options,
        Command.repository_options,
    ]

    def main(self, request_id):
        """Run the command."""
        repository_info, tool = self.initialize_scm_tool(
            client_name=self.options.repository_type)
        server_url = self.get_server_url(repository_info, tool)
        api_client, api_root = self.get_api(server_url)

        request = get_review_request(request_id, api_root)

        try:
            draft = request.get_draft()
            draft = draft.update(public=True)
        except APIError as e:
github reviewboard / rbtools / rbtools / commands / diff.py View on Github external
from __future__ import print_function, unicode_literals

from rbtools.clients.errors import InvalidRevisionSpecError
from rbtools.commands import Command, CommandError


class Diff(Command):
    """Prints a diff to the terminal."""
    name = 'diff'
    author = 'The Review Board Project'
    args = '[revisions]'
    option_list = [
        Command.server_options,
        Command.diff_options,
        Command.repository_options,
        Command.perforce_options,
        Command.subversion_options,
    ]

    def main(self, *args):
        """Print the diff to terminal."""
        # The 'args' tuple must be made into a list for some of the
        # SCM Clients code. See comment in post.
        args = list(args)

        if self.options.revision_range:
            raise CommandError(
                'The --revision-range argument has been removed. To create a '
                'diff for one or more specific revisions, pass those '
github reviewboard / rbtools / rbtools / commands / attach.py View on Github external
class Attach(Command):
    """Attach a file to a review request."""
    name = 'attach'
    author = 'The Review Board Project'
    args = ' '
    option_list = [
        Option('--filename',
               dest='filename',
               default=None,
               help='Custom filename for the file attachment.'),
        Option('--caption',
               dest='caption',
               default=None,
               help='Caption for the file attachment.'),
        Command.server_options,
        Command.repository_options,
    ]

    def main(self, request_id, path_to_file):
        self.repository_info, self.tool = self.initialize_scm_tool(
            client_name=self.options.repository_type)
        server_url = self.get_server_url(self.repository_info, self.tool)
        api_client, api_root = self.get_api(server_url)

        request = get_review_request(request_id, api_root)

        try:
            with open(path_to_file, 'rb') as f:
                content = f.read()
        except IOError:
            raise CommandError('%s is not a valid file.' % path_to_file)
github reviewboard / rbtools / rbtools / commands / status.py View on Github external
class Status(Command):
    """Display review requests for the current repository."""
    name = 'status'
    author = 'The Review Board Project'
    description = 'Output a list of your pending review requests.'
    args = ''
    option_list = [
        Option('--all',
               dest='all_repositories',
               action='store_true',
               default=False,
               help='Shows review requests for all repositories instead '
                    'of just the detected repository.'),
        Command.server_options,
        Command.repository_options,
        Command.perforce_options,
        Command.tfs_options,
    ]
    # The number of spaces between the request's status and the request's id
    # and summary.
    TAB_SIZE = 3
    # The number of spaces after the end of the request's summary.
    PADDING = 5

    def tabulate(self, request_stats):
        """Print review request summary and status in a table.

        Args:
            request_stats (dict):
                A dict that contains statistics about each review request.
github reviewboard / rbtools / rbtools / commands / stamp.py View on Github external
option_list = [
        OptionGroup(
            name='Stamp Options',
            description='Controls the behavior of a stamp, including what '
                        'review request URL gets stamped.',
            option_list=[
                Option('-r', '--review-request-id',
                       dest='rid',
                       metavar='ID',
                       default=None,
                       help='Specifies the existing review request ID to '
                            'be stamped.'),
            ]
        ),
        Command.server_options,
        Command.repository_options,
        Command.diff_options,
        Command.perforce_options,
    ]

    def no_commit_error(self):
        raise CommandError('No existing commit to stamp on.')

    def _ask_review_request_match(self, review_request):
        question = ("Stamp with Review Request #%s: '%s'? "
                    % (review_request.id,
                       get_draft_or_current_value(
                           'summary', review_request)))

        return confirm(question)
github reviewboard / rbtools / rbtools / commands / post.py View on Github external
dest='change_only',
                       action='store_true',
                       default=False,
                       help='Updates fields from the change description, '
                            'but does not upload a new diff '
                            '(Perforce/Plastic only).'),
                Option('--diff-only',
                       dest='diff_only',
                       action='store_true',
                       default=False,
                       help='Uploads a new diff, but does not update '
                            'fields from the change description '
                            '(Perforce/Plastic only).'),
            ]
        ),
        Command.server_options,
        Command.repository_options,
        OptionGroup(
            name='Review Request Field Options',
            description='Options for setting the contents of fields in the '
                        'review request.',
            option_list=[
                Option('-g', '--guess-fields',
                       dest='guess_fields',
                       action='store',
                       config_key='GUESS_FIELDS',
                       nargs='?',
                       default=GUESS_AUTO,
                       const=GUESS_YES,
                       choices=GUESS_CHOICES,
                       help='Short-hand for --guess-summary '
                            '--guess-description.'),
github reviewboard / rbtools / rbtools / commands / patch.py View on Github external
Option('--print',
               dest='patch_stdout',
               action='store_true',
               default=False,
               help='Prints the patch to standard output instead of applying '
                    'it to the tree.',
               added_in='0.5.3'),
        Option('-R', '--revert',
               dest='revert_patch',
               action='store_true',
               default=False,
               help='Revert the given patch instead of applying it.\n'
                    'This feature does not work with Bazaar or Mercurial '
                    'repositories.',
               added_in='0.7.3'),
        Command.server_options,
        Command.repository_options,
    ]

    def get_patch(self, request_id, api_root, diff_revision=None):
        """Return the diff as a string, the used diff revision and its basedir.

        If a diff revision is not specified, then this will look at the most
        recent diff.
        """
        try:
            diffs = api_root.get_diffs(review_request_id=request_id)
        except APIError as e:
            raise CommandError('Error getting diffs: %s' % e)

        # Use the latest diff if a diff revision was not given.
        # Since diff revisions start a 1, increment by one, and
github reviewboard / rbtools / rbtools / commands / diff.py View on Github external
from __future__ import print_function, unicode_literals

from rbtools.clients.errors import InvalidRevisionSpecError
from rbtools.commands import Command, CommandError

import six


class Diff(Command):
    """Prints a diff to the terminal."""

    name = 'diff'
    author = 'The Review Board Project'
    args = '[revisions]'
    option_list = [
        Command.server_options,
        Command.diff_options,
        Command.branch_options,
        Command.repository_options,
        Command.git_options,
        Command.perforce_options,
        Command.subversion_options,
        Command.tfs_options,
    ]

    def main(self, *args):
        """Print the diff to terminal."""
        # The 'args' tuple must be made into a list for some of the
        # SCM Clients code. See comment in post.
        args = list(args)

        if self.options.revision_range:
github reviewboard / rbtools / rbtools / commands / logout.py View on Github external
import logging

from rbtools.commands import Command


class Logout(Command):
    """Logs out of a Review Board server.

    The session cookie will be removed into from the .rbtools-cookies
    file. The next RBTools command you run will then prompt for credentials.
    """

    name = 'logout'
    author = 'The Review Board Project'
    option_list = [
        Command.server_options,
    ]

    def main(self):
        """Run the command."""
        server_url = self.get_server_url(None, None)
        api_client, api_root = self.get_api(server_url)

        session = api_root.get_session(expand='user')

        if session.authenticated:
            api_client.logout()

            logging.info('You are now logged out of Review Board at %s',
                         api_client.domain)
        else:
            logging.info('You are already logged out of Review Board at %s',
github reviewboard / rbtools / rbtools / commands / close.py View on Github external
By default, the command will change the status to submitted. The
    user can provide an optional description for this action.
    """
    name = 'close'
    author = 'The Review Board Project'
    args = ''
    option_list = [
        Option('--close-type',
               dest='close_type',
               default=SUBMITTED,
               help='Either `submitted` or `discarded`.'),
        Option('--description',
               dest='description',
               default=None,
               help='An optional description accompanying the change.'),
        Command.server_options,
        Command.repository_options,
    ]

    def check_valid_type(self, close_type):
        """Check if the user specificed a proper type.

        Type must either be 'discarded' or 'submitted'. If the type
        is wrong, the command will stop and alert the user.
        """
        if close_type not in (SUBMITTED, DISCARDED):
            raise CommandError("%s is not valid type. Try '%s' or '%s'" % (
                self.options.close_type, SUBMITTED, DISCARDED))

    def main(self, request_id):
        """Run the command."""
        close_type = self.options.close_type