예제 #1
0
    def get_ticket_details(self, ticket_number):
        data = self.get_ticket_info_from_db(ticket_number)

        if data:
            return data
        if not data:
            logger.debug("Gathering data from Chiliproject API")
            try:
                request = urllib2.Request(self.issue_format % ticket_number)
                request.add_header(
                    "Authorization",
                    base64.encodestring(
                        "%s:%s" % (self.username, self.password)).replace(
                            "\n", ""))
                result = urllib2.urlopen(request).read()
                data = json.loads(result)
                self.store_ticket_info_in_db(
                    ticket_number,
                    data["issue"]["project"]["name"],
                    data["issue"]["subject"],
                )
                return (
                    data["issue"]["project"]["name"],
                    data["issue"]["subject"],
                )
            except urllib2.HTTPError as e:
                logger.debug("Encountered an HTTP Exception while " +
                             "gathering data. %s" % e)
            except Exception as e:
                logger.exception(e)
예제 #2
0
 def store_ticket_info_in_db(self, ticket_number, project, details):
     logger.debug("Storing ticket information for %s" % ticket_number)
     try:
         self.db.execute("""
             INSERT INTO ticket_details (number, project, details)
             VALUES (?, ?, ?)
             """, (ticket_number, project, details, ))
     except sqlite3.OperationalError as e:
         logger.exception(e)
예제 #3
0
 def get_ticket_info_from_db(self, ticket_number):
     try:
         logger.debug("Checking in DB for %s" % ticket_number)
         return self.db.execute("""
             SELECT project, details FROM ticket_details
             WHERE number = ?
             """, (ticket_number, )).fetchall()[0]
     except IndexError as e:
         logger.debug("No information in DB for %s" % ticket_number)
         return None
예제 #4
0
 def get_ticket_info_from_db(self, ticket_number):
     try:
         logger.debug("Checking in DB for %s" % ticket_number)
         return self.db.execute(
             """
             SELECT project, details FROM ticket_details
             WHERE number = ?
             """, (ticket_number, )).fetchall()[0]
     except IndexError as e:
         logger.debug("No information in DB for %s" % ticket_number)
         return None
예제 #5
0
 def store_ticket_info_in_db(self, ticket_number, project, details):
     logger.debug("Storing ticket information for %s" % ticket_number)
     try:
         self.db.execute(
             """
             INSERT INTO ticket_details (number, project, details)
             VALUES (?, ?, ?)
             """, (
                 ticket_number,
                 project,
                 details,
             ))
     except sqlite3.OperationalError as e:
         logger.exception(e)
예제 #6
0
    def get_ticket_details(self, ticket_number):
        data = self.get_ticket_info_from_db(ticket_number)

        if data:
            return data
        if not data:
            logger.debug("Gathering data from Chiliproject API")
            try:
                request = urllib2.Request(self.issue_format % ticket_number)
                request.add_header(
                            "Authorization",
                            base64.encodestring(
                                    "%s:%s" % (
                                            self.username,
                                            self.password
                                        )
                                ).replace("\n", "")
                        )
                result = urllib2.urlopen(request).read()
                data = json.loads(result)
                self.store_ticket_info_in_db(
                            ticket_number,
                            data["issue"]["project"]["name"],
                            data["issue"]["subject"],
                        )
                return (
                            data["issue"]["project"]["name"],
                            data["issue"]["subject"],
                        )
            except urllib2.HTTPError as e:
                logger.debug(
                    "Encountered an HTTP Exception while "
                    + "gathering data. %s" % e
                    )
            except Exception as e:
                logger.exception(e)