Commit ddbc1740 authored by Guido Günther's avatar Guido Günther

UpstreamSource: turn is_* vars and properties into methods

since this is more consistent with the other is_* methods in other
classes.
parent cc6ee3b5
......@@ -94,8 +94,6 @@ class UpstreamSource(object):
Upstream source. Can be either an unpacked dir, a tarball or another type
of archive
@cvar is_dir: are the upstream sources an unpacked dir
@type is_dir: boolean
@cvar _orig: are the upstream sources already suitable as an upstream
tarball
@type _orig: boolean
......@@ -105,19 +103,17 @@ class UpstreamSource(object):
@type _unpacked: string
"""
def __init__(self, name, unpacked=None):
self.is_dir = False
self._orig = False
self._path = name
self.unpacked = unpacked
self.is_dir = [False, True][os.path.isdir(name)]
self._check_orig()
if self.is_dir:
if self.is_dir():
self.unpacked = self.path
def _check_orig(self):
"""Check if archive can be used as orig tarball"""
if self.is_dir:
if self.is_dir():
self._orig = False
return
......@@ -130,10 +126,22 @@ class UpstreamSource(object):
except IndexError:
self._orig = False
@property
def is_orig(self):
"""
@return: C{True} if sources are suitable as upstream source,
C{False} otherwise
@rtype: C{bool}
"""
return self._orig
def is_dir(self):
"""
@return: C{True} if if upstream sources are an unpacked directory,
C{False} otherwise
@rtype: C{bool}
"""
return True if os.path.isdir(self._path) else False
@property
def path(self):
return self._path.rstrip('/')
......@@ -143,7 +151,7 @@ class UpstreamSource(object):
Unpack packed upstream sources into a given directory
and determine the toplevel of the source tree.
"""
if self.is_dir:
if self.is_dir():
raise GbpError, "Cannot unpack directory %s" % self.path
if not filters:
......
......@@ -62,7 +62,7 @@ class OrigUpstreamSource(UpstreamSource):
"""
if ((options.pristine_tar and options.filter_pristine_tar and len(options.filters) > 0)):
return True
elif not self.is_orig:
elif not self.is_orig():
if len(options.filters):
return True
elif options.pristine_tar:
......@@ -224,7 +224,7 @@ def find_source(options, args):
def repacked_tarball_name(source, name, version):
if source.is_orig:
if source.is_orig():
# Repacked orig tarballs get need a different name since there's already
# one with that name
name = os.path.join(
......@@ -242,7 +242,7 @@ def repack_source(source, name, version, tmpdir, filters):
"""Repack the source tree"""
name = repacked_tarball_name(source, name, version)
repacked = source.pack(name, filters)
if source.is_orig: # the tarball was filtered on unpack
if source.is_orig(): # the tarball was filtered on unpack
repacked.unpacked = source.unpacked
else: # otherwise unpack the generated tarball get a filtered tree
if tmpdir:
......@@ -360,7 +360,7 @@ def main(argv):
if repo.bare:
set_bare_repo_options(options)
if not source.is_dir:
if not source.is_dir():
tmpdir = tempfile.mkdtemp(dir='../')
source.unpack(tmpdir, options.filters)
gbp.log.debug("Unpacked '%s' to '%s'" % (source.path, source.unpacked))
......
......@@ -50,12 +50,12 @@ class TestUnpack:
def test_upstream_source_type(self):
for (comp, archive) in self.archives.iteritems():
source = gbp.deb.UpstreamSource(archive[0])
assert source.is_orig == True
assert source.is_dir == False
assert source.is_orig() == True
assert source.is_dir() == False
assert source.unpacked == None
source.unpack(".")
assert source.is_orig == True
assert source.is_dir == False
assert source.is_orig() == True
assert source.is_dir() == False
assert type(source.unpacked) == str
def test_upstream_source_unpack(self):
......
......@@ -16,7 +16,7 @@ class TestDir(unittest.TestCase):
def test_directory(self):
"""Upstream source is a directory"""
source = UpstreamSource('.')
self.assertEqual(source.is_orig, False)
self.assertEqual(source.is_orig(), False)
self.assertEqual(source.path, '.')
self.assertEqual(source.unpacked, '.')
......@@ -50,8 +50,8 @@ class TestTar(unittest.TestCase):
target = os.path.join(self.tmpdir,
"gbp_0.1.tar.bz2")
repacked = source.pack(target)
self.assertEqual(repacked.is_orig, True)
self.assertEqual(repacked.is_dir, False)
self.assertEqual(repacked.is_orig(), True)
self.assertEqual(repacked.is_dir(), False)
self._check_tar(repacked, ["gbp/errors.py", "gbp/__init__.py"])
def test_pack_filtered(self):
......@@ -60,8 +60,8 @@ class TestTar(unittest.TestCase):
target = os.path.join(self.tmpdir,
"gbp_0.1.tar.bz2")
repacked = source.pack(target, ["__init__.py"])
self.assertEqual(repacked.is_orig, True)
self.assertEqual(repacked.is_dir, False)
self.assertEqual(repacked.is_orig(), True)
self.assertEqual(repacked.is_dir(), False)
self._check_tar(repacked, ["gbp/errors.py"],
["gbp/__init__.py"])
......@@ -82,8 +82,8 @@ class TestZip(unittest.TestCase):
def test_unpack(self):
source = UpstreamSource(self.zipfile)
self.assertEqual(source.is_orig, False)
self.assertEqual(source.is_dir, False)
self.assertEqual(source.is_orig(), False)
self.assertEqual(source.is_dir(), False)
self.assertEqual(source.unpacked, None)
source.unpack(self.tmpdir)
self.assertNotEqual(source.unpacked, None)
......
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