Exemplo n.º 1
0
Arquivo: app.py Projeto: f0rk/cartman
    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)

        self.login()

        # Load the initial timestamp from the ticket page
        r = self.get("/ticket/%d" % ticket_id)
        timestamp = text.extract_timestamp(r.content)

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

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

        r = self.post("/ticket/%d" % ticket_id, {
            "ts": timestamp,
            "comment": comment,
            "action": "leave",
        })

        if "system-message" in r.content or r.status_code != 200:
            raise exceptions.FatalError("unable to save comment")
Exemplo n.º 2
0
Arquivo: app.py Projeto: f0rk/cartman
    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/%d" % ticket_id)
        timestamp = text.extract_timestamp(r.content)
        statuses = text.extract_statuses(r.content)

        # 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: %s)" % \
                                        ", ".join(statuses))
        else:
            status = text.extract_status_from_ticket_page(r.content)
            print("Current status: %s" % status)
            print("Available statuses: %s" % ", ".join(statuses))
            return

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

        r = self.post("/ticket/%d" % ticket_id, {
            "ts": timestamp,
            "action": status,
            "comment": comment,
        })

        if "system-message" in r.content or r.status_code != 200:
            raise exceptions.FatalError("unable to set status")