Exemplo n.º 1
0
    def run_open(self, ticket_id):
        """Open a ticket in your browser.

        usage: cm open ticket_id
        """
        ticket_id = text.validate_id(ticket_id)

        self.open_in_browser(ticket_id)
Exemplo n.º 2
0
Arquivo: app.py Projeto: strk/cartman
    def run_open(self, ticket_id):
        """Open a ticket in your browser.

        usage: cm open ticket_id
        """
        ticket_id = text.validate_id(ticket_id)

        self.open_in_browser(ticket_id)
Exemplo n.º 3
0
    def run_change(self, ticket_id, *values):
        """Make change to the given ticket_id.

        This command does not return anything if successful.

        TODO: support spawning an editor to change field values.

        usage: cm change ticket_id field=value [field=value...]

        """
        ticket_id = text.validate_id(ticket_id)

        if not values:
            raise exceptions.InvalidParameter("should provide at least one "
                                              "field change")
        fields_data = {}
        for v in values:
            s = v.split('=', 1)
            if len(s) != 2:
                raise exceptions.InvalidParameter(
                    "invalid value '{}', should be a field=value "
                    "pair".format(v))
            field = s[0].strip()
            value = s[1]
            fields_data["field_" + field] = value

        self.login()

        # Load the timestamps from the ticket page.
        r = self.get("/ticket/{}".format(ticket_id))
        timestamps = self._extract_timestamps(r.text)

        if self.message:
            comment = self.message
        elif self.add_comment:
            comment = self._read_comment()
        else:
            comment = ""

        data = {
            "action": "leave",
            "comment": comment,
            "submit": "Submit changes",
        }
        data.update(timestamps)
        data.update(fields_data)

        r = self.post("/ticket/{}".format(ticket_id), data)

        # Starting from 1.0+, the system-message element is always on the page,
        # only the style is changed.
        if self.trac_version >= (1, 0):
            token = 'system-message" style=""'
        else:
            token = "system-message"

        if token in r.text or r.status_code != 200:
            raise exceptions.FatalError("unable to save change")
Exemplo n.º 4
0
    def run_change(self, ticket_id, *values):
        """Make change to the given ticket_id.

        This command does not return anything if successful.

        TODO: support spawning an editor to change field values.

        usage: cm change ticket_id field=value [field=value...]

        """
        ticket_id = text.validate_id(ticket_id)

        if not values:
            raise exceptions.InvalidParameter("should provide at least one "
                                              "field change")
        fields_data = {}
        for v in values:
            s = v.split('=', 1)
            if len(s) != 2:
                raise exceptions.InvalidParameter(
                        "invalid value '{}', should be a field=value "
                        "pair".format(v))
            field = s[0].strip()
            value = s[1]
            fields_data["field_" + field] = value

        self.login()

        # Load the timestamps from the ticket page.
        r = self.get("/ticket/{}".format(ticket_id))
        timestamps = self._extract_timestamps(r.text)

        if self.message:
            comment = self.message
        elif self.add_comment:
            comment = self._read_comment()
        else:
            comment = ""

        data = {
            "action": "leave",
            "comment": comment,
            "submit": "Submit changes",
        }
        data.update(timestamps)
        data.update(fields_data)

        r = self.post("/ticket/{}".format(ticket_id), data)

        # Starting from 1.0+, the system-message element is always on the page,
        # only the style is changed.
        if self.trac_version >= (1, 0):
            token = 'system-message" style=""'
        else:
            token = "system-message"

        if token in r.text or r.status_code != 200:
            raise exceptions.FatalError("unable to save change")
Exemplo n.º 5
0
    def run_report(self, report_id=None):
        """List tickets from a given report number.

        usage: cm report ticket_id

        """
        report_id = text.validate_id(report_id)

        query_string = "/report/{}?format=tab".format(report_id)

        for t in self.get_tickets(query_string):
            print(t.format_title())
