Ejemplo n.º 1
0
    def main(self, path, *args):
        query_args = {}
        query_arg_re = re.compile('^--(?P<name>.*)=(?P<value>.*)$')

        for arg in args:
            m = query_arg_re.match(arg)

            if m:
                query_args[m.group('name')] = m.group('value')
            else:
                raise ParseError("Unexpected query argument %s" % arg)

        self.repository_info, self.tool = self.initialize_scm_tool()
        server_url = self.get_server_url(self.repository_info, self.tool)
        api_client, api_root = self.get_api(server_url)

        try:
            if path.startswith('http://') or path.startswith('https://'):
                resource = api_client.get_url(path, **query_args)
            else:
                resource = api_client.get_path(path, **query_args)
        except APIError, e:
            if e.rsp:
                print self._dumps(e.rsp)
                raise CommandExit(1)
            else:
                raise CommandError('Could not retrieve the requested '
                                   'resource: %s' % e)
Ejemplo n.º 2
0
    def main(self, path, *args):
        query_args = {}
        query_arg_re = re.compile('^--(?P<name>.*)=(?P<value>.*)$')

        for arg in args:
            m = query_arg_re.match(arg)

            if m:
                query_args[m.group('name')] = m.group('value')
            else:
                raise ParseError('Unexpected query argument %s' % arg)

        try:
            if path.startswith('http://') or path.startswith('https://'):
                resource = self.api_client.get_url(path, **query_args)
            else:
                resource = self.api_client.get_path(path, **query_args)
        except APIError as e:
            if e.rsp:
                self.stdout.write(self._dumps(e.rsp))
                raise CommandExit(1)
            else:
                raise CommandError('Could not retrieve the requested '
                                   'resource: %s' % e)

        self.stdout.write(self._dumps(resource.rsp))
Ejemplo n.º 3
0
    def get_status_update(self, api_root):
        """Handle getting status update information from Review Board.

        Args:
            api_root (rbtools.api.transport.Transport):
                Representation of the root level of the Review Board API for
                doing further requests to the Review Board API.

        Raises:
            rbtools.commands.CommandError:
                Error with the execution of the command.

            rbtools.commands.CommandExit:
                Stop executing and return an exit status.
        """
        try:
            if self.options.sid:
                self.print(
                    api_root.get_status_update(
                        review_request_id=self.options.rid,
                        status_update_id=self.options.sid).rsp.get(
                            'status_update'))
            else:
                self.print(
                    api_root.get_status_updates(review_request_id=self.options.
                                                rid).rsp.get('status_updates'))
        except APIError as e:
            if e.rsp:
                print(json.dumps(e.rsp, indent=2))
                raise CommandExit(1)
            else:
                raise CommandError('Could not retrieve the requested '
                                   'resource: %s' % e)
Ejemplo n.º 4
0
    def get_status_update(self):
        """Handle getting status update information from Review Board.

        Raises:
            rbtools.commands.CommandError:
                Error with the execution of the command.

            rbtools.commands.CommandExit:
                Stop executing and return an exit status.
        """
        try:
            if self.options.sid:
                self.print(
                    self.api_root.get_status_update(
                        review_request_id=self.options.rid,
                        status_update_id=self.options.sid).rsp.get(
                            'status_update'))
            else:
                self.print(
                    self.api_root.get_status_updates(
                        review_request_id=self.options.rid).rsp.get(
                            'status_updates'))
        except APIError as e:
            if e.rsp:
                self.stdout.write(json.dumps(e.rsp, indent=2))
                raise CommandExit(1)
            else:
                raise CommandError('Could not retrieve the requested '
                                   'resource: %s' % e)
Ejemplo n.º 5
0
    def set_status_update(self, api_root):
        """Handle setting status update information on Review Board.

        Args:
            api_root (rbtools.api.transport.Transport):
                Representation of the root level of the Review Board API for
                doing further requests to the Review Board API.

        Raises:
            rbtools.commands.CommandError:
                Error with the execution of the command.

            rbtools.commands.CommandExit:
                Stop executing and return an exit status.
        """
        # If a review file is specified, create review.
        new_review_draft = None
        review_draft_id = None

        if self.options.review:
            new_review_draft = self.add_review(api_root)
            review_draft_id = new_review_draft.id

        # Validate state option.
        allowed_state = ['pending', 'done-failure', 'done-success', 'error']

        if self.options.state and self.options.state not in allowed_state:
            raise CommandError('--state must be one of: %s' %
                               (', '.join(allowed_state)))

        # Build query args.
        request_parameters = [
            'change_id', 'description', 'service_id', 'state', 'summary',
            'timeout', 'url', 'url_text'
        ]

        options = vars(self.options)

        query_args = {
            parameter: options.get(parameter)
            for parameter in iter(request_parameters) if options.get(parameter)
        }

        # Attach review to status-update.
        if review_draft_id:
            query_args['review_id'] = review_draft_id

        try:
            if self.options.sid:
                status_update = api_root.get_status_update(
                    review_request_id=self.options.rid,
                    status_update_id=self.options.sid)

                status_update = status_update.update(**query_args)
            else:
                if not self.options.service_id or not self.options.summary:
                    raise CommandError('--service-id and --summary are '
                                       'required input for creating a new '
                                       'status update')

                status_update = api_root.get_status_updates(
                    review_request_id=self.options.rid)

                status_update = status_update.create(**query_args)

            # Make review public.
            if new_review_draft:
                new_review_draft.update(public=True)

            self.print(status_update.rsp.get('status_update'))
        except APIError as e:
            if e.rsp:
                print(json.dumps(e.rsp, indent=2))
                raise CommandExit(1)
            else:
                raise CommandError('Could not set the requested '
                                   'resource: %s' % e)