Exemplo n.º 1
0
    def _fetch_tickets(self, db=None):
        """
        Fetch from the DB the ids, type, status of the tickets planned for this sprint,
        and returns a list of id, type, status.
        """
        params = {"table": BACKLOG_TICKET_TABLE, "scope": self.name}
        t_sql = (
            "SELECT DISTINCT id, type, status FROM ticket INNER JOIN ticket_custom ON "
            "ticket.id=ticket_custom.ticket LEFT OUTER JOIN %(table)s ON "
            "ticket.id=%(table)s.ticket_id WHERE (%(table)s.name='Sprint Backlog' "
            "AND scope='%(scope)s') or (ticket_custom.name='sprint' AND "
            "ticket_custom.value='%(scope)s')" % params
        )

        tickets = [(0, "", "")]

        db, handle_ta = get_db_for_write(self.env, db)
        try:
            cursor = db.cursor()
            debug(self, "SQL (_fetch_tickets_stats): %s" % t_sql)
            cursor.execute(t_sql)
            tickets = cursor.fetchall()
        except:
            if handle_ta:
                db.rollback()
        return tickets
Exemplo n.º 2
0
 def create_milestone(self, name, due=None, duration=20, db=None):
     """
     Creates a milestone with the given name and due
     date, the latter should be a datetime object
     """
     db, handle_ta = get_db_for_write(self.env, db)
     # Try to load the milestone first
     try:
         m = Milestone(self.env, name=name, db=db)
     except ResourceNotFound:
         # than we create it
         m = Milestone(self.env, db=db)
         m.name = name
         if due is not None and isinstance(due, datetime):
             dueo = due.toordinal() + duration
             m.due = mktime(datetime.fromordinal(dueo).timetuple())
         m.insert()
         if handle_ta:
             try:
                 db.commit()
                 # workaround for the fact that trac in 0.11.1 doesn't set exists correctly...
                 m._old_name = m.name
             except Exception, e:
                 self.env.log.warning(exception_to_unicode(e))
                 db.rollback()
Exemplo n.º 3
0
 def save(self, db=None):
     """saves the object to the database"""
     db, handle_ta = get_db_for_write(self.env, db)
     try:
         for o_day, hours in self._calendar.items():
             entry = self.ce_manager.get(date=o_day, teammember=self.team_member, db=db)
             if not entry:
                 entry = self.ce_manager.create(date=o_day, teammember=self.team_member, db=db)
             # Save only exceptions
             if hours != self.team_member.capacity[datetime.fromordinal(o_day).date().weekday()]:
                 entry.hours = hours
                 self.ce_manager.save(entry, db=db)
             elif entry.exists: # we don't need it anymore
                 self.ce_manager.delete(entry, db=db)
         if handle_ta:
             db.commit()
         # Invalidate the Chart generator cache cause the capacity may be changed
         from agilo.charts import ChartGenerator
         ChartGenerator(self.env).invalidate_cache()
         return True
     except Exception, e:
         error(self, _("An error occurred while saving Calendar Entry: %s" % to_unicode(e)))
         if handle_ta:
             db.rollback()
         raise
Exemplo n.º 4
0
 def _save(self, timestamp, value, update=False, db=None):
     """Saves a remaining time value to the database. The update parameter
     decides if the value should be updated (True) or inserted (False)"""
     params = {
         Key.TABLE : BURNDOWN_TABLE,
         Key.TASK_ID : self.task.id,
         Key.DATE : timestamp,
         Key.REMAINING_TIME : value,
     }
     if update:
         sql_query = "UPDATE %(table)s SET remaining_time=%(remaining_time)d " \
                     "WHERE task_id=%(task_id)d AND date=%(date)f" % params
     else:
         sql_query = "INSERT INTO %(table)s (task_id, date, remaining_time) " \
                     "VALUES (%(task_id)s, %(date)s, %(remaining_time)s)" % params
     
     db, handle_ta = get_db_for_write(self.env, db)
     try:
         cursor = db.cursor()
         cursor.execute(sql_query)
         if handle_ta:
             db.commit()
             debug(self, 
                   "DB Committed, saved remaining time (%s) for task %d" % \
                   (params[Key.REMAINING_TIME], self.task.id))
     except Exception, e:
         error(self, to_unicode(e))
         if handle_ta:
             db.rollback()
         raise TracError("Error while saving remaining time: %s" % \
                         to_unicode(e))
Exemplo n.º 5
0
 def create_milestone(self, name, due=None, duration=20, db=None):
     """
     Creates a milestone with the given name and due
     date, the latter should be a datetime object
     """
     db, handle_ta = get_db_for_write(self.env, db)
     # Try to load the milestone first
     try:
         m = Milestone(self.env, name=name, db=db)
     except ResourceNotFound:
         # than we create it
         m = Milestone(self.env, db=db)
         m.name = name
         if due is not None and isinstance(due, datetime):
             dueo = due.toordinal() + duration
             m.due = mktime(datetime.fromordinal(dueo).timetuple())
         m.insert()
         if handle_ta:
             try:
                 db.commit()
                 # workaround for the fact that trac in 0.11.1 doesn't set exists correctly...
                 m._old_name = m.name
             except Exception, e:
                 self.env.log.warning(exception_to_unicode(e))
                 db.rollback()
