/usr/lib/python3/dist-packages/simple_cdd/tools/mirror_reprepro.py is in python3-simple-cdd 0.6.5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | from simple_cdd.exceptions import Fail
from simple_cdd.utils import run_command, list_debs, shell_which
from .base import Tool, ToolShell
from debian import deb822
import shutil
import subprocess
import os
import logging
log = logging.getLogger()
@Tool.register
class ToolMirrorReprepro(ToolShell):
type = "mirror"
name = "reprepro"
def run(self):
"""
Export variables and run the script
"""
self.check_pre()
codename = self.env.get("CODENAME")
di_codename = self.env.get("DI_CODENAME")
# Distributions in our local mirror
distributions_used = [codename]
distributions = {
codename: {
"Architectures": "{ARCHES}",
"Components": "{mirror_components}",
"UDebComponents": "main",
"Description": "mirror for {CODENAME}",
"Suite": "{SUITE}",
}
}
if codename != di_codename:
distributions_used.append(di_codename)
distributions["di_codename"] = {
"Architectures": "{ARCHES}",
"Components": "{mirror_components}",
"UDebComponents": "main",
"Description": "mirror for {CODENAME}",
"Update": "default-udebs",
"Suite": "{SUITE}",
}
# Update methods for our distributions
updates = {
"default": {
"Suite": "*",
"Architectures": "{ARCHES}",
"UDebComponents": "",
"Method": "{debian_mirror}",
"FilterList": "deinstall package-list",
"VerifyRelease": "{verify_release_keys}",
},
"default-base": {
"Suite": "*",
"Architectures": "{ARCHES}",
"UDebComponents": "",
"Method": "{debian_mirror}",
"FilterFormula": "priority (== required) | priority (== important) | priority (== standard)",
"VerifyRelease": "{verify_release_keys}",
},
"default-udebs": {
"Suite": "*",
"Architectures": "{ARCHES}",
"Components": "",
"Method": "{debian_mirror}",
"VerifyRelease": "{verify_release_keys}",
},
"default-security": {
"Suite": "*/updates",
"Architectures": "{ARCHES}",
"UDebComponents": "",
"Method": "{security_mirror}",
"FilterList": "deinstall package-list",
"VerifyRelease": "{verify_release_keys}",
},
"default-base-security": {
"Suite": "*/updates",
"Architectures": "{ARCHES}",
"UDebComponents": "",
"Method": "{security_mirror}",
"FilterFormula": "priority (== required) | priority (== important) | priority (== standard)",
"VerifyRelease": "{verify_release_keys}",
},
"default-updates": {
"Suite": "{CODENAME}-updates",
"Architectures": "{ARCHES}",
"UDebComponents": "main",
"Method": "{updates_mirror}",
"FilterList": "deinstall package-list",
"VerifyRelease": "{verify_release_keys}",
},
"default-base-updates": {
"Suite": "{CODENAME}-updates",
"Architectures": "{ARCHES}",
"UDebComponents": "main",
"Method": "{updates_mirror}",
"FilterFormula": "priority (== required) | priority (== important) | priority (== standard)",
"VerifyRelease": "{verify_release_keys}",
},
"default-extra": {
"Suite": "*",
"Architectures": "{ARCHES}",
"Components": "{mirror_components_extra}",
"UDebComponents": "{mirror_udebcomponents_extra}",
"Method": "{debian_mirror_extra}",
"FilterList": "deinstall package-list",
"VerifyRelease": "{verify_release_keys}",
"ListShellHook": "{debian_mirror_extra_list_shell_hook}",
},
"default-proposed-updates": {
"Suite": "{CODENAME}-proposed-updates",
"Architectures": "{ARCHES}",
"UDebComponents": "main",
"Method": "{debian_mirror}",
"FilterList": "deinstall package-list",
"VerifyRelease": "{verify_release_keys}",
},
"default-base-proposed-updates": {
"Suite": "{CODENAME}-proposed-updates",
"Architectures": "{ARCHES}",
"UDebComponents": "main",
"Method": "{debian_mirror}",
"FilterFormula": "priority (== required) | priority (== important) | priority (== standard)",
"VerifyRelease": "{verify_release_keys}",
},
"default-profiles-udeb": {
"Suite": "{profiles_udeb_dist}",
"Architectures": "{ARCHES}",
"Components": "",
"FilterFormula": "package (== simple-cdd-profiles)",
"Method": "{debian_mirror}",
"VerifyRelease": "{verify_release_keys}",
},
"default-extra-udebs": {
"Suite": "{extra_udeb_dist}",
"Architectures": "{ARCHES}",
"Components": "",
"Method": "{debian_mirror}",
"VerifyRelease": "{verify_release_keys}",
},
"default-backports": {
"Suite": "{CODENAME}-backports",
"Architectures": "{ARCHES}",
"UDebComponents": "main",
"Method": "{backports_mirror}",
"FilterList": "deinstall backports-packages",
"VerifyRelease": "{verify_release_keys}",
},
"default-backports-filter-formula": {
"Suite": "{CODENAME}-backports",
"Architectures": "{ARCHES}",
"UDebComponents": "main",
"Method": "{backports_mirror}",
"FilterFormula": "{backports_filter_formula}",
"VerifyRelease": "{verify_release_keys}",
},
}
updates_used = ["default", "default-base", "default-udebs"]
if self.env.get("clean_mirror"):
# invoke reprepro's "magic delete" rule.
updates_used.append("-")
if self.env.get("security_mirror"):
updates_used.append("default-base-security")
updates_used.append("default-security")
if self.env.get("debian_mirror_extra"):
updates_used.append("default-extra")
if self.env.get("debian_mirror_extra_dist"):
updates["default-extra"]["Suite"] = "{debian_mirror_extra_dist}"
if self.env.get("proposed_updates"):
updates_used.append("default-base-proposed-updates")
updates_used.append("default-proposed-updates")
if self.env.get("updates_mirror"):
updates_used.append("default-base-updates")
updates_used.append("default-updates")
if self.env.get("profiles_udeb_dist"):
updates_used.append("default-profiles-udeb")
if self.env.get("extra_udeb_dist"):
updates_used.append("default-extra-udebs")
filter = []
for p in self.env.get("extra_udeb_dist_packages"):
filter.append("package (== {})".format(p))
updates["default-extra-udebs"]["FilterFormula"] = " | ".join(filter)
if self.env.get("backports"):
updates_used.append("default-backports")
if self.env.get("backports_filter_formula"):
updates_used.append("default-backports-filter-formula")
if self.env.get("udebs_filter_formula"):
updates["default-udebs"]["FilterFormula"] = "{udebs_filter_formula}"
distributions[codename]["Update"] = " ".join(updates_used)
confdir = os.path.join(self.env.get("MIRROR"), "conf")
os.makedirs(confdir, exist_ok=True)
def print_records(confname, name_field, field_order, records_used, records):
verify_release_keys = "|".join(self.env.get("verify_release_keys"))
with open(os.path.join(confdir, confname), "wt") as fd:
for name in records_used:
rec = records[name]
print("{}: {}".format(name_field, name), file=fd)
for field in field_order:
val = rec.get(field, None)
if val is None: continue
print("{}: {}".format(field, self.env.format(val, verify_release_keys=verify_release_keys)), file=fd)
print(file=fd)
# Generate the conf/distributions file
field_order = ["Architectures", "Components", "UDebComponents", "Description", "Update", "Suite"]
print_records("distributions", "Codename", field_order, distributions_used, distributions)
# Generate the conf/updates file
field_order = ["Suite", "Architectures", "Components", "UDebComponents", "Method", "FilterList", "FilterFormula", "VerifyRelease", "ListShellHook"]
print_records("updates", "Name", field_order, updates_used, updates)
# Generate the conf/backport-packages file
if self.env.get("backports"):
with open(os.path.join(confdir, "backports-packages"), "wt") as fd:
packages = set(self.env.get("backports_packages"))
for package in sorted(packages):
print(package, "install", file=fd)
# Recreate an empty package-list file
pkglist_file = os.path.join(confdir, "package-list")
with open(pkglist_file, "wt") as fd:
pass
# Build the environment for running reprepro
reprepro_env = {}
for name, val, changed in self.env.export_iter():
reprepro_env[name] = str(val)
# include local packages into the mirror
for src in self.env.get("local_packages"):
for f in list_debs(src):
if f.endswith(".deb"):
cmd = ["reprepro"]
cmd.extend(self.env.get("reprepro_opts"))
cmd.extend(["--ignore=wrongdistribution", "includedeb", codename, f])
retval = run_command("reprepro: including local deb file", cmd, env=reprepro_env)
if retval != 0:
raise Fail("reprepro failed with exit code: %d", retval)
elif f.endswith(".udeb"):
cmd = ["reprepro"]
cmd.extend(self.env.get("reprepro_opts"))
cmd.extend(["--ignore=wrongdistribution", "includeudeb", codename, f])
retval = run_command("reprepro: including local deb file", cmd, env=reprepro_env)
if retval != 0:
raise Fail("reprepro failed with exit code: %d", retval)
if codename != di_codename:
cmd = ["reprepro"]
cmd.extend(self.env.get("reprepro_opts"))
cmd.extend(["--ignore=wrongdistribution", "includeudeb", di_codename, f])
retval = run_command("reprepro: including local deb file", cmd, env=reprepro_env)
else:
log.warn("unknown package type: %s", f)
# Update package lists
cmd = ["reprepro"]
cmd.extend(self.env.get("reprepro_opts"))
cmd.extend(["--noskipold", "update"])
retval = run_command("reprepro: updating package lists", cmd, env=reprepro_env)
if retval != 0:
raise Fail("reprepro failed with exit code: %d", retval)
# TODO: we can compute here via dose-debcheck if $all_packages are all
# installable, and warn otherwise or fail before we start building a
# mirror
self.run_script()
for f in self.env.get("exclude_files"):
with open(f, "rt") as infd:
for line in infd:
pkg = line.strip()
if not pkg or pkg.startswith("#"): continue
# Remove files listed in exclude_files
cmd = ["reprepro"]
cmd.extend(self.env.get("reprepro_opts"))
cmd.extend(["--noskipold", "remove", self.env.get("CODENAME"), pkg])
retval = run_command("reprepro: remove console-tools-freebsd", cmd, env=reprepro_env)
if retval != 0:
raise Fail("reprepro failed with exit code: %d", retval)
self.check_post(retval)
def check_post(self, retval):
debcheck = shell_which("dose-debcheck")
if debcheck is None:
log.info("dose-debcheck not found: skipping mirror checks")
return
for a in self.env.get("ARCHES"):
mirror_components = self.env.get("mirror_components")
for component in mirror_components:
bg_pkgfile = [
self.env.format(
"{MIRROR}/dists/{CODENAME}/{component}/binary-{a}/Packages",
component=i, a=a)
for i in mirror_components if i != component
]
bg_command = []
for file in bg_pkgfile:
bg_command.append('--bg')
bg_command.append(file)
command = [debcheck, "--failures", "--explain"]
command.extend(bg_command)
pkgfile = self.env.format(
"{MIRROR}/dists/{CODENAME}/{component}/binary-{a}/Packages",
component=component, a=a)
if os.stat(pkgfile).st_size == 0: continue
log.info("Checking package file %s using %s", pkgfile, debcheck)
command.append(pkgfile)
proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
retval = proc.wait()
if retval != 0:
log.warn("Found uninstallable packages in %s:", pkgfile)
for line in stdout.decode("utf-8").split("\n"):
log.warn(" %s", line)
|