Commit 628e0dac authored by Guido Günther's avatar Guido Günther

uscan: disentangle logic a bit

parent b1e593e6
......@@ -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('<status>up to date</status>')
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\:·:
......@@ -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:
......
......@@ -39,6 +39,6 @@ gpgv: aka "Richard W.M. Jones <rich@annexia.org>"
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')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment