10637.3.1
by Guilherme Salgado
Use the default python version instead of a hard-coded version |
1 |
#!/usr/bin/python -S
|
8687.15.22
by Karl Fogel
Add the copyright header block to the remaining .py files. |
2 |
#
|
3 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
|
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
5 |
||
8486.12.1
by Celso Providelo
Fixing the 'fixable' scripts and adding a checker with the really-broken ones blacklisted. |
6 |
# pylint: disable-msg=W0403
|
9641.1.7
by Gary Poster
fix scripts to work |
7 |
import _pythonpath |
2200.1.22
by James Henstridge
driver scripts for finding and merging email clusters |
8 |
|
9 |
import sys |
|
10 |
import logging |
|
11 |
import optparse |
|
12 |
||
3127.1.3
by James Henstridge
Fix find-email-clusters.py to not use pyme constants. |
13 |
import gpgme |
2200.1.22
by James Henstridge
driver scripts for finding and merging email clusters |
14 |
|
15 |
from canonical.launchpad.scripts import ( |
|
16 |
execute_zcml_for_scripts, logger_options, logger as logger_from_options) |
|
8486.12.1
by Celso Providelo
Fixing the 'fixable' scripts and adding a checker with the really-broken ones blacklisted. |
17 |
from lp.registry.scripts.keyringtrustanalyser import ( |
18 |
addOtherKeyring, addTrustedKeyring, findEmailClusters) |
|
19 |
||
2200.1.22
by James Henstridge
driver scripts for finding and merging email clusters |
20 |
|
21 |
validity_map = { |
|
3127.1.3
by James Henstridge
Fix find-email-clusters.py to not use pyme constants. |
22 |
'UNDEFINED': gpgme.VALIDITY_UNDEFINED, |
23 |
'NEVER': gpgme.VALIDITY_NEVER, |
|
24 |
'MARGINAL': gpgme.VALIDITY_MARGINAL, |
|
25 |
'FULL': gpgme.VALIDITY_FULL, |
|
26 |
'ULTIMATE': gpgme.VALIDITY_ULTIMATE, |
|
2200.1.22
by James Henstridge
driver scripts for finding and merging email clusters |
27 |
}
|
28 |
||
8486.12.1
by Celso Providelo
Fixing the 'fixable' scripts and adding a checker with the really-broken ones blacklisted. |
29 |
|
2200.1.22
by James Henstridge
driver scripts for finding and merging email clusters |
30 |
def main(argv): |
31 |
parser = optparse.OptionParser( |
|
32 |
usage="usage: %prog [options] keyrings ...", |
|
33 |
description="This script inferrs clusters of " |
|
34 |
"email addresses belonging to a single user "
|
|
35 |
"from the user IDs attached to PGP keys.") |
|
36 |
parser.add_option('-o', '--output', metavar='FILE', action='store', |
|
37 |
help='Output clusters to given file', |
|
38 |
type='string', dest='output', default=None) |
|
39 |
parser.add_option('--trust', metavar='KEYRING', action='append', |
|
40 |
help='Trust the owners of keys on this keyring', |
|
41 |
type='string', dest='trust', default=[]) |
|
42 |
parser.add_option('--owner-trust', metavar='TRUST', action='store', |
|
43 |
help='What level of trust to assign to trusted keys', |
|
44 |
type='string', dest='owner_trust', default='ULTIMATE') |
|
45 |
parser.add_option('--min-valid', metavar='TRUST', action='store', |
|
46 |
help='Minimum trust necessary for a user ID to ' |
|
47 |
'be considered valid', |
|
48 |
type='string', dest='minvalid', default='MARGINAL') |
|
49 |
||
50 |
logger_options(parser, logging.WARNING) |
|
51 |
||
52 |
options, args = parser.parse_args(argv[1:]) |
|
53 |
||
54 |
# map validity options
|
|
55 |
if options.owner_trust.upper() not in validity_map: |
|
56 |
sys.stderr.write('%s: unknown owner trust value %s' |
|
57 |
% (argv[0], options.owner_trust)) |
|
58 |
return 1 |
|
59 |
options.owner_trust = validity_map[options.owner_trust.upper()] |
|
60 |
||
61 |
if options.minvalid.upper() not in validity_map: |
|
62 |
sys.stderr.write('%s: unknown min valid value %s' |
|
63 |
% (argv[0], options.minvalid)) |
|
64 |
return 1 |
|
65 |
options.minvalid = validity_map[options.minvalid.upper()] |
|
66 |
||
67 |
# get logger
|
|
68 |
logger = logger_from_options(options) |
|
69 |
||
70 |
if options.output is not None: |
|
71 |
logger.debug('openning %s', options.output) |
|
72 |
fp = open(options.output, 'w') |
|
73 |
else: |
|
74 |
fp = sys.stdout |
|
75 |
||
76 |
logger.info('Setting up utilities') |
|
77 |
execute_zcml_for_scripts() |
|
78 |
||
79 |
logger.info('Loading trusted keyrings') |
|
80 |
for keyring in options.trust: |
|
81 |
logger.info('Loading %s', keyring) |
|
82 |
addTrustedKeyring(keyring, options.owner_trust) |
|
83 |
||
84 |
logger.info('Loading other keyrings') |
|
85 |
for keyring in args: |
|
86 |
logger.info('Loading %s', keyring) |
|
87 |
addOtherKeyring(keyring) |
|
88 |
||
89 |
logger.info('Computing address clusters') |
|
90 |
for cluster in findEmailClusters(options.minvalid): |
|
91 |
for email in cluster: |
|
92 |
fp.write('%s\n' % email) |
|
93 |
fp.write('\n') |
|
94 |
||
95 |
logger.info('Done') |
|
96 |
||
97 |
return 0 |
|
98 |
||
8486.12.1
by Celso Providelo
Fixing the 'fixable' scripts and adding a checker with the really-broken ones blacklisted. |
99 |
|
2200.1.22
by James Henstridge
driver scripts for finding and merging email clusters |
100 |
if __name__ == '__main__': |
101 |
sys.exit(main(sys.argv)) |