File: popcon.py

package info (click to toggle)
game-data-packager 63
  • links: PTS, VCS
  • area: contrib
  • in suites: buster
  • size: 15,920 kB
  • sloc: python: 10,537; sh: 515; makefile: 497
file content (82 lines) | stat: -rwxr-xr-x 2,560 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python3
# encoding=utf-8
#
# Copyright © 2016 Alexandre Detiste <alexandre@detiste.be>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# You can find the GPL license text on a Debian system under
# /usr/share/common-licenses/GPL-2.

import glob
import gzip
import sys

scope = set()
with open('out/bash_completion', 'r') as bash:
    # keep each even line
    while bash.readline():
        scope |= set(bash.readline().rstrip().split())

# old package names
scope.add('quake2-data')
scope.add('wolf3d-data-wl1')
scope.add('wolf3d-v14-data')
scope.add('rtcw-data')

# add this to compare against other Doom packages
scope.add('doom-wad-shareware')

scope.add('game-data-packager')

def process(scope, distro):
    result = dict()
    if len(sys.argv) == 2:
        popcon = '/var/cache/popcon/' + distro + '_' + sys.argv[1] + '.gz'
    else:
        popcon = sorted(glob.glob('/var/cache/popcon/' + distro + '_*.gz')).pop()

    with gzip.open(popcon, 'rb') as f:
        file_content = f.read().decode('latin1')
    for line in file_content.split('\n'):
        if not line or line[0] in ('#','-'):
            continue
        try:
            package, score = line.split()[1:3]
            score = int(score)
            if package in scope:
                #print("%30s %d" % (package, score))
                result[package] = score
        # theres is some random crap with 0 popcon in the Ubuntu file
        except ValueError:
            #print(distro,line)
            pass

    return result

debian = process(scope, 'debian')
ubuntu = process(scope, 'ubuntu')

games = []
for key in scope:
     games.append({
                   'name': key,
                   'debian': debian.get(key, 0),
                   'ubuntu': ubuntu.get(key, 0),
                  })

games = sorted(games, key=lambda k: (-k['debian'], k['name']))

print ('Package                                             Debian   Ubuntu')
print ('-------------------------------------------------------------------')
for package in games:
    print('%49s %8d %8d' % (package['name'],
                            package['debian'],
                            package['ubuntu']))