aboutsummaryrefslogtreecommitdiff
path: root/repos/ubuntu.py
blob: 7b51ffd1bf79b741f250ef13922bf74c78d40c32 (plain)
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
import gzip
from pathlib import Path
import re
from typing import Mapping

from .base import Repository, Version

__all__ = [
    'focal_main_amd64',
    'focal_restricted_amd64',
    'focal_universe_amd64',
    'focal_multiverse_amd64',

    'focal_updates_main_amd64',
    'focal_updates_restricted_amd64',
    'focal_updates_universe_amd64',
    'focal_updates_multiverse_amd64',

    'focal_backports_main_amd64',
    'focal_backports_restricted_amd64',
    'focal_backports_universe_amd64',
    'focal_backports_multiverse_amd64',

    'focal_security_main_amd64',
    'focal_security_restricted_amd64',
    'focal_security_universe_amd64',
    'focal_security_multiverse_amd64',

    'groovy_main_amd64',
    'groovy_restricted_amd64',
    'groovy_universe_amd64',
    'groovy_multiverse_amd64',

    'groovy_updates_main_amd64',
    'groovy_updates_restricted_amd64',
    'groovy_updates_universe_amd64',
    'groovy_updates_multiverse_amd64',

    'groovy_backports_main_amd64',
    'groovy_backports_restricted_amd64',
    'groovy_backports_universe_amd64',
    'groovy_backports_multiverse_amd64',

    'groovy_security_main_amd64',
    'groovy_security_restricted_amd64',
    'groovy_security_universe_amd64',
    'groovy_security_multiverse_amd64',
]

PACKAGE_REVISION_INFO = re.compile(r'(\+\w+)*-\d+$')

def parse_cached(cached: Path) -> Mapping[str, Version]:
    result = dict()
    with gzip.open(cached, mode='rt') as file:
        this_package = None
        this_version = None
        for line in file:
            line = line.strip()
            pieces = line.split(': ', 1)
            if len(pieces) != 2:
                continue
            line_type, line_data = pieces
            if line_type == 'Package':
                this_package = line_data
            elif line_type == 'Version':
                this_version = line_data

            if this_package is not None and this_version is not None:
                clean_version = PACKAGE_REVISION_INFO.sub('', this_version)
                result[this_package] = Version(this_version, clean_version)
                this_version = None
                this_package = None
    return result

def build_repo(name: str, dist: str, section: str, arch: str) -> Repository:
    url = f'http://archive.ubuntu.com/ubuntu/dists/{dist}/{section}/binary-{arch}/Packages.gz'
    section = f'{section}/{arch}'
    return Repository(
        family='Ubuntu',
        repo=name,
        section=section,
        index_url=url,
        parse=parse_cached,
    )

focal_main_amd64 = build_repo('20.04 Focal', 'focal', 'main', 'amd64')
focal_restricted_amd64 = build_repo('20.04 Focal', 'focal', 'restricted', 'amd64')
focal_universe_amd64 = build_repo('20.04 Focal', 'focal', 'universe', 'amd64')
focal_multiverse_amd64 = build_repo('20.04 Focal', 'focal', 'multiverse', 'amd64')

focal_updates_main_amd64 = build_repo('20.04 Focal Updates', 'focal-updates', 'main', 'amd64')
focal_updates_restricted_amd64 = build_repo('20.04 Focal Updates', 'focal-updates', 'restricted', 'amd64')
focal_updates_universe_amd64 = build_repo('20.04 Focal Updates', 'focal-updates', 'universe', 'amd64')
focal_updates_multiverse_amd64 = build_repo('20.04 Focal Updates', 'focal-updates', 'multiverse', 'amd64')

focal_backports_main_amd64 = build_repo('20.04 Focal Backports', 'focal-backports', 'main', 'amd64')
focal_backports_restricted_amd64 = build_repo('20.04 Focal Backports', 'focal-backports', 'restricted', 'amd64')
focal_backports_universe_amd64 = build_repo('20.04 Focal Backports', 'focal-backports', 'universe', 'amd64')
focal_backports_multiverse_amd64 = build_repo('20.04 Focal Backports', 'focal-backports', 'multiverse', 'amd64')

focal_security_main_amd64 = build_repo('20.04 Focal Security', 'focal-security', 'main', 'amd64')
focal_security_restricted_amd64 = build_repo('20.04 Focal Security', 'focal-security', 'restricted', 'amd64')
focal_security_universe_amd64 = build_repo('20.04 Focal Security', 'focal-security', 'universe', 'amd64')
focal_security_multiverse_amd64 = build_repo('20.04 Focal Security', 'focal-security', 'multiverse', 'amd64')

groovy_main_amd64 = build_repo('20.10 Groovy', 'groovy', 'main', 'amd64')
groovy_restricted_amd64 = build_repo('20.10 Groovy', 'groovy', 'restricted', 'amd64')
groovy_universe_amd64 = build_repo('20.10 Groovy', 'groovy', 'universe', 'amd64')
groovy_multiverse_amd64 = build_repo('20.10 Groovy', 'groovy', 'multiverse', 'amd64')

groovy_updates_main_amd64 = build_repo('20.10 Groovy Updates', 'groovy-updates', 'main', 'amd64')
groovy_updates_restricted_amd64 = build_repo('20.10 Groovy Updates', 'groovy-updates', 'restricted', 'amd64')
groovy_updates_universe_amd64 = build_repo('20.10 Groovy Updates', 'groovy-updates', 'universe', 'amd64')
groovy_updates_multiverse_amd64 = build_repo('20.10 Groovy Updates', 'groovy-updates', 'multiverse', 'amd64')

groovy_backports_main_amd64 = build_repo('20.10 Groovy Backports', 'groovy-backports', 'main', 'amd64')
groovy_backports_restricted_amd64 = build_repo('20.10 Groovy Backports', 'groovy-backports', 'restricted', 'amd64')
groovy_backports_universe_amd64 = build_repo('20.10 Groovy Backports', 'groovy-backports', 'universe', 'amd64')
groovy_backports_multiverse_amd64 = build_repo('20.10 Groovy Backports', 'groovy-backports', 'multiverse', 'amd64')

groovy_security_main_amd64 = build_repo('20.10 Groovy Security', 'groovy-security', 'main', 'amd64')
groovy_security_restricted_amd64 = build_repo('20.10 Groovy Security', 'groovy-security', 'restricted', 'amd64')
groovy_security_universe_amd64 = build_repo('20.10 Groovy Security', 'groovy-security', 'universe', 'amd64')
groovy_security_multiverse_amd64 = build_repo('20.10 Groovy Security', 'groovy-security', 'multiverse', 'amd64')