Merge lp:~stevenk/python-debian/merge-and-stricter into lp:~launchpad-pqm/python-debian/devel

Proposed by Steve Kowalik
Status: Merged
Merged at revision: 186
Proposed branch: lp:~stevenk/python-debian/merge-and-stricter
Merge into: lp:~launchpad-pqm/python-debian/devel
Diff against target: 361 lines (+184/-22)
8 files modified
debian/changelog (+14/-10)
debian/control (+2/-2)
lib/debian/changelog.py (+77/-0)
lib/debian/deb822.py (+27/-10)
lib/debian/debian_support.py (+4/-0)
tests/test_Sources.mixed_encoding (+34/-0)
tests/test_changelog.py (+2/-0)
tests/test_deb822.py (+24/-0)
To merge this branch: bzr merge lp:~stevenk/python-debian/merge-and-stricter
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
William Grant (community) code* Approve
Review via email: mp+55277@code.launchpad.net

Description of the change

Merge to the tip of lp:python-debian, and include a patch that makes BaseVersion stricter about versions.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code*)
Revision history for this message
Robert Collins (lifeless) wrote :

Looks fine to me

review: Approve
Revision history for this message
Robert Collins (lifeless) wrote :

(the find() -> in change would be nice too, of course)

188. By Steve Kowalik

