def test_is_native_file_3_file(self):
        """Test native package of format 3"""
        source = DebianSource('.')
        os.makedirs('debian/source')

        dsf = DebianSourceFormat.from_content("3.0", "native")
        self.assertEqual(dsf.type, 'native')
        self.assertTrue(source.is_native(False))

        dsf = DebianSourceFormat.from_content("3.0", "quilt")
        self.assertEqual(dsf.type, 'quilt')
        self.assertFalse(source.is_native(True))
    def test_is_native_file_3_file(self):
        """Test native package of format 3"""
        source = DebianSource('.')
        os.makedirs('debian/source')
        self.assertRaises(DebianSourceError, source.is_native)

        dsf = DebianSourceFormat.from_content("3.0", "native")
        self.assertEqual(dsf.type, 'native')
        self.assertTrue(source.is_native())

        dsf = DebianSourceFormat.from_content("3.0", "quilt")
        self.assertEqual(dsf.type, 'quilt')
        self.assertFalse(source.is_native())
Example #3
0
def is_30_quilt(repo, options):
    format_file = DebianSourceFormat.format_file
    try:
        content = GitVfs(repo, options.debian_branch).open(format_file).read()
    except IOError:
        return False
    return str(DebianSourceFormat(content)) == "3.0 (quilt)"
def extract_orig(orig_tarball, dest_dir):
    """extract orig tarball to export dir before exporting from git"""
    gbp.log.info("Extracting %s to '%s'" % (os.path.basename(orig_tarball), dest_dir))

    move_old_export(dest_dir)
    upstream = DebianUpstreamSource(orig_tarball)
    upstream.unpack(dest_dir)

    # Check if tarball extracts into a single folder:
    if upstream.unpacked != dest_dir:
        # If it extracts a single folder, move its contents to dest_dir:
        gbp.log.debug("Moving %s to %s" % (upstream.unpacked, dest_dir))
        tmpdir = dest_dir + '.new'
        os.rename(upstream.unpacked, tmpdir)
        os.rmdir(dest_dir)
        os.rename(tmpdir, dest_dir)

    # Remove debian/ from unpacked upstream tarball in case of non 1.0 format
    underlay_debian_dir = os.path.join(dest_dir, 'debian')
    format_file = os.path.join('debian', 'source', 'format')
    if os.path.exists(underlay_debian_dir) and os.path.exists(format_file):
        format = DebianSourceFormat.parse_file(format_file)
        if format.version in ['2.0', '3.0']:
            gbp.log.info("Removing debian/ from unpacked upstream source at %s" % underlay_debian_dir)
            shutil.rmtree(underlay_debian_dir)
Example #5
0
def extract_orig(orig_tarball, dest_dir):
    """extract orig tarball to export dir before exporting from git"""
    gbp.log.info("Extracting %s to '%s'" %
                 (os.path.basename(orig_tarball), dest_dir))

    move_old_export(dest_dir)
    upstream = DebianUpstreamSource(orig_tarball)
    upstream.unpack(dest_dir)

    # Check if tarball extracts into a single folder:
    if upstream.unpacked != dest_dir:
        # If it extracts a single folder, move its contents to dest_dir:
        gbp.log.debug("Moving %s to %s" % (upstream.unpacked, dest_dir))
        tmpdir = dest_dir + '.new'
        os.rename(upstream.unpacked, tmpdir)
        os.rmdir(dest_dir)
        os.rename(tmpdir, dest_dir)

    # Remove debian/ from unpacked upstream tarball in case of non 1.0 format
    underlay_debian_dir = os.path.join(dest_dir, 'debian')
    format_file = os.path.join('debian', 'source', 'format')
    if os.path.exists(underlay_debian_dir) and os.path.exists(format_file):
        format = DebianSourceFormat.parse_file(format_file)
        if format.version in ['2.0', '3.0']:
            gbp.log.info("Removing debian/ from unpacked upstream "
                         "source at %s" % underlay_debian_dir)
            shutil.rmtree(underlay_debian_dir)
 def _commit_format(self, version, format):
     # Commit a format file to disk
     if not os.path.exists('debian/source'):
         os.makedirs('debian/source')
     dsf = DebianSourceFormat.from_content(version, format)
     self.assertEqual(dsf.type, format)
     self.repo.add_files('.')
     self.repo.commit_all('foo')
     os.unlink('debian/source/format')
     self.assertFalse(os.path.exists('debian/source/format'))
 def _commit_format(self, version, format):
     # Commit a format file to disk
     if not os.path.exists('debian/source'):
         os.makedirs('debian/source')
     dsf = DebianSourceFormat.from_content(version, format)
     self.assertEqual(dsf.type, format)
     self.repo.add_files('.')
     self.repo.commit_all('foo')
     os.unlink('debian/source/format')
     self.assertFalse(os.path.exists('debian/source/format'))
