Move write_controlfiles to britney_util

Signed-off-by: Niels Thykier <niels@thykier.net>
master
Niels Thykier 10 years ago
parent b429d4871e
commit 5ddd9ebc36

@ -216,7 +216,7 @@ from britney_util import (old_libraries_format, same_source, undo_changes,
register_reverses, compute_reverse_tree,
read_nuninst, write_nuninst, write_heidi,
eval_uninst, newly_uninst, make_migrationitem,
write_excuses, write_heidi_delta, write_sources)
write_excuses, write_heidi_delta, write_controlfiles)
from consts import (VERSION, SECTION, BINARIES, MAINTAINER, FAKESRC,
SOURCE, SOURCEVER, ARCHITECTURE, DEPENDS, CONFLICTS,
PROVIDES, RDEPENDS, RCONFLICTS, MULTIARCH, ESSENTIAL)
@ -868,52 +868,6 @@ class Britney(object):
return hints
def write_controlfiles(self, basedir, suite):
"""Write the control files
This method writes the control files for the binary packages of all
the architectures and for the source packages.
"""
sources = self.sources[suite]
self.__log("Writing new %s control files to %s" % (suite, basedir))
for arch in self.options.architectures:
filename = os.path.join(basedir, 'Packages_%s' % arch)
f = open(filename, 'w')
binaries = self.binaries[suite][arch][0]
for pkg in binaries:
output = "Package: %s\n" % pkg
for key, k in ((SECTION, 'Section'), (ARCHITECTURE, 'Architecture'), (MULTIARCH, 'Multi-Arch'), (SOURCE, 'Source'), (VERSION, 'Version'),
(DEPENDS, 'Depends'), (PROVIDES, 'Provides'), (CONFLICTS, 'Conflicts'), (ESSENTIAL, 'Essential')):
if not binaries[pkg][key]: continue
if key == SOURCE:
if binaries[pkg][SOURCE] == pkg:
if binaries[pkg][SOURCEVER] != binaries[pkg][VERSION]:
source = binaries[pkg][SOURCE] + " (" + binaries[pkg][SOURCEVER] + ")"
else: continue
else:
if binaries[pkg][SOURCEVER] != binaries[pkg][VERSION]:
source = binaries[pkg][SOURCE] + " (" + binaries[pkg][SOURCEVER] + ")"
else:
source = binaries[pkg][SOURCE]
output += (k + ": " + source + "\n")
if sources[binaries[pkg][SOURCE]][MAINTAINER]:
output += ("Maintainer: " + sources[binaries[pkg][SOURCE]][MAINTAINER] + "\n")
elif key == PROVIDES:
if len(binaries[pkg][key]) > 0:
output += (k + ": " + ", ".join(binaries[pkg][key]) + "\n")
elif key == ESSENTIAL:
if binaries[pkg][key]:
output += (k + ": " + " yes\n")
else:
output += (k + ": " + binaries[pkg][key] + "\n")
f.write(output + "\n")
f.close()
filename = os.path.join(basedir, 'Sources')
write_sources(sources, filename)
# Utility methods for package analysis
# ------------------------------------
@ -2388,7 +2342,10 @@ class Britney(object):
if not self.options.dry_run:
# re-write control files
if self.options.control_files:
self.write_controlfiles(self.options.testing, 'testing')
self.__log("Writing new testing control files to %s" %
self.options.testing)
write_controlfiles(self.sources, self.binaries,
'testing', self.options.testing)
# write dates
try:

@ -25,6 +25,7 @@ import apt_pkg
from functools import partial
from datetime import datetime
from itertools import chain, ifilter, ifilterfalse, izip, repeat
import os
import re
import time
import yaml
@ -33,7 +34,8 @@ from migrationitem import MigrationItem, UnversionnedMigrationItem
from consts import (VERSION, BINARIES, PROVIDES, DEPENDS, CONFLICTS,
RDEPENDS, RCONFLICTS, ARCHITECTURE, SECTION,
SOURCE, SOURCEVER, MAINTAINER)
SOURCE, SOURCEVER, MAINTAINER, MULTIARCH,
ESSENTIAL)
binnmu_re = re.compile(r'^(.*)\+b\d+$')
@ -493,3 +495,58 @@ def write_sources(sources_s, filename):
output += "\n".join(k + ": "+ src_data[key]
for key, k in key_pairs if src_data[key])
f.write(output + "\n\n")
def write_controlfiles(sources, packages, suite, basedir):
"""Write the control files
This method writes the control files for the binary packages of all
the architectures and for the source packages. Note that Britney
discards a lot of fields that she does not care about. Therefore,
these files may omit a lot of regular fields.
"""
sources_s = sources[suite]
packages_s = packages[suite]
key_pairs = ((SECTION, 'Section'), (ARCHITECTURE, 'Architecture'),
(MULTIARCH, 'Multi-Arch'), (SOURCE, 'Source'),
(VERSION, 'Version'), (DEPENDS, 'Depends'),
(PROVIDES, 'Provides'), (CONFLICTS, 'Conflicts'),
(ESSENTIAL, 'Essential'))
for arch in packages_s:
filename = os.path.join(basedir, 'Packages_%s' % arch)
binaries = packages_s[arch][0]
with open(filename, 'w') as f:
for pkg in binaries:
output = "Package: %s\n" % pkg
bin_data = binaries[pkg]
for key, k in key_pairs:
if not bin_data[key]: continue
if key == SOURCE:
src = bin_data[SOURCE]
if sources_s[src][MAINTAINER]:
output += ("Maintainer: " + sources_s[src][MAINTAINER] + "\n")
if bin_data[SOURCE] == pkg:
if bin_data[SOURCEVER] != bin_data[VERSION]:
source = src + " (" + bin_data[SOURCEVER] + ")"
else: continue
else:
if bin_data[SOURCEVER] != bin_data[VERSION]:
source = src + " (" + bin_data[SOURCEVER] + ")"
else:
source = src
output += (k + ": " + source + "\n")
elif key == PROVIDES:
if bin_data[key]:
output += (k + ": " + ", ".join(bin_data[key]) + "\n")
elif key == ESSENTIAL:
if bin_data[key]:
output += (k + ": " + " yes\n")
else:
output += (k + ": " + bin_data[key] + "\n")
f.write(output + "\n")
write_sources(sources_s, os.path.join(basedir, 'Sources'))

Loading…
Cancel
Save