diff options
author | Bastian Blank <waldi@debian.org> | 2007-06-17 10:51:18 +0000 |
---|---|---|
committer | Bastian Blank <waldi@debian.org> | 2007-06-17 10:51:18 +0000 |
commit | 0d6e4097bc22c7d0804296334aa638280ecabb52 (patch) | |
tree | 69df82306d9ac29adca46dcf52ac235551098ff0 /debian/lib/python/debian_linux/debian.py | |
parent | bb11d129398e6dea016b3000302d52b46158b902 (diff) | |
download | kernel_replicant_linux-0d6e4097bc22c7d0804296334aa638280ecabb52.tar.gz kernel_replicant_linux-0d6e4097bc22c7d0804296334aa638280ecabb52.tar.bz2 kernel_replicant_linux-0d6e4097bc22c7d0804296334aa638280ecabb52.zip |
debian/bin/gencontrol.py, debian/lib/python/debian_linux: Cleanup.
svn path=/dists/trunk/linux-2.6/; revision=8982
Diffstat (limited to 'debian/lib/python/debian_linux/debian.py')
-rw-r--r-- | debian/lib/python/debian_linux/debian.py | 171 |
1 files changed, 75 insertions, 96 deletions
diff --git a/debian/lib/python/debian_linux/debian.py b/debian/lib/python/debian_linux/debian.py index cd2c35d57e9e..296bdbeec743 100644 --- a/debian/lib/python/debian_linux/debian.py +++ b/debian/lib/python/debian_linux/debian.py @@ -162,90 +162,7 @@ class PackageDescription(object): if str: self.long.extend(str.split("\n.\n")) -class PackageRelation(object): - __slots__ = "name", "operator", "version", "arches" - - _re = re.compile(r'^(\S+)(?: \((<<|<=|=|!=|>=|>>)\s*([^)]+)\))?(?: \[([^]]+)\])?$') - - class _operator(object): - OP_LT = 1 - OP_LE = 2 - OP_EQ = 3 - OP_NE = 4 - OP_GE = 5 - OP_GT = 6 - - operators = { - '<<': OP_LT, - '<=': OP_LE, - '=': OP_EQ, - '!=': OP_NE, - '>=': OP_GE, - '>>': OP_GT, - } - operators_neg = { - OP_LT: OP_GE, - OP_LE: OP_GT, - OP_EQ: OP_NE, - OP_NE: OP_EQ, - OP_GE: OP_LT, - OP_GT: OP_LE, - } - operators_text = dict([(b, a) for a, b in operators.iteritems()]) - - __slots__ = '_op', - - def __init__(self, value): - self._op = self.operators[value] - - def __neg__(self): - return self.__class__(self.operators_text[self.operators_neg[self._op]]) - - def __str__(self): - return self.operators_text[self._op] - - def __init__(self, value = None): - if value is not None: - self.parse(value) - else: - self.name = None - self.operator = None - self.version = None - self.arches = [] - - def __str__(self): - ret = [self.name] - if self.operator is not None and self.version is not None: - ret.extend([' (', str(self.operator), ' ', self.version, ')']) - if self.arches: - ret.extend([' [', ' '.join(self.arches), ']']) - return ''.join(ret) - - def config(self, entry): - if self.version is not None or self.arches: - return - value = entry.get(self.name, None) - if value is None: - return - self.parse(value) - - def parse(self, value): - match = self._re.match(value) - if match is None: - raise RuntimeError, "Can't parse dependency %s" % value - match = match.groups() - self.name = match[0] - if match[1] is not None: - self.operator = self._operator(match[1]) - else: - self.operator = None - self.version = match[2] - if match[3] is not None: - self.arches = re.split('\s+', match[3]) - else: - self.arches = [] - -class PackageRelationList(list): +class PackageRelation(list): def __init__(self, value = None): if value is not None: self.extend(value) @@ -268,7 +185,7 @@ class PackageRelationList(list): if j: j._updateArches(value) else: - super(PackageRelationList, self).append(value) + super(PackageRelation, self).append(value) def config(self, entry): for i in self: @@ -305,8 +222,8 @@ class PackageRelationGroup(list): def append(self, value): if isinstance(value, basestring): - value = PackageRelation(value) - elif not isinstance(value, PackageRelation): + value = PackageRelationEntry(value) + elif not isinstance(value, PackageRelationEntry): raise ValueError super(PackageRelationGroup, self).append(value) @@ -322,6 +239,68 @@ class PackageRelationGroup(list): for i in value: self.append(i) +class PackageRelationEntry(object): + __slots__ = "name", "operator", "version", "arches" + + _re = re.compile(r'^(\S+)(?: \((<<|<=|=|!=|>=|>>)\s*([^)]+)\))?(?: \[([^]]+)\])?$') + + class _operator(object): + OP_LT = 1; OP_LE = 2; OP_EQ = 3; OP_NE = 4; OP_GE = 5; OP_GT = 6 + operators = { '<<': OP_LT, '<=': OP_LE, '=': OP_EQ, '!=': OP_NE, '>=': OP_GE, '>>': OP_GT } + operators_neg = { OP_LT: OP_GE, OP_LE: OP_GT, OP_EQ: OP_NE, OP_NE: OP_EQ, OP_GE: OP_LT, OP_GT: OP_LE } + operators_text = dict([(b, a) for a, b in operators.iteritems()]) + + __slots__ = '_op', + + def __init__(self, value): + self._op = self.operators[value] + + def __neg__(self): + return self.__class__(self.operators_text[self.operators_neg[self._op]]) + + def __str__(self): + return self.operators_text[self._op] + + def __init__(self, value = None): + if isinstance(value, basestring): + self.parse(value) + else: + raise ValueError + + def __str__(self): + ret = [self.name] + if self.operator is not None and self.version is not None: + ret.extend([' (', str(self.operator), ' ', self.version, ')']) + if self.arches: + ret.extend([' [', ' '.join(self.arches), ']']) + return ''.join(ret) + + def config(self, entry): + if self.version is not None or self.arches: + return + value = entry.get(self.name, None) + if value is None: + return + print "config:", this + self.parse(value) + print "config:", this + + def parse(self, value): + match = self._re.match(value) + if match is None: + raise RuntimeError, "Can't parse dependency %s" % value + match = match.groups() + self.name = match[0] + if match[1] is not None: + self.operator = self._operator(match[1]) + else: + self.operator = None + self.version = match[2] + if match[3] is not None: + self.arches = re.split('\s+', match[3]) + else: + self.arches = [] + class Package(dict): _fields = utils.SortedDict(( ('Package', str), @@ -332,15 +311,15 @@ class Package(dict): ('Maintainer', str), ('Uploaders', str), ('Standards-Version', str), - ('Build-Depends', PackageRelationList), - ('Build-Depends-Indep', PackageRelationList), - ('Provides', PackageRelationList), - ('Pre-Depends', PackageRelationList), - ('Depends', PackageRelationList), - ('Recommends', PackageRelationList), - ('Suggests', PackageRelationList), - ('Replaces', PackageRelationList), - ('Conflicts', PackageRelationList), + ('Build-Depends', PackageRelation), + ('Build-Depends-Indep', PackageRelation), + ('Provides', PackageRelation), + ('Pre-Depends', PackageRelation), + ('Depends', PackageRelation), + ('Recommends', PackageRelation), + ('Suggests', PackageRelation), + ('Replaces', PackageRelation), + ('Conflicts', PackageRelation), ('Description', PackageDescription), )) |