Use in, rather than .find()

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2010-08-02 22:12:54 +0000
+++ debian/changelog 2011-03-29 04:59:41 +0000
@@ -1,19 +1,23 @@
1python-debian (0.1.17~bzr184~launchpad2) hardy; urgency=low1python-debian (0.1.18) unstable; urgency=low
2
3 * Support installation together with older versions of python-apt.
4 Original patch by Jelmer Vernooij. (Closes: #590805)
5
6 -- John Wright <jsw@debian.org> Wed, 04 Aug 2010 01:16:52 -0700
7
8python-debian (0.1.17) unstable; urgency=low
29
3 [ James Westby ]10 [ James Westby ]
4 * Use os.path.normpath to hide python version differences11 * Use os.path.normpath to hide python version differences
512
6 [ John Wright ]13 [ John Wright ]
7 * test_deb822.py: Make test_gpg_info more robust (Closes: #582878)14 * test_deb822.py: Make test_gpg_info more robust (Closes: #582878)
8 * Support installation together with older versions of python-apt.15 * deb822: Use chardet to try to detect character encodings as necessary
9 Original patch by Jelmer Vernooij. (Closes: #590805)16 - This is only used when the specified encoding doesn't work. It's mainly
1017 useful for files containing multiple deb822 paragraphs with mixed
11 [ Jelmer Vernooij ]18 encodings, like etch's Sources file. (Closes: #586021)
12 * Always use NativeVersion class to work around Debian bug #573592.19
13 * Upload to Launchpad PPA.20 -- John Wright <jsw@debian.org> Sun, 25 Jul 2010 02:07:11 -0700
14 * Downgrade source format to 1.0 to support building on Hardy.
15
16 -- Jelmer Vernooij <jelmer@debian.org> Thu, 29 Jul 2010 14:23:02 +0200
1721
18python-debian (0.1.16) unstable; urgency=low22python-debian (0.1.16) unstable; urgency=low
1923
2024
=== modified file 'debian/control'
--- debian/control 2010-08-02 22:12:54 +0000
+++ debian/control 2011-03-29 04:59:41 +0000
@@ -8,7 +8,7 @@
8 Reinhard Tartler <siretart@tauware.de>,8 Reinhard Tartler <siretart@tauware.de>,
9 Stefano Zacchiroli <zack@debian.org>,9 Stefano Zacchiroli <zack@debian.org>,
10 John Wright <jsw@debian.org>10 John Wright <jsw@debian.org>
11Build-Depends: debhelper (>= 5.0.37.2), python, python-setuptools11Build-Depends: debhelper (>= 5.0.37.2), python, python-setuptools, python-chardet
12Build-Depends-Indep: python-support (>= 0.3)12Build-Depends-Indep: python-support (>= 0.3)
13Standards-Version: 3.8.413Standards-Version: 3.8.4
14Vcs-Browser: http://git.debian.org/?p=pkg-python-debian/python-debian.git14Vcs-Browser: http://git.debian.org/?p=pkg-python-debian/python-debian.git
@@ -16,7 +16,7 @@
1616
17Package: python-debian17Package: python-debian
18Architecture: all18Architecture: all
19Depends: ${python:Depends}, ${misc:Depends}19Depends: ${python:Depends}, ${misc:Depends}, python-chardet
20Recommends: python-apt20Recommends: python-apt
21Suggests: gpgv21Suggests: gpgv
22Provides: python-deb82222Provides: python-deb822
2323
=== modified file 'lib/debian/changelog.py'
--- lib/debian/changelog.py 2010-03-14 09:16:30 +0000
+++ lib/debian/changelog.py 2011-03-29 04:59:41 +0000
@@ -23,7 +23,10 @@
2323
24"""This module implements facilities to deal with Debian changelogs."""24"""This module implements facilities to deal with Debian changelogs."""
2525
26import os
27import pwd
26import re28import re
29import socket
27import warnings30import warnings
2831
29import debian_support32import debian_support
@@ -470,3 +473,77 @@
470473
471 def write_to_open_file(self, file):474 def write_to_open_file(self, file):
472 file.write(self.__str__())475 file.write(self.__str__())
476
477
478def get_maintainer():
479 """Get the maintainer information in the same manner as dch.
480
481 This function gets the information about the current user for
482 the maintainer field using environment variables of gecos
483 informations as approriate.
484
485 It uses the same methods as dch to get the information, namely
486 DEBEMAIL, DEBFULLNAME, EMAIL, NAME, /etc/mailname and gecos.
487
488 :returns: a tuple of the full name, email pair as strings.
489 Either of the pair may be None if that value couldn't
490 be determined.
491 """
492 env = os.environ
493 regex = re.compile(r"^(.*)\s+<(.*)>$")
494
495 # Split email and name
496 if 'DEBEMAIL' in env:
497 match_obj = regex.match(env['DEBEMAIL'])
498 if match_obj:
499 if not 'DEBFULLNAME' in env:
500 env['DEBFULLNAME'] = match_obj.group(1)
501 env['DEBEMAIL'] = match_obj.group(2)
502 if 'DEBEMAIL' not in env or 'DEBFULLNAME' not in env:
503 if 'EMAIL' in env:
504 match_obj = regex.match(env['EMAIL'])
505 if match_obj:
506 if not 'DEBFULLNAME' in env:
507 env['DEBFULLNAME'] = match_obj.group(1)
508 env['EMAIL'] = match_obj.group(2)
509
510 # Get maintainer's name
511 if 'DEBFULLNAME' in env:
512 maintainer = env['DEBFULLNAME']
513 elif 'NAME' in env:
514 maintainer = env['NAME']
515 else:
516 # Use password database if no data in environment variables
517 try:
518 maintainer = re.sub(r',.*', '', pwd.getpwuid(os.getuid()).pw_gecos)
519 except (KeyError, AttributeError):
520 maintainer = None
521
522 # Get maintainer's mail address
523 if 'DEBEMAIL' in env:
524 email = env['DEBEMAIL']
525 elif 'EMAIL' in env:
526 email = env['EMAIL']
527 else:
528 addr = None
529 if os.path.exists('/etc/mailname'):
530 f = open('/etc/mailname')
531 try:
532 addr = f.readline().strip()
533 finally:
534 f.close()
535 if not addr:
536 addr = socket.getfqdn()
537 if addr:
538 user = pwd.getpwuid(os.getuid()).pw_name
539 if not user:
540 addr = None
541 else:
542 addr = "%s@%s" % (user, addr)
543
544 if addr:
545 email = addr
546 else:
547 email = None
548
549 return (maintainer, email)
473550
=== modified file 'lib/debian/deb822.py'
--- lib/debian/deb822.py 2010-08-02 22:12:54 +0000
+++ lib/debian/deb822.py 2011-03-29 04:59:41 +0000
@@ -4,7 +4,7 @@
4# (.changes, .dsc, Packages, Sources, etc)4# (.changes, .dsc, Packages, Sources, etc)
5#5#
6# Copyright (C) 2005-2006 dann frazier <dannf@dannf.org>6# Copyright (C) 2005-2006 dann frazier <dannf@dannf.org>
7# Copyright (C) 2006-2008 John Wright <john@johnwright.org>7# Copyright (C) 2006-2010 John Wright <john@johnwright.org>
8# Copyright (C) 2006 Adeodato Simó <dato@net.com.org.es>8# Copyright (C) 2006 Adeodato Simó <dato@net.com.org.es>
9# Copyright (C) 2008 Stefano Zacchiroli <zack@upsilon.cc>9# Copyright (C) 2008 Stefano Zacchiroli <zack@upsilon.cc>
10#10#
@@ -32,10 +32,13 @@
32except (ImportError, AttributeError):32except (ImportError, AttributeError):
33 _have_apt_pkg = False33 _have_apt_pkg = False
3434
35import chardet
35import new36import new
36import re37import re
37import string38import string
38import sys39import sys
40import warnings
41
39import StringIO42import StringIO
40import UserDict43import UserDict
4144
@@ -178,7 +181,25 @@
178181
179 if isinstance(value, str):182 if isinstance(value, str):
180 # Always return unicode objects instead of strings183 # Always return unicode objects instead of strings
181 value = value.decode(self.encoding)184 try:
185 value = value.decode(self.encoding)
186 except UnicodeDecodeError, e:
187 # Evidently, the value wasn't encoded with the encoding the
188 # user specified. Try detecting it.
189 warnings.warn('decoding from %s failed; attempting to detect '
190 'the true encoding' % self.encoding,
191 UnicodeWarning)
192 result = chardet.detect(value)
193 try:
194 value = value.decode(result['encoding'])
195 except UnicodeDecodeError:
196 raise e
197 else:
198 # Assume the rest of the paragraph is in this encoding as
199 # well (there's no sense in repeating this exercise for
200 # every field).
201 self.encoding = result['encoding']
202
182 return value203 return value
183204
184 def __delitem__(self, key):205 def __delitem__(self, key):
@@ -309,33 +330,29 @@
309 curkey = None330 curkey = None
310 content = ""331 content = ""
311 for line in self.gpg_stripped_paragraph(sequence):332 for line in self.gpg_stripped_paragraph(sequence):
312 if isinstance(line, str):
313 line = line.decode(self.encoding)
314 m = single.match(line)333 m = single.match(line)
315 if m:334 if m:
316 if curkey:335 if curkey:
317 self[curkey] += content336 self[curkey] = content
318337
319 if not wanted_field(m.group('key')):338 if not wanted_field(m.group('key')):
320 curkey = None339 curkey = None
321 continue340 continue
322341
323 curkey = m.group('key')342 curkey = m.group('key')
324 self[curkey] = m.group('data')343 content = m.group('data')
325 content = ""
326 continue344 continue
327345
328 m = multi.match(line)346 m = multi.match(line)
329 if m:347 if m:
330 if curkey:348 if curkey:
331 self[curkey] += content349 self[curkey] = content
332350
333 if not wanted_field(m.group('key')):351 if not wanted_field(m.group('key')):
334 curkey = None352 curkey = None
335 continue353 continue
336354
337 curkey = m.group('key')355 curkey = m.group('key')
338 self[curkey] = ""
339 content = ""356 content = ""
340 continue357 continue
341358
@@ -345,7 +362,7 @@
345 continue362 continue
346363
347 if curkey:364 if curkey:
348 self[curkey] += content365 self[curkey] = content
349366
350 def __str__(self):367 def __str__(self):
351 return self.dump()368 return self.dump()
352369
=== modified file 'lib/debian/debian_support.py'
--- lib/debian/debian_support.py 2010-03-14 11:37:42 +0000
+++ lib/debian/debian_support.py 2011-03-29 04:59:41 +0000
@@ -94,6 +94,10 @@
94 m = self.re_valid_version.match(version)94 m = self.re_valid_version.match(version)
95 if not m:95 if not m:
96 raise ValueError("Invalid version string %r" % version)96 raise ValueError("Invalid version string %r" % version)
97 # If there no epoch ("1:..."), then the upstream version can not
98 # contain a :.
99 if m.group("epoch") is None and ':' in m.group("upstream_version"):
100 raise ValueError("Invalid version string %r" % version)
97101
98 self.__full_version = version102 self.__full_version = version
99 self.__epoch = m.group("epoch")103 self.__epoch = m.group("epoch")
100104
=== added file 'tests/test_Sources.mixed_encoding'
--- tests/test_Sources.mixed_encoding 1970-01-01 00:00:00 +0000
+++ tests/test_Sources.mixed_encoding 2011-03-29 04:59:41 +0000
@@ -0,0 +1,34 @@
1Package: amarok
2Binary: amarok, amarok-engines, amarok-xine
3Version: 1.4.4-4etch1
4Priority: optional
5Section: kde
6Maintainer: Adeodato Simó <dato@net.com.org.es>
7Build-Depends: cdbs, debhelper (>= 5), quilt, bzip2, automake1.9, libtool, kdelibs4-dev, kdemultimedia-dev, kdebase-dev, libxine-dev, libtag1-dev (>> 1.4), libsqlite3-dev, libtunepimp3-dev, libmysqlclient15-dev, libpq-dev, xmms-dev, libvisual-0.4-dev, libsdl1.2-dev, libifp-dev, libusb-dev, libgpod-dev, libnjb-dev, ruby, ruby1.8-dev, dpkg-dev (>= 1.13.19)
8Architecture: any
9Standards-Version: 3.7.2
10Format: 1.0
11Directory: pool/main/a/amarok
12Files:
13 f8e80af55fbd8386e6b13b0b12d798f4 986 amarok_1.4.4-4etch1.dsc
14 0adbbd8373da2198b80e509618a2dab9 17628566 amarok_1.4.4.orig.tar.gz
15 c29b0538c033ededacc6d31339d17700 42402 amarok_1.4.4-4etch1.diff.gz
16Uploaders: Ana Beatriz Guerrero Lopez <ana@debian.org>
17
18Package: texinfo
19Binary: texinfo, info
20Version: 4.8.dfsg.1-4
21Priority: important
22Section: doc
23Maintainer: Norbert Preining <preining@debian.org>
24Build-Depends: debhelper (>= 5), dpatch, libncurses5-dev | libncurses-dev, gettext
25Architecture: any
26Standards-Version: 3.7.2
27Format: 1.0
28Directory: pool/main/t/texinfo
29Files:
30 2c233d2bf6627eac32deb9bb87726ea1 680 texinfo_4.8.dfsg.1-4.dsc
31 614273ac8568a25926aae374cd9a6683 1926534 texinfo_4.8.dfsg.1.orig.tar.gz
32 e01520524bc114d90a2a1e5eefe71b50 101211 texinfo_4.8.dfsg.1-4.diff.gz
33Uploaders: Frank Küster <frank@debian.org>
34
035
=== modified file 'tests/test_changelog.py'
--- tests/test_changelog.py 2010-03-14 09:16:30 +0000
+++ tests/test_changelog.py 2011-03-29 04:59:41 +0000
@@ -202,6 +202,8 @@
202 self._test_version('2:1.0.4+svn26-1ubuntu1', '2', '1.0.4+svn26',202 self._test_version('2:1.0.4+svn26-1ubuntu1', '2', '1.0.4+svn26',
203 '1ubuntu1')203 '1ubuntu1')
204 self._test_version('2:1.0.4~rc2-1', '2', '1.0.4~rc2', '1')204 self._test_version('2:1.0.4~rc2-1', '2', '1.0.4~rc2', '1')
205 self.assertRaises(
206 ValueError, changelog.Version, 'a1:1.8.8-070403-1~priv1')
205207
206 def test_version_updating(self):208 def test_version_updating(self):
207 v = changelog.Version('1:1.4.1-1')209 v = changelog.Version('1:1.4.1-1')
208210
=== modified file 'tests/test_deb822.py'
--- tests/test_deb822.py 2010-07-25 07:12:28 +0000
+++ tests/test_deb822.py 2011-03-29 04:59:41 +0000
@@ -21,6 +21,7 @@
21import re21import re
22import sys22import sys
23import unittest23import unittest
24import warnings
24from StringIO import StringIO25from StringIO import StringIO
2526
26sys.path.insert(0, '../lib/debian/')27sys.path.insert(0, '../lib/debian/')
@@ -702,6 +703,29 @@
702 self.assertEqual(utf8_contents, latin1_to_utf8.getvalue())703 self.assertEqual(utf8_contents, latin1_to_utf8.getvalue())
703 self.assertEqual(latin1_contents, utf8_to_latin1.getvalue())704 self.assertEqual(latin1_contents, utf8_to_latin1.getvalue())
704705
706 def test_mixed_encodings(self):
707 """Test that we can handle a simple case of mixed encodings
708
709 In general, this isn't guaranteed to work. It uses the chardet
710 package, which tries to determine heuristically the encoding of the
711 text given to it. But as far as I've seen, it's reliable for mixed
712 latin1 and utf-8 in maintainer names in old Sources files...
713 """
714
715 # Avoid spitting out the encoding warning during testing.
716 warnings.filterwarnings(action='ignore', category=UnicodeWarning)
717
718 filename = 'test_Sources.mixed_encoding'
719 for paragraphs in [deb822.Sources.iter_paragraphs(file(filename)),
720 deb822.Sources.iter_paragraphs(file(filename),
721 use_apt_pkg=False)]:
722 p1 = paragraphs.next()
723 self.assertEqual(p1['maintainer'],
724 u'Adeodato Simó <dato@net.com.org.es>')
725 p2 = paragraphs.next()
726 self.assertEqual(p2['uploaders'],
727 u'Frank Küster <frank@debian.org>')
728
705class TestPkgRelations(unittest.TestCase):729class TestPkgRelations(unittest.TestCase):
706730
707 def test_packages(self):731 def test_packages(self):

Subscribers

People subscribed via source and target branches