Exemplo n.º 6
0
 def save(self, db=None):
     """saves the object to the database"""
     db, handle_ta = get_db_for_write(self.env, db)
     try:
         for o_day, hours in self._calendar.items():
             entry = self.ce_manager.get(date=o_day,
                                         teammember=self.team_member,
                                         db=db)
             if not entry:
                 entry = self.ce_manager.create(date=o_day,
                                                teammember=self.team_member,
                                                db=db)
             # Save only exceptions
             if hours != self.team_member.capacity[datetime.fromordinal(
                     o_day).date().weekday()]:
                 entry.hours = hours
                 self.ce_manager.save(entry, db=db)
             elif entry.exists:  # we don't need it anymore
                 self.ce_manager.delete(entry, db=db)
         if handle_ta:
             db.commit()
         # Invalidate the Chart generator cache cause the capacity may be changed
         from agilo.charts import ChartGenerator
         ChartGenerator(self.env).invalidate_cache()
         return True
     except Exception, e:
         error(
             self,
             _("An error occurred while saving Calendar Entry: %s" %
               to_unicode(e)))
         if handle_ta:
             db.rollback()
         raise
Exemplo n.º 7
0
 def _rename(self, name, new_name, db=None):
     """Renames this sprint and reassigns all tickets to the new 
     name."""
     # avoid circular imports
     from agilo.scrum.metrics.model import TeamMetrics
     params = {
         'name' : name,
         'new_name' : new_name,
     }
     team_metrics_entry_table = TeamMetrics.TeamMetricsEntry._table.name
     queries = [
         "UPDATE ticket_custom SET value=%(new_name)s WHERE name='sprint' AND value=%(name)s",
         "UPDATE " + team_metrics_entry_table + " SET sprint=%(new_name)s WHERE sprint=%(name)s",
     ]
     db, handle_ta = get_db_for_write(self.env, db)
     try:
         cursor = db.cursor()
         for q in queries:
             debug(self, "RENAME => Executing query: %s (%s)" % (q, params))
             safe_execute(cursor, q, params)
         if handle_ta:
             db.commit()
     except Exception, e:
         if handle_ta:
             db.rollback()
         raise TracError("An error occurred while renaming sprint: %s" % to_unicode(e))
Exemplo n.º 8
0
 def _load(self, db=None):
     """Try to load the Sprint from the database"""
     db, handle_ta = get_db_for_write(self.env, db)
     sql_query = "SELECT date, remaining_time FROM %s" \
                 " WHERE task_id=%d ORDER BY date DESC" % (BURNDOWN_TABLE, self.task.id)
     debug(self, "Burndown-SQL Query: %s" % sql_query)
     try:
         history = dict()
         cursor = db.cursor()
         cursor.execute(sql_query)
         for row in cursor.fetchall():
             timestamp, remaining_time = row
             history[timestamp] = remaining_time
         
         self.loaded = True
     except Exception, e:
         error(self, to_unicode(e))
         if handle_ta:
             db.rollback()
         raise TracError("An error occurred while loading Burndown data: %s" % to_unicode(e))
Exemplo n.º 9
0
    def _rename(self, name, new_name, db=None):
        """Renames this sprint and reassigns all tickets to the new 
        name."""
        # avoid circular imports
        from agilo.scrum.metrics.model import TeamMetrics

        params = {"name": name, "new_name": new_name}
        team_metrics_entry_table = TeamMetrics.TeamMetricsEntry._table.name
        queries = [
            "UPDATE ticket_custom SET value=%(new_name)s WHERE name='sprint' AND value=%(name)s",
            "UPDATE " + team_metrics_entry_table + " SET sprint=%(new_name)s WHERE sprint=%(name)s",
        ]
        db, handle_ta = get_db_for_write(self.env, db)
        try:
            cursor = db.cursor()
            for q in queries:
                debug(self, "RENAME => Executing query: %s (%s)" % (q, params))
                safe_execute(cursor, q, params)
            if handle_ta:
                db.commit()
        except Exception, e:
            if handle_ta:
                db.rollback()
            raise TracError("An error occurred while renaming sprint: %s" % to_unicode(e))
Exemplo n.º 10
0
 def _fetch_tickets(self, db=None):
     """
     Fetch from the DB the ids, type, status of the tickets planned for this sprint,
     and returns a list of id, type, status.
     """
     params = {'table': BACKLOG_TICKET_TABLE, 'scope': self.name}
     t_sql = "SELECT DISTINCT id, type, status FROM ticket INNER JOIN ticket_custom ON "\
             "ticket.id=ticket_custom.ticket LEFT OUTER JOIN %(table)s ON " \
             "ticket.id=%(table)s.ticket_id WHERE (%(table)s.name='Sprint Backlog' " \
             "AND scope='%(scope)s') or (ticket_custom.name='sprint' AND " \
             "ticket_custom.value='%(scope)s')" % params
     
     tickets = [(0, '', '')]
     
     db, handle_ta = get_db_for_write(self.env, db)
     try:
         cursor = db.cursor()
         debug(self, "SQL (_fetch_tickets_stats): %s" % t_sql)
         cursor.execute(t_sql)
         tickets = cursor.fetchall()
     except:
         if handle_ta:
             db.rollback()
     return tickets
Exemplo n.º 11
0
 def db(self):
     return get_db_for_write(self.env)[0]