[Pkg-python-debian-commits] trunk r102: Merge in changes for #473259
John Wright
jsw at debian.org
Wed Apr 30 23:28:35 UTC 2008
------------------------------------------------------------
revno: 102
committer: John Wright <jsw at debian.org>
branch nick: trunk
timestamp: Wed 2008-04-30 17:28:35 -0600
message:
Merge in changes for #473259
modified:
debian/changelog
debian_bundle/deb822.py
------------------------------------------------------------
revno: 100.2.1
committer: john.wright at hp.com
branch nick: bug473259
timestamp: Wed 2008-04-30 17:23:15 -0600
message:
Add support for fixed-length fields in multivalued fields. If the subclass
provides a _fixed_field_lengths dictionary attribute mapping multivalued field
keys to {subfield: length} dictionaries, those lengths will be used. See
Release and PdiffIndex classes for an example.
modified:
debian_bundle/deb822.py
-------------- next part --------------
=== modified file 'debian/changelog'
--- a/debian/changelog 2008-04-02 08:18:17 +0000
+++ b/debian/changelog 2008-04-30 23:28:35 +0000
@@ -4,8 +4,16 @@
- Do not cache _CaseInsensitiveString objects, since it causes case
preservation issues under certain circumstances (Closes: #473254)
- Add a test case
+ * debian_bundle/deb822.py:
+ - Add support for fixed-length subfields in multivalued fields. I updated
+ the Release and PdiffIndex classes to use this. The default behavior for
+ Release is that of apt-ftparchive, just because it's simpler. Changing
+ the behavior to resemble dak requires simply setting the
+ size_field_behavior attribute to 'dak'. (Ideally, deb822 would detect
+ which behavior to use if given an actual Release file as input, but this
+ is not implemented yet.) (Closes: #473259)
- -- John Wright <jsw at debian.org> Wed, 02 Apr 2008 02:17:23 -0600
+ -- John Wright <jsw at debian.org> Wed, 30 Apr 2008 17:25:12 -0600
python-debian (0.1.9) unstable; urgency=low
=== modified file 'debian_bundle/deb822.py'
--- a/debian_bundle/deb822.py 2008-04-02 08:18:17 +0000
+++ b/debian_bundle/deb822.py 2008-04-30 23:28:35 +0000
@@ -32,7 +32,7 @@
import StringIO
import UserDict
-class Deb822Dict(UserDict.DictMixin):
+class Deb822Dict(object, UserDict.DictMixin):
# Subclassing UserDict.DictMixin because we're overriding so much dict
# functionality that subclassing dict requires overriding many more than
# the four methods that DictMixin requires.
@@ -441,15 +441,27 @@
fd.write('%s: %s\n' % (key, value))
else:
fd.write(key + ":")
- if isinstance(self[key], dict): # single-line
+ if hasattr(self[key], 'keys'): # single-line
array = [ self[key] ]
else: # multi-line
fd.write("\n")
array = self[key]
order = self._multivalued_fields[keyl]
+ try:
+ field_lengths = self._fixed_field_lengths
+ except AttributeError:
+ field_lengths = {}
for item in array:
- fd.write(" " + " ".join([item[x] for x in order]))
+ for x in order:
+ raw_value = str(item[x])
+ try:
+ length = field_lengths[keyl][x]
+ except KeyError:
+ value = raw_value
+ else:
+ value = (length - len(raw_value)) * " " + raw_value
+ fd.write(" %s" % value)
fd.write("\n")
if return_string:
return fd.getvalue()
@@ -499,14 +511,64 @@
"sha1-patches": [ "SHA1", "size", "date" ],
}
+ @property
+ def _fixed_field_lengths(self):
+ fixed_field_lengths = {}
+ for key in self._multivalued_fields:
+ if hasattr(self[key], 'keys'):
+ # Not multi-line -- don't need to compute the field length for
+ # this one
+ continue
+ length = self._get_size_field_length(key)
+ fixed_field_lengths[key] = {"size": length}
+ return fixed_field_lengths
+
+ def _get_size_field_length(self, key):
+ lengths = [len(str(item['size'])) for item in self[key]]
+ return max(lengths)
+
class Release(_multivalued):
+ """Represents a Release file
+
+ Set the size_field_behavior attribute to "dak" to make the size field
+ length only as long as the longest actual value. The default,
+ "apt-ftparchive" makes the field 16 characters long regardless.
+ """
+ # FIXME: Add support for detecting the behavior of the input, if
+ # constructed from actual 822 text.
+
_multivalued_fields = {
"md5sum": [ "md5sum", "size", "name" ],
"sha1": [ "sha1", "size", "name" ],
"sha256": [ "sha256", "size", "name" ],
}
+ __size_field_behavior = "apt-ftparchive"
+ def set_size_field_behavior(self, value):
+ if value not in ["apt-ftparchive", "dak"]:
+ raise ValueError("size_field_behavior must be either "
+ "'apt-ftparchive' or 'dak'")
+ else:
+ self.__size_field_behavior = value
+ size_field_behavior = property(lambda self: self.__size_field_behavior,
+ set_size_field_behavior)
+
+ @property
+ def _fixed_field_lengths(self):
+ fixed_field_lengths = {}
+ for key in self._multivalued_fields:
+ length = self._get_size_field_length(key)
+ fixed_field_lengths[key] = {"size": length}
+ return fixed_field_lengths
+
+ def _get_size_field_length(self, key):
+ if self.size_field_behavior == "apt-ftparchive":
+ return 16
+ elif self.size_field_behavior == "dak":
+ lengths = [len(str(item['size'])) for item in self[key]]
+ return max(lengths)
+
Sources = Dsc
Packages = Deb822
More information about the pkg-python-debian-commits
mailing list