Пример #1
0
def report_patch_times(con, todays_patches):
    """Report how long it took to apply the given patches."""
    cur = con.cursor()

    todays_patches = [
        patch_tuple for patch_tuple, patch_file in todays_patches
    ]

    cur.execute("""
        SELECT
            major, minor, patch, start_time, end_time - start_time AS db_time
        FROM LaunchpadDatabaseRevision
        WHERE start_time > CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
            - CAST('1 month' AS interval)
        ORDER BY major, minor, patch
        """)
    for major, minor, patch, start_time, db_time in cur.fetchall():
        if (major, minor, patch) in todays_patches:
            continue
        db_time = total_seconds(db_time)
        start_time = start_time.strftime('%Y-%m-%d')
        log.info("%d-%02d-%d applied %s in %0.1f seconds" %
                 (major, minor, patch, start_time, db_time))

    for major, minor, patch in todays_patches:
        cur.execute(
            """
            SELECT end_time - start_time AS db_time
            FROM LaunchpadDatabaseRevision
            WHERE major = %s AND minor = %s AND patch = %s
            """, (major, minor, patch))
        db_time = cur.fetchone()[0]
        # Patches before 2208-01-1 don't have timing information.
        # Ignore this. We can remove this code the next time we
        # create a new database baseline, as all patches will have
        # timing information.
        if db_time is None:
            log.debug('%d-%d-%d no application time', major, minor, patch)
            continue
        log.info("%d-%02d-%d applied just now in %0.1f seconds", major, minor,
                 patch, total_seconds(db_time))
Пример #2
0
def report_patch_times(con, todays_patches):
    """Report how long it took to apply the given patches."""
    cur = con.cursor()

    todays_patches = [patch_tuple for patch_tuple, patch_file
        in todays_patches]

    cur.execute("""
        SELECT
            major, minor, patch, start_time, end_time - start_time AS db_time
        FROM LaunchpadDatabaseRevision
        WHERE start_time > CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
            - CAST('1 month' AS interval)
        ORDER BY major, minor, patch
        """)
    for major, minor, patch, start_time, db_time in cur.fetchall():
        if (major, minor, patch) in todays_patches:
            continue
        db_time = total_seconds(db_time)
        start_time = start_time.strftime('%Y-%m-%d')
        log.info(
            "%d-%02d-%d applied %s in %0.1f seconds"
            % (major, minor, patch, start_time, db_time))

    for major, minor, patch in todays_patches:
        cur.execute("""
            SELECT end_time - start_time AS db_time
            FROM LaunchpadDatabaseRevision
            WHERE major = %s AND minor = %s AND patch = %s
            """, (major, minor, patch))
        db_time = cur.fetchone()[0]
        # Patches before 2208-01-1 don't have timing information.
        # Ignore this. We can remove this code the next time we
        # create a new database baseline, as all patches will have
        # timing information.
        if db_time is None:
            log.debug('%d-%d-%d no application time', major, minor, patch)
            continue
        log.info(
            "%d-%02d-%d applied just now in %0.1f seconds",
            major, minor, patch, total_seconds(db_time))
Пример #3
0
 def record_activity(self, date_started, date_completed):
     """Record the successful completion of the script."""
     self.txn.begin()
     self.login(ANONYMOUS)
     getUtility(IScriptActivitySet).recordSuccess(
         name=self.name,
         date_started=date_started,
         date_completed=date_completed)
     self.txn.commit()
     # date_started is recorded *after* the lock is acquired and we've
     # initialized Zope components and the database.  Thus this time is
     # only for the script proper, rather than total execution time.
     seconds_taken = total_seconds(date_completed - date_started)
     self.logger.debug(
         "%s ran in %ss (excl. load & lock)" % (self.name, seconds_taken))
Пример #4
0
 def record_activity(self, date_started, date_completed):
     """Record the successful completion of the script."""
     self.txn.begin()
     self.login(ANONYMOUS)
     getUtility(IScriptActivitySet).recordSuccess(
         name=self.name,
         date_started=date_started,
         date_completed=date_completed)
     self.txn.commit()
     # date_started is recorded *after* the lock is acquired and we've
     # initialized Zope components and the database.  Thus this time is
     # only for the script proper, rather than total execution time.
     seconds_taken = total_seconds(date_completed - date_started)
     self.logger.debug("%s ran in %ss (excl. load & lock)" %
                       (self.name, seconds_taken))
Пример #5
0
 def test_total_seconds(self):
     # Numbers are arbitrary.
     duration = timedelta(days=3, seconds=45, microseconds=16)
     self.assertEqual(3 * 24 * 3600 + 45.000016, total_seconds(duration))
Пример #6
0
    def main(self):
        """Script entry point."""
        self.logger.info('Starting the PPA .htaccess generation')
        self.expireSubscriptions()
        affected_ppas = self.deactivateInvalidTokens(send_email=True)
        current_ppa_count = len(affected_ppas)
        self.logger.debug(
            '%s PPAs with deactivated tokens' % current_ppa_count)

        last_success = self.getTimeToSyncFrom()

        # In addition to the ppas that are affected by deactivated
        # tokens, we also want to include any ppas that have tokens
        # created since the last time we ran.
        num_tokens = 0
        for token in self.getNewTokens(since=last_success):
            affected_ppas.add(token.archive)
            num_tokens += 1

        new_ppa_count = len(affected_ppas)
        self.logger.debug(
            "%s new tokens since last run, %s PPAs affected"
            % (num_tokens, new_ppa_count - current_ppa_count))
        current_ppa_count = new_ppa_count

        affected_ppas.update(self.getNewPrivatePPAs(since=last_success))
        new_ppa_count = len(affected_ppas)
        self.logger.debug(
            "%s new private PPAs since last run"
            % (new_ppa_count - current_ppa_count))

        self.logger.debug('%s PPAs require updating' % new_ppa_count)
        for ppa in affected_ppas:
            # If this PPA is blacklisted, do not touch it's htaccess/pwd
            # files.
            blacklisted_ppa_names_for_owner = self.blacklist.get(
                ppa.owner.name, [])
            if ppa.name in blacklisted_ppa_names_for_owner:
                self.logger.info(
                    "Skipping htaccess updates for blacklisted PPA "
                    " '%s' owned by %s.",
                        ppa.name,
                        ppa.owner.displayname)
                continue
            elif ppa.status == ArchiveStatus.DELETED or ppa.enabled is False:
                self.logger.info(
                    "Skipping htaccess updates for deleted or disabled PPA "
                    " '%s' owned by %s.",
                        ppa.name,
                        ppa.owner.displayname)
                continue

            self.ensureHtaccess(ppa)
            htpasswd_write_start = datetime.now()
            temp_htpasswd = self.generateHtpasswd(ppa)
            self.replaceUpdatedHtpasswd(ppa, temp_htpasswd)
            htpasswd_write_duration = datetime.now() - htpasswd_write_start
            self.logger.debug(
                "Wrote htpasswd for '%s': %ss"
                % (ppa.name, total_seconds(htpasswd_write_duration)))

        if self.options.no_deactivation or self.options.dryrun:
            self.logger.info('Dry run, so not committing transaction.')
            self.txn.abort()
        else:
            self.logger.info('Committing transaction...')
            self.txn.commit()

        self.logger.info('Finished PPA .htaccess generation')
Пример #7
0
 def test_total_seconds(self):
     # Numbers are arbitrary.
     duration = timedelta(days=3, seconds=45, microseconds=16)
     self.assertEqual(3 * 24 * 3600 + 45.000016, total_seconds(duration))