diff --git a/debian/bin/gencontrol.py b/debian/bin/gencontrol.py index e2ae17cc5..8e4a7c1b9 100755 --- a/debian/bin/gencontrol.py +++ b/debian/bin/gencontrol.py @@ -327,7 +327,7 @@ class Gencontrol(Base): name = new_package['Package'] if name in packages: package = packages.get(name) - package['Architecture'].append(arch) + package['Architecture'].add(arch) for field in 'Depends', 'Provides', 'Suggests', 'Recommends', 'Conflicts': if field in new_package: @@ -338,7 +338,7 @@ class Gencontrol(Base): package[field] = new_package[field] else: - new_package['Architecture'] = [arch] + new_package['Architecture'] = arch packages.append(new_package) def process_changelog(self): diff --git a/debian/lib/python/debian_linux/debian.py b/debian/lib/python/debian_linux/debian.py index 68e180648..cf9703ee7 100644 --- a/debian/lib/python/debian_linux/debian.py +++ b/debian/lib/python/debian_linux/debian.py @@ -1,4 +1,4 @@ -from collections import OrderedDict +import collections import itertools import os.path import re @@ -157,22 +157,38 @@ $ self.linux_revision_other = match.group('revision_other') and True -class PackageFieldList(list): +class PackageArchitecture(collections.MutableSet): + __slots__ = '_data' + def __init__(self, value=None): - self.extend(value) + self._data = set() + if value: + self.extend(value) + + def __contains__(self, value): + return self._data.__contains__(value) + + def __iter__(self): + return self._data.__iter__() + + def __len__(self): + return self._data.__len__() def __str__(self): - return ' '.join(self) + return ' '.join(sorted(self)) - def _extend(self, value): - if value is not None: - self.extend([j.strip() for j in re.split('\s', value.strip())]) + def add(self, value): + self._data.add(value) + + def discard(self, value): + self._data.discard(value) def extend(self, value): - if isinstance(value, str): - self._extend(value) + if isinstance(value, basestring): + for i in re.split('\s', value.strip()): + self.add(i) else: - super(PackageFieldList, self).extend(value) + raise RuntimeError class PackageDescription(object): @@ -363,10 +379,10 @@ class PackageRelationEntry(object): class Package(dict): - _fields = OrderedDict(( + _fields = collections.OrderedDict(( ('Package', str), ('Source', str), - ('Architecture', PackageFieldList), + ('Architecture', PackageArchitecture), ('Section', str), ('Priority', str), ('Maintainer', str), diff --git a/debian/lib/python/debian_linux/gencontrol.py b/debian/lib/python/debian_linux/gencontrol.py index 431702654..40ff8a391 100644 --- a/debian/lib/python/debian_linux/gencontrol.py +++ b/debian/lib/python/debian_linux/gencontrol.py @@ -278,7 +278,7 @@ class Gencontrol(object): def subst(match): return vars[match.group(1)] - return re.sub(r'@([-_a-z]+)@', subst, s) + return re.sub(r'@([-_a-z]+)@', subst, str(s)) def write(self, packages, makefile): self.write_control(packages.itervalues())