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