1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#!/usr/bin/python2.4
# Copyright 2005 Canonical Ltd. All rights reserved.
# pylint: disable-msg=C0103,W0403
# This script updates the cached source package information in the system.
# We use this for fast source package searching (as opposed to joining
# through gazillions of publishing tables).
import _pythonpath
from zope.component import getUtility
from canonical.config import config
from canonical.launchpad.interfaces import IDistributionSet
from canonical.launchpad.scripts.base import LaunchpadCronScript
from canonical.lp import READ_COMMITTED_ISOLATION
class PackageCacheUpdater(LaunchpadCronScript):
def updateDistroSeriesCache(self, distroseries):
self.logger.info('%s %s starting' % (
distroseries.distribution.name, distroseries.name))
distroseries.updatePackageCount()
self.txn.commit()
distroseries.removeOldCacheItems(log=self.logger)
self.txn.commit()
distroseries.updateCompletePackageCache(
ztm=self.txn, log=self.logger)
self.txn.commit()
for arch in distroseries.architectures:
arch.updatePackageCount()
self.txn.commit()
def main(self):
self.txn.set_isolation_level(READ_COMMITTED_ISOLATION)
self.logger.debug('Starting the sp cache update')
# Do the cache update
distroset = getUtility(IDistributionSet)
for distro in distroset:
for distroseries in distro.serieses:
self.updateDistroSeriesCache(distroseries)
distro.removeOldCacheItems(log=self.logger)
self.txn.commit()
distro.updateCompleteSourcePackageCache(ztm=self.txn,
log=self.logger)
self.txn.commit()
self.logger.info('%s done' % distro.name)
self.logger.debug('Finished the sp cache update')
if __name__ == '__main__':
script = PackageCacheUpdater('spcache', dbuser=config.statistician.dbuser)
script.lock_and_run()
|