412
by Martin Pitt
langpacksize: remove old code |
1 |
#!/usr/bin/python |
91
by Martin Pitt
langpacksize: rewrite using python-apt, which is much faster and also allows us to do easier handling of input support packages |
2 |
|
93
by Martin Pitt
langpacksize: print MB instead of bytes if "MB" is given as argument |
3 |
import apt, re, sys |
91
by Martin Pitt
langpacksize: rewrite using python-apt, which is much faster and also allows us to do easier handling of input support packages |
4 |
|
5 |
apt_cache = apt.Cache() |
|
1
by martin at piware
state for breezy final |
6 |
|
7 |
# most spoken languages of the world, prioritized |
|
95
by Martin Pitt
langpacksize: shuffle priority langs according to new input support policy |
8 |
priority_langs = [ 'en', 'es', 'xh', 'pt', 'de', 'fr', 'bn', 'hi', 'ar', 'ru', |
294
by Martin Pitt
langpacksize: add support for the zh split |
9 |
'zh-hans', 'ja'] |
1
by martin at piware
state for breezy final |
10 |
|
92
by Martin Pitt
langpacksize: add size of required input support packages |
11 |
extra_pkgs_counted = {'gnome': set(), 'kde': set(), '(gnome|kde)': set()} |
12 |
||
91
by Martin Pitt
langpacksize: rewrite using python-apt, which is much faster and also allows us to do easier handling of input support packages |
13 |
def language_size(lang, mode): |
1
by martin at piware
state for breezy final |
14 |
'''Return the cumulative size of all language packs related to the given
|
15 |
language code.'''
|
|
16 |
||
17 |
sum = 0 |
|
91
by Martin Pitt
langpacksize: rewrite using python-apt, which is much faster and also allows us to do easier handling of input support packages |
18 |
name_re = re.compile('^language-pack-(?:%s-)?%s(?:-|$)' % (mode, lang)) |
19 |
for p in apt_cache.keys(): |
|
20 |
if name_re.match(p): |
|
295
by Martin Pitt
langpacksize: Port to current apt API |
21 |
sum += apt_cache[p].candidate.size |
91
by Martin Pitt
langpacksize: rewrite using python-apt, which is much faster and also allows us to do easier handling of input support packages |
22 |
|
1
by martin at piware
state for breezy final |
23 |
if sum == 0: |
24 |
raise Exception('Invalid language: %s' % lang) |
|
92
by Martin Pitt
langpacksize: add size of required input support packages |
25 |
|
1
by martin at piware
state for breezy final |
26 |
return sum |
27 |
||
91
by Martin Pitt
langpacksize: rewrite using python-apt, which is much faster and also allows us to do easier handling of input support packages |
28 |
def all_languages(): |
29 |
'''Return list of all available languages.'''
|
|
1
by martin at piware
state for breezy final |
30 |
|
91
by Martin Pitt
langpacksize: rewrite using python-apt, which is much faster and also allows us to do easier handling of input support packages |
31 |
langs = [] |
32 |
for p in apt_cache.keys(): |
|
33 |
if p.startswith('language-pack-'): |
|
34 |
comps = p.split('-') |
|
294
by Martin Pitt
langpacksize: add support for the zh split |
35 |
if len(comps) == 3 and comps[2] != 'zh': |
91
by Martin Pitt
langpacksize: rewrite using python-apt, which is much faster and also allows us to do easier handling of input support packages |
36 |
langs.append(comps[2]) |
294
by Martin Pitt
langpacksize: add support for the zh split |
37 |
if len(comps) == 4 and comps[2] == 'zh' and comps[3] != 'base': |
38 |
langs.append('%s-%s' % (comps[2], comps[3])) |
|
91
by Martin Pitt
langpacksize: rewrite using python-apt, which is much faster and also allows us to do easier handling of input support packages |
39 |
return langs |
1
by martin at piware
state for breezy final |
40 |
|
41 |
def main(): |
|
42 |
# prioritize languages |
|
91
by Martin Pitt
langpacksize: rewrite using python-apt, which is much faster and also allows us to do easier handling of input support packages |
43 |
langs = all_languages() |
57
by martin at piware
langpacksize: avoid duplicates if using multiple Packages.gz |
44 |
langs.sort() |
1
by martin at piware
state for breezy final |
45 |
priority_langs.reverse() |
46 |
for pl in priority_langs: |
|
47 |
if pl in langs: |
|
48 |
langs.remove(pl) |
|
49 |
langs.insert(0, pl) |
|
50 |
||
51 |
gnomesum = 0 |
|
52 |
kdesum = 0 |
|
40
by martin at piware
langpacksize: also show gnome+kde combined for edubuntu |
53 |
gnomekdesum = 0 |
1
by martin at piware
state for breezy final |
54 |
for l in langs: |
91
by Martin Pitt
langpacksize: rewrite using python-apt, which is much faster and also allows us to do easier handling of input support packages |
55 |
gsize = language_size(l, 'gnome') |
56 |
ksize = language_size(l, 'kde') |
|
57 |
gksize = language_size(l, '(gnome|kde)') |
|
1
by martin at piware
state for breezy final |
58 |
gnomesum += gsize |
59 |
kdesum += ksize |
|
364
by Martin Pitt
convert tabs to spaces in Python source files |
60 |
gnomekdesum += gksize |
1
by martin at piware
state for breezy final |
61 |
|
93
by Martin Pitt
langpacksize: print MB instead of bytes if "MB" is given as argument |
62 |
if len(sys.argv) > 1 and sys.argv[1] == 'MB': |
363
by Martin Pitt
use logging module instead of bare print, and make remaining print statements Python 3 friendly |
63 |
print("%-5s G: %8.2f K: %8.2f G+K: %8.2f GSum: %8.2f KSum: %8.2f G+KSum: %8.2f" % \ |
93
by Martin Pitt
langpacksize: print MB instead of bytes if "MB" is given as argument |
64 |
(l, gsize/1048576., ksize/1048576., gksize/1048576., |
363
by Martin Pitt
use logging module instead of bare print, and make remaining print statements Python 3 friendly |
65 |
gnomesum/1048576., kdesum/1048576., gnomekdesum/1048576.)) |
93
by Martin Pitt
langpacksize: print MB instead of bytes if "MB" is given as argument |
66 |
else: |
363
by Martin Pitt
use logging module instead of bare print, and make remaining print statements Python 3 friendly |
67 |
print("%-5s G: %10i K: %10i G+K: %10i GSum: %10i KSum: %10i G+KSum: %10i" % \ |
68 |
(l, gsize, ksize, gksize, gnomesum, kdesum, gnomekdesum)) |
|
1
by martin at piware
state for breezy final |
69 |
|
70 |
if __name__ == '__main__': |
|
71 |
main() |