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
@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
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('/')
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:
"""
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:
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(
"""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:
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))
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):
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, '.')
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):
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"])
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)