def render(self, dest):
     """
     We're actually rendering a tarball out, not files from a model
     directory. We also expect that `dest' is in pkgname-version format,
     ready for taring up.
     """
     dest = abspath("%s/../" % (dest))
     make_orig_tarball(dest, self.pkgname, self.version,
                       compression=self.compression,
                       outputdir=dest)
def test_localdir_generation():
    pkgname = "pkgfoo"
    version = "2.0"
    debdir = "%s-%s" % (pkgname, version)
    compression = "bzip2"
    tarball = "%s_%s.orig.tar.bz2" % (pkgname, version)

    with tmpdir() as tmp:
        with cd(tmp):
            mkdir(debdir)
            assert not os.path.exists(tarball)
            make_orig_tarball(".", pkgname, version, compression=compression)
            assert os.path.exists(tarball)
def test_insane_compression_fails():
    pkgname = "pkgfoo"
    version = "2.0"
    debdir = "%s-%s" % (pkgname, version)

    with tmpdir() as tmp:
        with cd(tmp):
            mkdir(debdir)
            try:
                make_orig_tarball(".", pkgname, version, compression="asfasf")
                assert True is False
            except ValueError:
                assert True is True
def make_and_check_tarball(testname, rundir, upname, upversion, compression,
                           visitor, visit_open=True):
    """Create, check and clean up a tarball (test utility)

    Utility for setting up a dir, compile a tarball from a resource path,
    opening the tarball and passing it to vistor.

    testname is used to create a unique name for the test.  The
    compression is also used for this purpose, so multiple tests can
    share the same "testname" as long as the compression differs.

    rundir, upname, upversion and compression are passed (as is) to
    make_orig_tarball.

    The tarball passed to visitor may not be seekable and should be
    checked inorder.
    """

    testdir = "%s-%s" % (testname, compression)
    xtn = compression
    if xtn == "gzip":
        xtn = "gz"
    elif xtn == "bzip2":
        xtn = "bz2"

    rundir = abspath(rundir)

    with tmpdir() as tmp:
        with cd(tmp):
            mkdir(testdir)

            make_orig_tarball(rundir, upname, upversion,
                              compression=compression, outputdir=testdir)
            tarname = "%s_%s.orig.tar.%s" % (upname, upversion, xtn)
            path = os.path.join(testdir, tarname)
            if visit_open:
                with open_compressed_tarball(path, compression) as tar:
                    visitor(tar)
            else:
                visitor(path)