Пример #1
0
 def filter_stream(self, req, method, filename, stream, data):
     """
         Checks the project timeline and if there is no events with default params then user is
         directed to see latest events
         :param stream: Contains whole website
         :param data: Contains events, project information etc
         :return stream or if no events then redirect
     """
     if filename == 'timeline.html':
         if not data['events']:
             import datetime
             from multiproject.core.db import db_query
             project_name = data['chrome']['scripts'][0]['href'].split(
                 "/")[1]
             row = []
             with db_query(project_name) as cursor:
                 query = "SELECT MAX(t.time) FROM (SELECT time from revision UNION SELECT time from ticket UNION SELECT time FROM ticket_change UNION SELECT time FROM wiki)t;"
                 cursor.execute(query)
                 row = cursor.fetchall()
             unix_date = str(list(row)[0])
             real_unix_date = int(unix_date[1:11])
             new_date = (datetime.datetime.fromtimestamp(
                 real_unix_date).strftime('%m/%d/%y'))
             resend_url = "../" + project_name + "/timeline?from=" + new_date + "&daysback=30&authors=&wiki=on&discussion=on&ticket=on&files_events=on&files_downloads_events=on&changeset=on&milestone=on&update=Update&error=not_found"
             return req.redirect(resend_url)
     return stream
Пример #2
0
    def queryProjectObjectsDB(self, project_query, db_name):
        projects = []

        with db_query(db_name) as cursor:
            try:
                cursor.execute(project_query)
                for project in cursor:
                    projects.append(Projects.sqlToProject(project))
            except:
                conf.log.exception("Project query failed: {0}".format(project_query))
                raise
Пример #3
0
    def applied(self):
        """
        Called by migration manager to check if the migration is already run into the
        database. This performs two queries; checks if any of project wiki time stamp
        columns are of type BIGINT(20). Then checks if the time stamp in question is already
        big enough to be correct.

        :returns: True if the migration has already been run
        """

        identifier_rows = self._get_project_identifier_rows()

        was_applied = True
        with db_query() as cursor:
            for identifier, in identifier_rows:
                query = ("DESCRIBE `%(identifier)s`.`wiki` `time`;" % {
                    'identifier': MySQLdb.escape_string(identifier)
                })
                cursor.execute(query)
                describe_row = cursor.fetchone()
                # Returning columns:
                # +-------+------------+------+-----+---------+-------+
                # | Field | Type       | Null | Key | Default | Extra |
                # +-------+------------+------+-----+---------+-------+
                if describe_row and describe_row[1] != 'bigint(20)':
                    print(
                        "ERROR: Type of column `time` of `wiki` table is wrong in database `%s`: %s "
                        % (identifier, describe_row[1]))
                    was_applied = False

                query = """
                SELECT count(*)
                  FROM `%(identifier)s`.`wiki`
                 WHERE (name = 'WikiStart' OR name = 'Downloads') AND version = 1
                   AND time < 2147483648;
                """ % {
                    'identifier': MySQLdb.escape_string(identifier)
                }
                cursor.execute(query)
                # Above select always returns a row, unless an exception is thrown
                count = cursor.fetchone()[0]
                if count and count != 0:
                    was_applied = False
                    break

        return was_applied
Пример #4
0
 def searchMostDownloaded(self):
     project_query = """
             SELECT project_key FROM project_dim, event_fact, event_dim
             WHERE project_dim.project_sk = event_fact.project_sk
             AND event_fact.event_sk = event_dim.event_sk
             AND action_name='source_checkin'
             GROUP BY project_name
             ORDER BY COUNT(project_name) DESC;
         """
     project_ids = []
     with db_query('trac_analytical') as cursor:
             cursor.execute(project_query)
             project_ids = cursor.fetchall()
     projects = []
     if project_ids is not None:
         for project_id in project_ids:
             projects.append(Project._get_project(project_id))
     return projects
    def applied(self):
        """
        Called by migration manager to check if the migration is already run into the
        database. This performs two queries; checks if any of project wiki time stamp
        columns are of type BIGINT(20). Then checks if the time stamp in question is already
        big enough to be correct.

        :returns: True if the migration has already been run
        """

        identifier_rows = self._get_project_identifier_rows()

        was_applied = True
        with db_query() as cursor:
            for identifier, in identifier_rows:
                query = ("DESCRIBE `%(identifier)s`.`wiki` `time`;" %
                         { 'identifier' : MySQLdb.escape_string(identifier)})
                cursor.execute(query)
                describe_row = cursor.fetchone()
                # Returning columns:
                # +-------+------------+------+-----+---------+-------+
                # | Field | Type       | Null | Key | Default | Extra |
                # +-------+------------+------+-----+---------+-------+
                if describe_row and describe_row[1] != 'bigint(20)':
                    print ("ERROR: Type of column `time` of `wiki` table is wrong in database `%s`: %s "
                           % (identifier, describe_row[1]))
                    was_applied = False

                query =  """
                SELECT count(*)
                  FROM `%(identifier)s`.`wiki`
                 WHERE (name = 'WikiStart' OR name = 'Downloads') AND version = 1
                   AND time < 2147483648;
                """ % { 'identifier' : MySQLdb.escape_string(identifier)}
                cursor.execute(query)
                # Above select always returns a row, unless an exception is thrown
                count = cursor.fetchone()[0]
                if count and count != 0:
                    was_applied = False
                    break

        return was_applied
Пример #6
0
 def filter_stream(self, req, method, filename, stream, data):
     """
         Checks the project timeline and if there is no events with default params then user is
         directed to see latest events
         :param stream: Contains whole website
         :param data: Contains events, project information etc
         :return stream or if no events then redirect
     """
     if filename == 'timeline.html':
         if not data['events']:
             import datetime
             from multiproject.core.db import db_query
             project_name = data['chrome']['scripts'][0]['href'].split("/")[1]
             row = []
             with db_query(project_name) as cursor:
                 query = "SELECT MAX(t.time) FROM (SELECT time from revision UNION SELECT time from ticket UNION SELECT time FROM ticket_change UNION SELECT time FROM wiki)t;"
                 cursor.execute(query)
                 row = cursor.fetchall()
             unix_date = str(list(row)[0])
             real_unix_date = int(unix_date[1:11])
             new_date = (datetime.datetime.fromtimestamp(real_unix_date).strftime('%m/%d/%y'))
             resend_url = "../"+project_name+"/timeline?from="+new_date+"&daysback=30&authors=&wiki=on&discussion=on&ticket=on&files_events=on&files_downloads_events=on&changeset=on&milestone=on&update=Update&error=not_found"
             return req.redirect(resend_url)
     return stream