Example #8
0
    def is_native(self):
        """
        Whether this is a native Debian package
        """
        try:
            with self._vfs.open('debian/source/format') as ff:
                f = DebianSourceFormat(ff.read())
            if f.type:
                return f.type == 'native'
        except IOError as e:
            pass  # Fall back to changelog parsing

        try:
            return '-' not in self.changelog.version
        except IOError as e:
            raise DebianSourceError("Failed to determine source format: %s" % e)
def overlay_extract_origs(source, tarball_dir, dest_dir, options):
    """Overlay extract orig tarballs to export dir before exporting debian dir from git"""

    comp_type = guess_comp_type(options.comp_type,
                                source,
                                repo=None,
                                tarball_dir=tarball_dir)
    tarball = os.path.join(tarball_dir,
                           source.upstream_tarball_name(comp_type))
    gbp.log.info("Extracting '%s' to '%s'" %
                 (os.path.basename(tarball), dest_dir))

    move_old_export(dest_dir)
    upstream = DebianUpstreamSource(tarball)
    upstream.unpack(dest_dir)

    # Check if tarball extracts into a single folder:
    if upstream.unpacked != dest_dir:
        # If it extracts a single folder, move its contents to dest_dir:
        gbp.log.debug("Moving %s to %s" % (upstream.unpacked, dest_dir))
        tmpdir = dest_dir + '.new'
        os.rename(upstream.unpacked, tmpdir)
        os.rmdir(dest_dir)
        os.rename(tmpdir, dest_dir)

    # Remove debian/ from unpacked upstream tarball in case of non 1.0 format
    underlay_debian_dir = os.path.join(dest_dir, 'debian')
    format_file = os.path.join('debian', 'source', 'format')
    if os.path.exists(underlay_debian_dir) and os.path.exists(format_file):
        format = DebianSourceFormat.parse_file(format_file)
        if format.version in ['2.0', '3.0']:
            gbp.log.info("Removing debian/ from unpacked upstream "
                         "source at %s" % underlay_debian_dir)
            shutil.rmtree(underlay_debian_dir)

    # Unpack additional tarballs
    for c in options.components:
        tarball = DebianAdditionalTarball(os.path.join(
            tarball_dir, source.upstream_tarball_name(comp_type, component=c)),
                                          component=c)
        gbp.log.info("Extracting '%s' to '%s/%s'" %
                     (os.path.basename(tarball.path), dest_dir, c))
        tarball.unpack(dest_dir, [])
Example #10
0
def overlay_extract_origs(source, tarball_dir, dest_dir, options):
    """Overlay extract orig tarballs to export dir before exporting debian dir from git"""

    comp_type = guess_comp_type(options.comp_type,
                                source,
                                repo=None,
                                tarball_dir=tarball_dir)
    tarball = os.path.join(tarball_dir, source.upstream_tarball_name(comp_type))
    gbp.log.info("Extracting '%s' to '%s'" % (os.path.basename(tarball), dest_dir))

    move_old_export(dest_dir)
    upstream = DebianUpstreamSource(tarball)
    upstream.unpack(dest_dir)

    # Check if tarball extracts into a single folder:
    if upstream.unpacked != dest_dir:
        # If it extracts a single folder, move its contents to dest_dir:
        gbp.log.debug("Moving %s to %s" % (upstream.unpacked, dest_dir))
        tmpdir = dest_dir + '.new'
        os.rename(upstream.unpacked, tmpdir)
        os.rmdir(dest_dir)
        os.rename(tmpdir, dest_dir)

    # Remove debian/ from unpacked upstream tarball in case of non 1.0 format
    underlay_debian_dir = os.path.join(dest_dir, 'debian')
    format_file = os.path.join('debian', 'source', 'format')
    if os.path.exists(underlay_debian_dir) and os.path.exists(format_file):
        format = DebianSourceFormat.parse_file(format_file)
        if format.version in ['2.0', '3.0']:
            gbp.log.info("Removing debian/ from unpacked upstream "
                         "source at %s" % underlay_debian_dir)
            shutil.rmtree(underlay_debian_dir)

    # Unpack additional tarballs
    for c in options.components:
        tarball = os.path.join(tarball_dir, source.upstream_tarball_name(
            comp_type, component=c))
        gbp.log.info("Extracting '%s' to '%s/%s'" % (os.path.basename(tarball), dest_dir, c))
        unpack_component_tarball(dest_dir, c, tarball, [])