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 |
||
14612.2.8
by William Grant
cronscripts |
16 |
from lp.registry.interfaces.person import IPersonSet |
17 |
from lp.services.apachelogparser.script import ParseApacheLogs |
|
14605.1.1
by Curtis Hovey
Moved canonical.config to lp.services. |
18 |
from lp.services.config import config |
7675.584.6
by William Grant
Add and test parse-ppa-apache-access-logs.py. |
19 |
from lp.soyuz.interfaces.archive import NoSuchPPA |
14612.2.8
by William Grant
cronscripts |
20 |
from lp.soyuz.scripts.ppa_apache_log_parser import ( |
21 |
DBUSER, |
|
22 |
get_ppa_file_key, |
|
23 |
)
|
|
7675.584.6
by William Grant
Add and test parse-ppa-apache-access-logs.py. |
24 |
|
25 |
||
26 |
class ParsePPAApacheLogs(ParseApacheLogs): |
|
27 |
"""An Apache log parser for PPA downloads."""
|
|
28 |
||
29 |
def setUpUtilities(self): |
|
30 |
"""See `ParseApacheLogs`."""
|
|
31 |
self.person_set = getUtility(IPersonSet) |
|
32 |
||
33 |
@property
|
|
34 |
def root(self): |
|
35 |
"""See `ParseApacheLogs`."""
|
|
36 |
return config.ppa_apache_log_parser.logs_root |
|
37 |
||
12163.1.4
by William Grant
Get the PPA log file glob from the config, and add a reasonable default. |
38 |
@property
|
39 |
def log_file_glob(self): |
|
40 |
return config.ppa_apache_log_parser.log_file_glob |
|
41 |
||
7675.584.6
by William Grant
Add and test parse-ppa-apache-access-logs.py. |
42 |
def getDownloadKey(self, path): |
43 |
"""See `ParseApacheLogs`."""
|
|
44 |
return get_ppa_file_key(path) |
|
45 |
||
46 |
def getDownloadCountUpdater(self, file_id): |
|
7675.584.13
by William Grant
Remove mistakenly placed hash. |
47 |
"""See `ParseApacheLogs`."""
|
7675.584.6
by William Grant
Add and test parse-ppa-apache-access-logs.py. |
48 |
person = self.person_set.getByName(file_id[0]) |
49 |
if person is None: |
|
50 |
return
|
|
51 |
try: |
|
52 |
archive = person.getPPAByName(file_id[1]) |
|
53 |
except NoSuchPPA: |
|
54 |
return None |
|
55 |
# file_id[2] (distro) isn't used yet, since getPPAByName
|
|
56 |
# hardcodes Ubuntu.
|
|
57 |
bpr = archive.getBinaryPackageReleaseByFileName(file_id[3]) |
|
58 |
if bpr is None: |
|
59 |
return None |
|
60 |
||
61 |
return functools.partial(archive.updatePackageDownloadCount, bpr) |
|
62 |
||
63 |
||
64 |
if __name__ == '__main__': |
|
65 |
script = ParsePPAApacheLogs('parse-ppa-apache-logs', DBUSER) |
|
66 |
script.lock_and_run() |