Exemplo n.º 6
0
Arquivo: app.py Projeto: strk/cartman
    def run_report(self, report_id=None):
        """List tickets from a given report number.

        usage: cm report report_id

        """
        output = []
        report_id = text.validate_id(report_id)

        query_string = "/report/{}?format=tab".format(report_id)

        for t in self.get_tickets(query_string):
            output.append(t.format_title())

        return output
Exemplo n.º 7
0
    def run_report(self, report_id=None):
        """List tickets from a given report number.

        usage: cm report report_id

        """
        output = []
        report_id = text.validate_id(report_id)

        query_string = "/report/{}?format=tab".format(report_id)

        self.login()

        for t in self.get_tickets(query_string):
            output.append(t.format_title())

        return output
Exemplo n.º 8
0
    def run_view(self, ticket_id):
        """Display a ticket summary.

        usage: cm view ticket_id

        """
        ticket_id = text.validate_id(ticket_id)

        query_string = "/ticket/{}?format=tab".format(ticket_id)

        t = next(self.get_tickets(query_string))
        title = t.format_title()

        print(ui.title(title))
        print("")

        print(t.description)
Exemplo n.º 9
0
    def run_status(self, ticket_id, status=None):
        """Updates the status of a ticket.

        usage: cm status ticket_id [new_status]

        """
        ticket_id = text.validate_id(ticket_id)

        self.login()

        # Get all the available actions for this ticket
        r = self.get("/ticket/{}".format(ticket_id))
        timestamps = self._extract_timestamps(r.text)
        statuses = text.extract_statuses(r.text)

        # A ``status`` was provided, try to find the exact match, else just
        # display the current status for this ticket, and the available ones.
        if status:
            status = text.fuzzy_find(status, statuses)

            if not status:
                raise exceptions.FatalError("bad status (for this ticket: {})"
                                            .format(", ".join(statuses)))
        else:
            status = text.extract_status_from_ticket_page(r.text)
            print("Current status: {}".format(status))
            print("Available statuses: {}".format(", ".join(statuses)))
            return

        if self.message:
            comment = self.message
        elif self.add_comment:
            comment = self._read_comment()
        else:
            comment = ""

        data = {
            "action": status,
            "comment": comment,
        }
        data.update(timestamps)

        r = self.post("/ticket/{}".format(ticket_id), data)

        if "system-message" in r.text or r.status_code != 200:
            raise exceptions.FatalError("unable to set status")
Exemplo n.º 10
0
    def run_status(self, ticket_id, status=None):
        """Updates the status of a ticket.

        usage: cm status ticket_id [new_status]

        """
        output = []
        ticket_id = text.validate_id(ticket_id)

        self.login()

        # Get all the available actions for this ticket
        r = self.get("/ticket/{}".format(ticket_id))
        statuses = text.extract_statuses(r.text)

        # Just display current status.
        if not status:
            status = self.extract_status_from_ticket_page(r.text)
            output.append("Current status: {}".format(status))
            if statuses:
                output.append("Available statuses: {}"
                              .format(", ".join(statuses)))
            return output

        if not status:
            raise exceptions.FatalError("bad status (acceptable: {})"
                                        .format(", ".join(statuses)))

        if self.message:
            comment = self.message
        elif self.add_comment:
            comment = self._read_comment()
        else:
            comment = ""

        # Not having a value for submit causes Trac to ignore the request.
        data = {
            "action": status,
            "comment": comment,
            "submit": "anything",
        }
        data.update(self._extract_timestamps(r.text))

        r = self.post("/ticket/{}".format(ticket_id), data)
