~justas.sadzevicius/schooltool/versionator

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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python

import sys
from glob import glob
import packages
import visualize
from van.pydeb import bin_to_py

UBUNTU = 'ftp.litnet.lt'
DEBIAN = 'ftp.litnet.lt'
PPA = 'ppa.launchpad.net_schooltool-owners'

def get_apt_list(archive, distro, pocket='main'):
    variables = dict(archive=archive, distro=distro, pocket=pocket)
    pattern = '%(distro)s/var/lib/apt/lists/%(archive)s_*_dists_' \
              '%(distro)s_%(pocket)s_binary-*_Packages' % variables
    files = glob(pattern)
    assert len(files) == 1
    return files[0]

def load_package_lists(names=()):
    print >> sys.stderr, 'Loading repository lists...'
    lists = {}

    lists['Ubuntu-Lucid-universe'] = packages.Debs(
        get_apt_list(UBUNTU, 'lucid', 'universe'), names)
    lists['Ubuntu-Lucid-main'] = packages.Debs(
        get_apt_list(UBUNTU, 'lucid', 'main'), names)
    lists['Ubuntu-Maverick-universe'] = packages.Debs(
        get_apt_list(UBUNTU, 'maverick', 'universe'), names)
    lists['Ubuntu-Maverick-main'] = packages.Debs(
        get_apt_list(UBUNTU, 'maverick', 'main'), names)
    lists['Debian-Unstable'] = packages.Debs(
        get_apt_list(DEBIAN, 'unstable', 'main'), names)
    lists['PPA-Lucid'] = packages.Debs(
        get_apt_list(PPA, 'lucid'))
    lists['PPA-Maverick'] = packages.Debs(
        get_apt_list(PPA, 'maverick'))

    print >> sys.stderr, 'Done.'

    print >> sys.stderr, 'Merging lists...'

    lists['Ubuntu-Lucid'] = packages.Debs()
    # Order matters here
    lists['Ubuntu-Lucid'].update(lists['Ubuntu-Lucid-main'])
    lists['Ubuntu-Lucid'].update(lists['Ubuntu-Lucid-universe'])

    lists['Lucid'] = packages.Debs()
    # Order matters here
    lists['Lucid'].update(lists['PPA-Lucid'])
    lists['Lucid'].update(lists['Ubuntu-Lucid'])

    lists['Ubuntu-Maverick'] = packages.Debs()
    # Order matters here
    lists['Ubuntu-Maverick'].update(lists['Ubuntu-Maverick-main'])
    lists['Ubuntu-Maverick'].update(lists['Ubuntu-Maverick-universe'])

    lists['Maverick'] = packages.Debs()
    # Order matters here
    lists['Maverick'].update(lists['PPA-Maverick'])
    lists['Maverick'].update(lists['Ubuntu-Maverick'])

    print >> sys.stderr, 'Done.'
    return lists


def overview_eggs_against_debs(eggs, debs, sort_key=None,
                               exclude_prefixes=('NEW', 'SAME'),
                               ignore_versions=None):
    log = visualize.Legendator(
        legend={
            'REM': ('MISS',
                    'This package is missing from the repository.'),
            'NEW': ('???',
                    'Package not in versions.cfg.'),
            'SAME': ('OK', ''),
            'DOWN': ('UP',
                     'This package needs to be upgraded in the repository.'),
            'UP': ('WARN',
                   'We want a lower version than is in the repository.'),
        },
        exclude_prefixes=exclude_prefixes
        )

    eggs = packages.MappedPackages(eggs)
    debs = packages.MappedPackages(debs)
    visualize.print_diff(eggs, debs, log=log,
                         with_legend=True, by_prefix=True,
                         sort_key=sort_key,
                         ignore_versions=ignore_versions)


def diff_two_repos(source, target, sort_key=None, exclude_prefixes=('SAME',)):

    log = visualize.Legendator(
        legend={
            'REM': ('---',
                    'Package not in target repository.'),
            'NEW': ('+++',
                    'Package not in source repository.'),
            'SAME': ('===', 'Packages are same.'),
            'DOWN': ('>>>',
                     'Source is newer than target.'),
            'UP': ('<<<',
                   'Newer version already in target.'),
        },
        exclude_prefixes=exclude_prefixes
        )

    visualize.print_diff(source, target, log=log,
                         with_legend=True, by_prefix=True,
                         sort_key=sort_key)


ignore_versions = {
    'setuptools':  '0.6c11',
    'zope.authentication': '3.7.1',
    'zope.browser': '1.3',
    'zope.cachedescriptors': '3.5.1',
    'zope.configuration': '3.7.2',
    'zope.event': '3.5.0-1',
    'zope.exceptions': '3.6.1',
    'zope.i18n': '3.7.4',
    'zope.lifecycleevent': '3.6.1',
    'zope.pagetemplate': '3.5.2',
    'zope.tales': '3.5.1',
    'zc.buildout': '1.4.4',
}


if __name__ == '__main__':

    # THIS ENABLES 'ANIMATED' GAUGES THAT UGLIFY MY EMACS
    # but keeps my sanity on, when processing Debian sid / Ubuntu universe+main
    # visualize.CLUTTER_STDOUT = True

    names = open('package_list', 'r').read().splitlines()
    lists = load_package_lists(names)

    py_names = [bin_to_py(name) for name in names]
    eggs = packages.Eggs('versions.cfg', py_names)

    sort_key = packages.loose_namespace_sort_key(
        ['', 'zope.', 'zope.app', 'zc.', 'z3c', 'schooltool'])

    visualize.print_header(
        'Overview of versions.cfg against Maverick+PPA', level=2)
    overview_eggs_against_debs(eggs, lists['Maverick'], sort_key=sort_key,
                               exclude_prefixes=(), ignore_versions=ignore_versions)

    visualize.print_header(
        'Overview of versions.cfg against Debian Unstable', level=2)
    overview_eggs_against_debs(eggs, lists['Debian-Unstable'], sort_key=sort_key,
                               exclude_prefixes=('NEW', 'SAME', 'REM'))

    visualize.print_header('Diff Lucid+PPA vs. Maverick', level=2)
    diff_two_repos(lists['Lucid'], lists['Maverick'], sort_key=sort_key)

    visualize.print_header('Fixes in Maverick PPA for Maverick', level=2)
    diff_two_repos(lists['PPA-Maverick'], lists['Ubuntu-Maverick'], sort_key=sort_key,
                   exclude_prefixes=('NEW',))

    visualize.print_header('Diff Debian Unstable vs. Ubuntu Maverick', level=2)
    diff_two_repos(lists['Debian-Unstable'], lists['Ubuntu-Maverick'], sort_key=sort_key)