3
# This script calculates statistics of the percentage of translation per
4
# language for all languages in Ubuntu by calling all involved functions in the
10
from optparse import OptionParser
11
sys.path.append(os.path.join(os.getcwd(), 'lib/python2.6/site-packages'))
13
import ul10n_iso_pots_get
14
import ul10n_stats_calc
18
STATS_URL = 'http://people.canonical.com/~danilo/ubuntu'
21
"""Parses the command line and config file options"""
23
settings = utils.get_settings()
25
USAGE = "%prog [OPTIONS]"
27
DESCRIPTION = """Lists all translation templates and source packages in the LiveCD for the
28
given distro version."""
30
parser = OptionParser(usage = USAGE, description = DESCRIPTION)
32
parser.add_option("-d",
36
help="File to read domains from and on which stats are based. Requires -c argument.")
38
parser.add_option("-c",
43
help="Turn on custom (non-Ubuntu) mode")
45
parser.add_option("-f",
50
help="Disables using conf file blacklist.")
52
parser.add_option("-p",
57
help="Disables using priorities to generate blacklist.")
59
parser.add_option("-s",
60
"--source-package-stats",
62
default='{0}/{1}-package-stats.log.gz'.format(DATA_DIR, settings['distro_codename']),
63
help="specify the file containing the source package statistics")
65
parser.add_option("-b",
66
"--template-blacklist",
68
default='config/blacklist.conf',
69
help="specify the file containing the templates to blacklist during the calculation of statistics")
71
(options, args) = parser.parse_args()
73
return options, settings
76
def get_raw_data(distro_codename):
78
print >>sys.stderr, "Fetching data..."
79
for stats_file in ('potemplate', 'package'):
80
url = '{0}/{1}-{2}-stats.log.gz'.format(STATS_URL, distro_codename, stats_file)
81
path = os.path.join(DATA_DIR, os.path.basename(url))
82
urllib.urlretrieve(url, path)
85
def get_working_templates(options, settings):
87
distro_codename = settings['distro_codename']
88
distro_id = settings['distro_id']
89
TEMPLATES_FILE = '{0}/{1}-potemplate-stats.log.gz'.format(DATA_DIR, distro_codename)
91
# if normal ubuntu mode, get src pkg list form seeds, else from custom
92
if not options.custom:
93
# Get the source packages from seeds
94
distro_src_pkgs = ul10n_iso_pots_get.get_src_pkgs_from_seeds(distro_id,
97
# create list ('valid') of lines from lp_stats_pots file that only includes
98
# src pkgs that are: in the seed, enabled, or in extra (for live cd)
99
valid = ul10n_iso_pots_get.apply_valid_pots_filter(TEMPLATES_FILE, distro_src_pkgs)
102
# print >> sys.stderr, line.split('|')[0].strip()
104
working_pots = ul10n_iso_pots_get.apply_blacklist_filter(options, settings, valid)
109
domain_src, domain_linenum, domain_template, lines = ul10n_iso_pots_get.get_dictionaries(TEMPLATES_FILE)
110
if options.domains_file:
111
if not os.path.exists(options.domains_file):
112
print >> sys.stderr, "Error: domains_file not found. Stopping."
114
f = open(options.domains_file, 'r')
115
domains = f.read().split('\n')
119
domains = ul10n_custom.get_domains()
120
for domain in domains: print >> sys.stderr, domain
123
for domain in domains:
124
if domain in domain_src.keys():
125
line = lines[domain_linenum[domain]].rstrip()
130
# Print lines to stdout for redirection to file and post processing
131
#for item in valid: print item
136
# Get the command line options and settings from the config file
137
options, settings = options_parse()
139
# Fetch the raw data export files to be used as the source for the
141
get_raw_data(settings['distro_codename'])
143
# Compile a list of working templates to be considered for the calculation.
144
# Apply any blacklisting if necessary.
145
working_pots = get_working_templates(options, settings)
147
# Calculate the unified, per language translation statistics from the
148
# working templates set and output them in a report
149
ul10n_stats_calc.calculate_stats(options, settings, working_pots)
151
if __name__ == "__main__":