10637.3.1
by Guilherme Salgado
Use the default python version instead of a hard-coded version |
1 |
#!/usr/bin/python -S
|
7675.584.6
by William Grant
Add and test parse-ppa-apache-access-logs.py. |
2 |
#
|
3 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
|
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
5 |
||
6 |
"""Parse PPA apache logs to find out download counts for each file."""
|
|
7 |
||
8 |
__metaclass__ = type |
|
9 |
||
10 |
import _pythonpath |
|
11 |
||
12 |
import functools |
|
13 |
||
14 |
from zope.component import getUtility |
|
15 |
||
16 |
from canonical.config import config |
|
11882.2.2
by Jonathan Lange
Clear up a heck of a lot of imports from canonical.launchpad.interfaces. |
17 |
from lp.registry.interfaces.person import IPersonSet |
7675.584.6
by William Grant
Add and test parse-ppa-apache-access-logs.py. |
18 |
from lp.soyuz.interfaces.archive import NoSuchPPA |
19 |
from lp.soyuz.scripts.ppa_apache_log_parser import DBUSER, get_ppa_file_key |
|
20 |
from lp.services.apachelogparser.script import ParseApacheLogs |
|
21 |
||
22 |
||
23 |
class ParsePPAApacheLogs(ParseApacheLogs): |
|
24 |
"""An Apache log parser for PPA downloads."""
|
|
25 |
||
26 |
def setUpUtilities(self): |
|
27 |
"""See `ParseApacheLogs`."""
|
|
28 |
self.person_set = getUtility(IPersonSet) |
|
29 |
||
30 |
@property
|
|
31 |
def root(self): |
|
32 |
"""See `ParseApacheLogs`."""
|
|
33 |
return config.ppa_apache_log_parser.logs_root |
|
34 |
||
12163.1.4
by William Grant
Get the PPA log file glob from the config, and add a reasonable default. |
35 |
@property
|
36 |
def log_file_glob(self): |
|
37 |
return config.ppa_apache_log_parser.log_file_glob |
|
38 |
||
7675.584.6
by William Grant
Add and test parse-ppa-apache-access-logs.py. |
39 |
def getDownloadKey(self, path): |
40 |
"""See `ParseApacheLogs`."""
|
|
41 |
return get_ppa_file_key(path) |
|
42 |
||
43 |
def getDownloadCountUpdater(self, file_id): |
|
7675.584.13
by William Grant
Remove mistakenly placed hash. |
44 |
"""See `ParseApacheLogs`."""
|
7675.584.6
by William Grant
Add and test parse-ppa-apache-access-logs.py. |
45 |
person = self.person_set.getByName(file_id[0]) |
46 |
if person is None: |
|
47 |
return
|
|
48 |
try: |
|
49 |
archive = person.getPPAByName(file_id[1]) |
|
50 |
except NoSuchPPA: |
|
51 |
return None |
|
52 |
# file_id[2] (distro) isn't used yet, since getPPAByName
|
|
53 |
# hardcodes Ubuntu.
|
|
54 |
bpr = archive.getBinaryPackageReleaseByFileName(file_id[3]) |
|
55 |
if bpr is None: |
|
56 |
return None |
|
57 |
||
58 |
return functools.partial(archive.updatePackageDownloadCount, bpr) |
|
59 |
||
60 |
||
61 |
if __name__ == '__main__': |
|
62 |
script = ParsePPAApacheLogs('parse-ppa-apache-logs', DBUSER) |
|
63 |
script.lock_and_run() |