Exemplo n.º 11
0
    def run_status(self, ticket_id, status=None):
        """Updates the status of a ticket.

        usage: cm status ticket_id [new_status]

        """
        output = []
        ticket_id = text.validate_id(ticket_id)

        self.login()

        # Get all the available actions for this ticket
        r = self.get("/ticket/{}".format(ticket_id))
        statuses = text.extract_statuses(r.text)

        # Just display current status.
        if not status:
            status = self.extract_status_from_ticket_page(r.text)
            output.append("Current status: {}".format(status))
            if statuses:
                output.append("Available statuses: {}".format(
                    ", ".join(statuses)))
            return output

        if not status:
            raise exceptions.FatalError("bad status (acceptable: {})".format(
                ", ".join(statuses)))

        if self.message:
            comment = self.message
        elif self.add_comment:
            comment = self._read_comment()
        else:
            comment = ""

        # Not having a value for submit causes Trac to ignore the request.
        data = {
            "action": status,
            "comment": comment,
            "submit": "anything",
        }
        data.update(self._extract_timestamps(r.text))

        r = self.post("/ticket/{}".format(ticket_id), data)
Exemplo n.º 12
0
    def run_comment(self, ticket_id):
        """Add a comment to the given ticket_id. This command does not return
        anything if successful. Command is cancelled if the content of the
        comment is empty.

        usage: cm comment ticket_id

        """
        ticket_id = text.validate_id(ticket_id)

        if self.message:
            comment = self.message
        else:
            comment = self._read_comment()

        if not comment.strip():
            raise exceptions.FatalError("empty comment, cancelling")

        self.login()

        # Load the timestamps from the ticket page.
        r = self.get("/ticket/{}".format(ticket_id))
        timestamps = self._extract_timestamps(r.text)

        data = {
            "comment": comment,
            "action": "leave",
            "submit": "Submit changes",
        }
        data.update(timestamps)

        r = self.post("/ticket/{}".format(ticket_id), data)

        # Starting from 1.0+, the system-message element is always on the page,
        # only the style is changed.
        if self.trac_version >= (1, 0):
            token = 'system-message" style=""'
        else:
            token = "system-message"

        if token in r.text or r.status_code != 200:
            raise exceptions.FatalError("unable to save comment")
Exemplo n.º 13
0
    def run_comment(self, ticket_id):
        """Add a comment to the given ticket_id. This command does not return
        anything if successful. Command is cancelled if the content of the
        comment is empty.

        usage: cm comment ticket_id

        """
        ticket_id = text.validate_id(ticket_id)

        if self.message:
            comment = self.message
        else:
            comment = self._read_comment()

        if not comment.strip():
            raise exceptions.FatalError("empty comment, cancelling")

        self.login()

        # Load the timestamps from the ticket page.
        r = self.get("/ticket/{}".format(ticket_id))
        timestamps = self._extract_timestamps(r.text)

        data = {
            "comment": comment,
            "action": "leave",
            "submit": "Submit changes",
        }
        data.update(timestamps)

        r = self.post("/ticket/{}".format(ticket_id), data)

        # Starting from 1.0+, the system-message element is always on the page,
        # only the style is changed.
        if self.trac_version >= (1, 0):
            token = 'system-message" style=""'
        else:
            token = "system-message"

        if token in r.text or r.status_code != 200:
            raise exceptions.FatalError("unable to save comment")
Exemplo n.º 14
0
    def run_view(self, ticket_id):
        """Display a ticket summary.

        usage: cm view ticket_id

        """
        ticket_id = text.validate_id(ticket_id)

        query_string = "/ticket/{}?format=tab".format(ticket_id)

        self.login()

        t = next(self.get_tickets(query_string))
        title = t.format_title()

        return [
            ui.title(title),
            "",
            t.description,
        ]
Exemplo n.º 15
0
    def run_view(self, ticket_id):
        """Display a ticket summary.

        usage: cm view ticket_id

        """
        ticket_id = text.validate_id(ticket_id)

        query_string = "/ticket/{}?format=tab".format(ticket_id)

        self.login()

        t = next(self.get_tickets(query_string))
        title = t.format_title()

        return [
            ui.title(title),
            "",
            t.description,
        ]
Exemplo n.º 16
0
 def test_validate_id_str_good(self):
     self.assertEquals(text.validate_id("12"), 12)
Exemplo n.º 17
0
 def test_validate_id_str_good(self):
     self.assertEquals(text.validate_id("12"), 12)