From 628e0dac5580476da4f8393cae383f4787da0a23 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Thu, 23 Nov 2017 13:06:03 +0100 Subject: uscan: disentangle logic a bit --- gbp/deb/uscan.py | 24 +++++++++++++++++------- gbp/scripts/import_orig.py | 16 +++++++--------- tests/31_test_uscan.py | 2 +- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/gbp/deb/uscan.py b/gbp/deb/uscan.py index 4e070933..0416587a 100644 --- a/gbp/deb/uscan.py +++ b/gbp/deb/uscan.py @@ -113,13 +113,16 @@ class Uscan(object): @param out: uscan output @type out: string + @returns: C{True} if package is uptodate >>> u = Uscan('http://example.com/') >>> u._parse_uptodate('up to date') + True >>> u.tarball >>> u.uptodate True >>> u._parse_uptodate('') + False >>> u.tarball >>> u.uptodate False @@ -128,6 +131,7 @@ class Uscan(object): self._uptodate = True else: self._uptodate = False + return self._uptodate def _raise_error(self, out): r""" @@ -171,7 +175,11 @@ class Uscan(object): raise UscanError(msg) def scan(self, destdir='..'): - """Invoke uscan to fetch a new upstream version""" + """ + Invoke uscan to fetch a new upstream version + + @returns: C{True} if a new version was downloaded + """ p = subprocess.Popen(['uscan', '--symlink', '--destdir=%s' % destdir, '--dehs'], cwd=self._dir, @@ -179,11 +187,13 @@ class Uscan(object): out = p.communicate()[0].decode() # uscan exits with 1 in case of uptodate and when an error occurred. # Don't fail in the uptodate case: - self._parse_uptodate(out) - if not self.uptodate: - if p.returncode: - self._raise_error(out) - else: - self._parse(out) + if self._parse_uptodate(out): + return False + + if p.returncode: + self._raise_error(out) + + self._parse(out) + return True # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index 1a690f85..97b6d54b 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -292,19 +292,17 @@ def find_upstream(use_uscan, args): uscan = Uscan() gbp.log.info("Launching uscan...") try: - uscan.scan() + if not uscan.scan(): + gbp.log.info("package is up to date, nothing to do.") + return None except UscanError as e: raise GbpError("%s" % e) - if uscan.uptodate: - gbp.log.info("package is up to date, nothing to do.") - return None + if uscan.tarball: + gbp.log.info("Using uscan downloaded tarball %s" % uscan.tarball) + args.append(uscan.tarball) else: - if uscan.tarball: - gbp.log.info("Using uscan downloaded tarball %s" % uscan.tarball) - args.append(uscan.tarball) - else: - raise GbpError("uscan didn't download anything, and no source was found in ../") + raise GbpError("uscan didn't download anything, and no source was found in ../") if len(args) > 1: # source specified raise GbpError("More than one archive specified. Try --help.") elif len(args) == 0: diff --git a/tests/31_test_uscan.py b/tests/31_test_uscan.py index 055f2647..5bd0e5e7 100644 --- a/tests/31_test_uscan.py +++ b/tests/31_test_uscan.py @@ -39,6 +39,6 @@ gpgv: aka "Richard W.M. Jones " def test_uscan(self, uscan_mock): """Test parsing a valid uscan file""" uscan = Uscan() - self.assertIsNone(uscan.scan()) + self.assertTrue(uscan.scan()) self.assertFalse(uscan.uptodate) self.assertEquals(uscan.tarball, '../virt-what_1.18.orig.tar.gz') -- cgit v1.2.3