Beispiel #1
0
    def test_update_component_tarballs(self):
        """
        Test importing new version with additional tarballs works
        """
        dsc = self._dsc('2.6-2')
        ok_(import_dsc(['arg0', '--pristine-tar', dsc]) == 0)
        repo = ComponentTestGitRepository(self.pkg)
        os.chdir(self.pkg)
        self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'])

        # Import 2.8
        orig = self._orig('2.8', dir='dsc-3.0-additional-tarballs')
        ok_(import_orig(['arg0', '--component=foo', '--no-interactive', '--pristine-tar', orig]) == 0)
        self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'],
                               tags=['debian/2.6-2', 'upstream/2.6', 'upstream/2.8'])
        self._check_component_tarballs(repo, ['foo/test1', 'foo/test2'])

        dsc = DscFile.parse(self._dsc('2.8-1', dir='dsc-3.0-additional-tarballs'))
        # Check if we can rebuild the upstream tarball and additional tarball
        ptars = [('hello-debhelper_2.8.orig.tar.gz', 'pristine-tar', '', dsc.tgz),
                 ('hello-debhelper_2.8.orig-foo.tar.gz', 'pristine-tar^', 'foo', dsc.additional_tarballs['foo'])]

        p = DebianPristineTar(repo)
        outdir = os.path.abspath('.')
        for f, w, s, o in ptars:
            eq_(repo.get_subject(w), 'pristine-tar data for %s' % f)
            old = self.hash_file(o)
            p.checkout('hello-debhelper', '2.8', 'gzip', outdir, component=s)
            out = os.path.join(outdir, f)
            new = self.hash_file(out)
            eq_(old, new, "Checksum %s of regenerated tarball %s does not match original %s" %
                (f, old, new))
            os.unlink(out)

        # Import 2.9
        orig = self._orig('2.9', dir='dsc-3.0-additional-tarballs')
        ok_(import_orig(['arg0', '--component=foo', '--no-interactive', '--pristine-tar', orig]) == 0)
        self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'],
                               tags=['debian/2.6-2', 'upstream/2.6', 'upstream/2.8', 'upstream/2.9'])
        self._check_component_tarballs(repo, ['foo/test1', 'foo/test2', 'foo/test3'])

        dsc = DscFile.parse(self._dsc('2.9-1', dir='dsc-3.0-additional-tarballs'))
        # Check if we can rebuild the upstream tarball and additional tarball
        ptars = [('hello-debhelper_2.9.orig.tar.gz', 'pristine-tar', '', dsc.tgz),
                 ('hello-debhelper_2.9.orig-foo.tar.gz', 'pristine-tar^', 'foo', dsc.additional_tarballs['foo'])]

        p = DebianPristineTar(repo)
        outdir = os.path.abspath('.')
        for f, w, s, o in ptars:
            eq_(repo.get_subject(w), 'pristine-tar data for %s' % f)
            old = self.hash_file(o)
            p.checkout('hello-debhelper', '2.9', 'gzip', outdir, component=s)
            new = self.hash_file(os.path.join(outdir, f))
            eq_(old, new, "Checksum %s of regenerated tarball %s does not match original %s" %
                (f, old, new))
 def test_dscfile_parse(self):
     """Test parsing a a 1.0 non-native dsc file without debian revision"""
     dsc = DscFile.parse(self.dscfile.name)
     self.assertEqual(dsc.version, '0.5')
     self.assertEqual(dsc.native, False)
     self.assertEqual(os.path.basename(dsc.tgz), 'latencytop_0.5.orig.tar.gz')
     self.assertEqual(os.path.basename(dsc.deb_tgz), '')
     self.assertEqual(os.path.basename(dsc.diff), 'latencytop_0.5.diff.gz')
     self.assertEqual(dsc.additional_tarballs, {}),
 def test_dscfile_parse(self):
     """Test parsing a a 1.0 non-native dsc file without debian revision"""
     dsc = DscFile.parse(self.dscfile.name)
     self.assertEqual(dsc.version, '0.5')
     self.assertEqual(dsc.native, False)
     self.assertEqual(os.path.basename(dsc.tgz),
                      'latencytop_0.5.orig.tar.gz')
     self.assertEqual(os.path.basename(dsc.deb_tgz), '')
     self.assertEqual(os.path.basename(dsc.diff), 'latencytop_0.5.diff.gz')
     self.assertEqual(dsc.additional_tarballs, {}),
 def test_dscfile_parse(self):
     """Test parsing a valid dsc file"""
     dsc = DscFile.parse(self.dscfile.name)
     self.assertEqual(dsc.version, '0.9.12-4')
     self.assertEqual(dsc.native, False)
     self.assertEqual(os.path.basename(dsc.tgz), 'libvirt_0.9.12.orig.tar.gz')
     self.assertEqual(os.path.basename(dsc.diff), '')
     self.assertEqual(os.path.basename(dsc.deb_tgz), 'libvirt_0.9.12-4.debian.tar.gz')
     for s in ['foo', 'bar']:
         self.assertEqual(os.path.basename(dsc.additional_tarballs[s]),
                          'libvirt_0.9.12.orig-%s.tar.gz' % s)
Beispiel #5
0
 def test_dscfile_parse(self):
     """Test parsing a valid dsc file"""
     dsc = DscFile.parse(self.dscfile.name)
     self.assertEqual(dsc.version, '0.9.12-4')
     self.assertEqual(dsc.native, False)
     self.assertEqual(os.path.basename(dsc.tgz), 'libvirt_0.9.12.orig.tar.gz')
     self.assertEqual(os.path.basename(dsc.diff), '')
     self.assertEqual(os.path.basename(dsc.deb_tgz), 'libvirt_0.9.12-4.debian.tar.gz')
     for s in ['foo', 'bar']:
         self.assertEqual(os.path.basename(dsc.additional_tarballs[s]),
                          'libvirt_0.9.12.orig-%s.tar.gz' % s)
    def test_import_30_additional_tarball_pristine_tar(self):
        """Test that importing a package with additional tarballs works"""
        def _dsc(version):
            return os.path.join(DEB_TEST_DATA_DIR,
                                'dsc-3.0-additional-tarballs',
                                'hello-debhelper_%s.dsc' % version)

        dscfile = _dsc('2.8-1')
        assert import_dsc([
            'arg0', '--verbose', '--pristine-tar', '--debian-branch=master',
            '--upstream-branch=upstream', dscfile
        ]) == 0
        repo = ComponentTestGitRepository('hello-debhelper')
        self._check_repo_state(repo, 'master',
                               ['master', 'pristine-tar', 'upstream'])
        commits, expected = len(repo.get_commits()), 2
        commitmsg = repo.get_commit_info('HEAD')['body']
        ok_("hello-debhelper (2.8-1) unstable; urgency=low" in commitmsg)
        ok_("hello (1.3-7) experimental; urgency=LOW" in commitmsg)

        for file in [b'foo/test1', b'foo/test2']:
            ok_(
                file in repo.ls_tree('HEAD'),
                "Could not find component tarball file %s in %s" %
                (file, repo.ls_tree('HEAD')))

        ok_(commits == expected,
            "Found %d commit instead of %d" % (commits, expected))

        dsc = DscFile.parse(dscfile)
        # Check if we can rebuild the tarball and component
        ptars = [('hello-debhelper_2.8.orig.tar.gz', 'pristine-tar', '',
                  dsc.tgz),
                 ('hello-debhelper_2.8.orig-foo.tar.gz', 'pristine-tar^',
                  'foo', dsc.additional_tarballs['foo'])]

        p = DebianPristineTar(repo)
        outdir = os.path.abspath('.')
        for f, w, s, o in ptars:
            eq_(repo.get_subject(w), 'pristine-tar data for %s' % f)
            old = self.hash_file(o)
            p.checkout('hello-debhelper', '2.8', 'gzip', outdir, component=s)
            new = self.hash_file(os.path.join(outdir, f))
            eq_(
                old, new,
                "Checksum %s of regenerated tarball %s does not match original %s"
                % (f, old, new))
Beispiel #7
0
    def test_import_multiple_pristine_tar(self):
        """Test if importing a multiple tarball package works"""
        def _dsc(version):
            return os.path.join(DEB_TEST_DATA_DIR,
                                'dsc-3.0-additional-tarballs',
                                'hello-debhelper_%s.dsc' % version)

        dscfile = _dsc('2.8-1')
        assert import_dsc(['arg0',
                           '--verbose',
                           '--pristine-tar',
                           '--debian-branch=master',
                           '--upstream-branch=upstream',
                           dscfile]) == 0
        repo = ComponentTestGitRepository('hello-debhelper')
        self._check_repo_state(repo, 'master', ['master', 'pristine-tar', 'upstream'])
        commits, expected = len(repo.get_commits()), 2
        commitmsg = repo.get_commit_info('HEAD')['body']
        ok_("hello-debhelper (2.8-1) unstable; urgency=low" in commitmsg)
        ok_("hello (1.3-7) experimental; urgency=LOW" in commitmsg)

        for file in ['foo/test1', 'foo/test2']:
            ok_(file in repo.ls_tree('HEAD'),
                "Could not find component tarball file %s in %s" % (file, repo.ls_tree('HEAD')))

        ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))

        dsc = DscFile.parse(dscfile)
        # Check if we can rebuild the tarball and component
        ptars = [('hello-debhelper_2.8.orig.tar.gz', 'pristine-tar', '', dsc.tgz),
                 ('hello-debhelper_2.8.orig-foo.tar.gz', 'pristine-tar^', 'foo', dsc.additional_tarballs['foo'])]

        p = DebianPristineTar(repo)
        outdir = os.path.abspath('.')
        for f, w, s, o in ptars:
            eq_(repo.get_subject(w), 'pristine-tar data for %s' % f)
            old = self.hash_file(o)
            p.checkout('hello-debhelper', '2.8', 'gzip', outdir, component=s)
            new = self.hash_file(os.path.join(outdir, f))
            eq_(old, new, "Checksum %s of regenerated tarball %s does not match original %s" %
                (f, old, new))
    def test_import_multiple_pristine_tar(self):
        """Test if importing a multiple tarball package works"""

        def _dsc(version):
            return os.path.join(DEB_TEST_DATA_DIR, "dsc-3.0-additional-tarballs", "hello-debhelper_%s.dsc" % version)

        dscfile = _dsc("2.8-1")
        assert (
            import_dsc(
                ["arg0", "--verbose", "--pristine-tar", "--debian-branch=master", "--upstream-branch=upstream", dscfile]
            )
            == 0
        )
        repo = ComponentTestGitRepository("hello-debhelper")
        self._check_repo_state(repo, "master", ["master", "pristine-tar", "upstream"])
        commits, expected = len(repo.get_commits()), 2

        for file in ["foo/test1", "foo/test2"]:
            ok_(
                file in repo.ls_tree("HEAD"),
                "Could not find component tarball file %s in %s" % (file, repo.ls_tree("HEAD")),
            )

        ok_(commits == expected, "Found %d commit instead of %d" % (commits, expected))

        dsc = DscFile.parse(dscfile)
        # Check if we can rebuild the tarball and subtarball
        ptars = [
            ("hello-debhelper_2.8.orig.tar.gz", "pristine-tar", "", dsc.tgz),
            ("hello-debhelper_2.8.orig-foo.tar.gz", "pristine-tar^", "foo", dsc.additional_tarballs["foo"]),
        ]

        p = DebianPristineTar(repo)
        outdir = os.path.abspath(".")
        for f, w, s, o in ptars:
            eq_(repo.get_subject(w), "pristine-tar data for %s" % f)
            old = self._hash_file(o)
            p.checkout("hello-debhelper", "2.8", "gzip", outdir, subtarball=s)
            new = self._hash_file(os.path.join(outdir, f))
            eq_(old, new, "Checksum %s of regenerated tarball %s does not match original %s" % (f, old, new))
Beispiel #9
0
def main(argv):
    dirs = dict(top=os.path.abspath(os.curdir))
    needs_repo = False
    ret = 0
    skipped = False

    options, pkg, target = parse_all(argv)
    if not options:
        return ExitCodes.parse_error

    try:
        try:
            repo = DebianGitRepository('.')
            is_empty = repo.is_empty()

            (clean, out) = repo.is_clean()
            if not clean and not is_empty:
                gbp.log.err("Repository has uncommitted changes, commit these first: ")
                raise GbpError(out)
        except GitRepositoryError:
            # no repo found, create one
            needs_repo = True
            is_empty = True

        if options.download:
            dsc = download_source(pkg,
                                  dirs=dirs,
                                  unauth=options.allow_unauthenticated)
        else:
            dsc = pkg

        src = DscFile.parse(dsc)
        if src.pkgformat not in ['1.0', '3.0']:
            raise GbpError("Importing %s source format not yet supported." % src.pkgformat)
        if options.verbose:
            print_dsc(src)

        if needs_repo:
            target = target or src.pkg
            if os.path.exists(target):
                raise GbpError("Directory '%s' already exists. If you want to import into it, "
                               "please change into this directory otherwise move it away first."
                               % target)
            gbp.log.info("No git repository found, creating one.")
            repo = DebianGitRepository.create(target)
            os.chdir(repo.path)
            repo_setup.set_user_name_and_email(options.repo_user, options.repo_email, repo)

        if repo.bare:
            disable_pristine_tar(options, "Bare repository")

        dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='..'))
        upstream = DebianUpstreamSource(src.tgz)
        upstream.unpack(dirs['tmp'], options.filters)
        for (component, tarball) in src.additional_tarballs.items():
            gbp.log.info("Found component tarball '%s'" % os.path.basename(tarball))
            unpack_component_tarball(upstream.unpacked, component, tarball, options.filters)

        format = [(options.upstream_tag, "Upstream"), (options.debian_tag, "Debian")][src.native]
        tag = repo.version_to_tag(format[0], src.upstream_version)
        msg = "%s version %s" % (format[1], src.upstream_version)

        if repo.find_version(options.debian_tag, src.version):
            gbp.log.warn("Version %s already imported." % src.version)
            if options.allow_same_version:
                gbp.log.info("Moving tag of version '%s' since import forced" % src.version)
                move_tag_stamp(repo, options.debian_tag, src.version)
            else:
                raise SkipImport

        if not repo.find_version(format[0], src.upstream_version):
            gbp.log.info("Tag %s not found, importing %s tarball" % (tag, format[1]))
            if is_empty:
                branch = None
            else:
                branch = [options.upstream_branch,
                          options.debian_branch][src.native]
                if not repo.has_branch(branch):
                    if options.create_missing_branches:
                        gbp.log.info("Creating missing branch '%s'" % branch)
                        repo.create_branch(branch)
                    else:
                        gbp.log.err(no_upstream_branch_msg % branch +
                                    "\nAlso check the --create-missing-branches option.")
                        raise GbpError

            if src.native:
                author = get_author_from_changelog(upstream.unpacked)
                committer = get_committer_from_author(author, options)
                commit_msg = "Import %s\n%s" % (msg, get_changes(upstream.unpacked,
                                                                 repo,
                                                                 is_empty,
                                                                 options.debian_branch))
            else:
                author = committer = {}
                commit_msg = "Import %s" % msg

            commit = repo.commit_dir(upstream.unpacked,
                                     commit_msg,
                                     branch,
                                     author=author,
                                     committer=committer)

            if not (src.native and options.skip_debian_tag):
                repo.create_tag(name=tag,
                                msg=msg,
                                commit=commit,
                                sign=options.sign_tags,
                                keyid=options.keyid)
            if not src.native:
                if is_empty:
                    repo.create_branch(options.upstream_branch, commit)
                if options.pristine_tar:
                    repo.create_pristinetar_commits(options.upstream_branch,
                                                    src.tgz,
                                                    src.additional_tarballs.items())
            if (not repo.has_branch(options.debian_branch) and
                    (is_empty or options.create_missing_branches)):
                repo.create_branch(options.debian_branch, commit)
        if not src.native:
            if src.diff or src.deb_tgz:
                apply_debian_patch(repo, upstream.unpacked, src, options,
                                   tag, is_empty)
            else:
                gbp.log.warn("Didn't find a diff to apply.")
        if repo.get_branch() == options.debian_branch or is_empty:
            # Update HEAD if we modified the checked out branch
            repo.force_head(options.debian_branch, hard=True)
    except KeyboardInterrupt:
        ret = 1
        gbp.log.err("Interrupted. Aborting.")
    except gbpc.CommandExecFailed:
        ret = 1
    except GitRepositoryError as msg:
        gbp.log.err("Git command failed: %s" % msg)
        ret = 1
    except GbpError as err:
        if str(err):
            gbp.log.err(err)
        ret = 1
    except SkipImport:
        skipped = True
    finally:
        os.chdir(dirs['top'])

    for d in ['tmp', 'download']:
        if d in dirs:
            gbpc.RemoveTree(dirs[d])()

    if not ret and not skipped:
        gbp.log.info("Version '%s' imported under '%s'" % (src.version, repo.path))
    return ret
def main(argv):
    dirs = dict(top=os.path.abspath(os.curdir))
    dscs = []
    ret = 0
    verbose = False
    dsc_key = cmp_to_key(DscCompareVersions())
    use_debsnap = False

    try:
        import_args = argv[1:]

        if '--verbose' in import_args:
            verbose = True
        gbp.log.setup(False, verbose)

        if '--ignore-repo-config' in import_args:
            set_gbp_conf_files()
            import_args.remove('--ignore-repo-config')
        # Not using Configparser since we want to pass all unknown options
        # unaltered to gbp import-dsc
        if '--debsnap' in import_args:
            use_debsnap = True
            import_args.remove('--debsnap')
            if import_args == []:
                print_help()
                raise GbpError
            pkg = import_args[-1]
            import_args = import_args[:-1]
        else:
            for arg in argv[::-1]:
                if arg.endswith('.dsc'):
                    dscs.append(DscFile.parse(arg))
                    import_args.remove(arg)

        if not use_debsnap and not dscs:
            print_help()
            raise GbpError

        if use_debsnap:
            dirs['tmp'] = os.path.abspath(tempfile.mkdtemp())
            dscs = [DscFile.parse(f) for f in fetch_snapshots(pkg, dirs['tmp'])]

        dscs.sort(key=dsc_key)
        importer = GitImportDsc(import_args)

        try:
            repo = GitRepository('.')
            (clean, out) = repo.is_clean()
            if not clean:
                gbp.log.err("Repository has uncommitted changes, "
                            "commit these first: ")
                raise GbpError(out)
            else:
                dirs['pkg'] = dirs['top']
        except GitRepositoryError:
            # no git repository there yet
            dirs['pkg'] = os.path.join(dirs['top'], dscs[0].pkg)

        if importer.importdsc(dscs[0]):
            raise GbpError("Failed to import '%s'" % dscs[0].dscfile)
        os.chdir(dirs['pkg'])

        for dsc in dscs[1:]:
            if importer.importdsc(dsc):
                raise GbpError("Failed to import '%s'" % dscs[0].dscfile)
    except KeyboardInterrupt:
        ret = 1
        gbp.log.err("Interrupted. Aborting.")
    except (GbpError, gbpc.CommandExecFailed, GitRepositoryError) as err:
        if str(err):
            gbp.log.err(err)
        ret = 1
    finally:
        if 'tmp' in dirs:
            gbpc.RemoveTree(dirs['tmp'])()
        os.chdir(dirs['top'])

    if not ret:
        gbp.log.info('Everything imported under %s' % dirs['pkg'])
    return ret
Beispiel #11
0
 def _import_one(cls, dsc, opts):
     opts = opts or []
     assert import_dsc(['arg0'] + opts + [dsc]) == 0
     parsed = DscFile(dsc)
     return ComponentTestGitRepository(parsed.pkg)
Beispiel #12
0
def main(argv):
    dirs = dict(top=os.path.abspath(os.curdir))
    needs_repo = False
    ret = 1
    skipped = False

    options, pkg, target = parse_all(argv)
    if not options:
        return ExitCodes.parse_error

    try:
        try:
            repo = DebianGitRepository('.')
            # remember if the was repo initially empty
            repo.empty = repo.is_empty()

            (clean, out) = repo.is_clean()
            if not clean and not repo.empty:
                raise GbpError(
                    "Repository has uncommitted changes, commit these first: %s"
                    % out)
        except GitRepositoryError:
            # no repo found, create one
            needs_repo = True

        if options.download:
            dscfile = download_source(pkg,
                                      dirs=dirs,
                                      unauth=options.allow_unauthenticated)
        else:
            dscfile = pkg

        dsc = DscFile.parse(dscfile)
        if dsc.pkgformat not in ['1.0', '3.0']:
            raise GbpError("Importing %s source format not yet supported." %
                           dsc.pkgformat)
        if options.verbose:
            print_dsc(dsc)

        if needs_repo:
            target = target or dsc.pkg
            if os.path.exists(target):
                raise GbpError(
                    "Directory '%s' already exists. If you want to import into it, "
                    "please change into this directory otherwise move it away first."
                    % target)
            gbp.log.info("No git repository found, creating one.")
            repo = DebianGitRepository.create(target)
            repo.empty = True
            os.chdir(repo.path)
            repo_setup.set_user_name_and_email(options.repo_user,
                                               options.repo_email, repo)

        if repo.bare:
            disable_pristine_tar(options, "Bare repository")

        # unpack
        dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='..'))
        source = DebianUpstreamSource(dsc.tgz)
        source.unpack(dirs['tmp'], options.filters)
        for (component, tarball) in dsc.additional_tarballs.items():
            gbp.log.info("Found component tarball '%s'" %
                         os.path.basename(tarball))
            unpack_component_tarball(source.unpacked, component, tarball,
                                     options.filters)

        if repo.find_version(options.debian_tag, dsc.version):
            gbp.log.warn("Version %s already imported." % dsc.version)
            if options.allow_same_version:
                gbp.log.info("Moving tag of version '%s' since import forced" %
                             dsc.version)
                move_tag_stamp(repo, options.debian_tag, dsc.version)
            else:
                raise SkipImport

        # import
        if dsc.native:
            import_native(repo, source, dsc, options)
        else:
            imported = False
            commit = repo.find_version(options.upstream_tag,
                                       dsc.upstream_version)
            if not repo.find_version(options.upstream_tag,
                                     dsc.upstream_version):
                commit = import_upstream(repo, source, dsc, options)
                imported = True

            if not repo.has_branch(options.debian_branch):
                if options.create_missing_branches:
                    repo.create_branch(options.debian_branch, commit)
                else:
                    raise GbpError(
                        "Branch %s does not exist, use --create-missing-branches"
                        % options.debian_branch)

            if dsc.diff or dsc.deb_tgz:
                apply_debian_patch(repo, source, dsc, commit, options)
            else:
                gbp.log.warn("Didn't find a diff to apply.")

            if imported and options.pristine_tar:
                repo.create_pristine_tar_commits(
                    commit, dsc.tgz, dsc.additional_tarballs.items())

        if repo.get_branch() == options.debian_branch or repo.empty:
            # Update HEAD if we modified the checked out branch
            repo.force_head(options.debian_branch, hard=True)
        ret = 0
    except KeyboardInterrupt:
        gbp.log.err("Interrupted. Aborting.")
    except gbpc.CommandExecFailed:
        pass  # command itself printed an error
    except GitRepositoryError as msg:
        gbp.log.err("Git command failed: %s" % msg)
    except GbpError as err:
        if str(err):
            gbp.log.err(err)
    except SkipImport:
        skipped = True
        ret = 0
    finally:
        os.chdir(dirs['top'])
        for d in ['tmp', 'download']:
            if d in dirs:
                gbpc.RemoveTree(dirs[d])()

    if not ret and not skipped:
        gbp.log.info("Version '%s' imported under '%s'" %
                     (dsc.version, repo.path))
    return ret
Beispiel #13
0
    def test_update_component_tarballs(self, repo):
        """
        Test importing new version with additional tarballs works
        """
        # Import 2.8
        orig = self._orig('2.8', dir='dsc-3.0-additional-tarballs')
        ok_(
            import_orig([
                'arg0', '--component=foo', '--no-interactive',
                '--pristine-tar', orig
            ]) == 0)
        self._check_repo_state(
            repo,
            'master', ['master', 'upstream', 'pristine-tar'],
            tags=['debian/2.6-2', 'upstream/2.6', 'upstream/2.8'])
        self._check_component_tarballs(repo, [b'foo/test1', b'foo/test2'])
        ok_(os.path.exists('debian/changelog'))

        dsc = DscFile.parse(
            _dsc_file(self.pkg, '2.8-1', dir='dsc-3.0-additional-tarballs'))
        # Check if we can rebuild the upstream tarball and additional tarball
        ptars = [('hello-debhelper_2.8.orig.tar.gz', 'pristine-tar', '',
                  dsc.tgz),
                 ('hello-debhelper_2.8.orig-foo.tar.gz', 'pristine-tar^',
                  'foo', dsc.additional_tarballs['foo'])]

        p = DebianPristineTar(repo)
        outdir = os.path.abspath('.')
        for f, w, s, o in ptars:
            eq_(repo.get_subject(w), 'pristine-tar data for %s' % f)
            old = self.hash_file(o)
            p.checkout('hello-debhelper', '2.8', 'gzip', outdir, component=s)
            out = os.path.join(outdir, f)
            new = self.hash_file(out)
            eq_(
                old, new,
                "Checksum %s of regenerated tarball %s does not match original %s"
                % (f, old, new))
            os.unlink(out)

        # Import 2.9
        orig = self._orig('2.9', dir='dsc-3.0-additional-tarballs')
        ok_(
            import_orig([
                'arg0', '--component=foo', '--no-interactive',
                '--pristine-tar', orig
            ]) == 0)
        self._check_repo_state(repo,
                               'master',
                               ['master', 'upstream', 'pristine-tar'],
                               tags=[
                                   'debian/2.6-2', 'upstream/2.6',
                                   'upstream/2.8', 'upstream/2.9'
                               ])
        self._check_component_tarballs(repo,
                                       ['foo/test1', 'foo/test2', 'foo/test3'])
        ok_(os.path.exists('debian/changelog'))

        dsc = DscFile.parse(
            _dsc_file(self.pkg, '2.9-1', dir='dsc-3.0-additional-tarballs'))
        # Check if we can rebuild the upstream tarball and additional tarball
        ptars = [('hello-debhelper_2.9.orig.tar.gz', 'pristine-tar', '',
                  dsc.tgz),
                 ('hello-debhelper_2.9.orig-foo.tar.gz', 'pristine-tar^',
                  'foo', dsc.additional_tarballs['foo'])]

        p = DebianPristineTar(repo)
        outdir = os.path.abspath('.')
        for f, w, s, o in ptars:
            eq_(repo.get_subject(w), 'pristine-tar data for %s' % f)
            old = self.hash_file(o)
            p.checkout('hello-debhelper', '2.9', 'gzip', outdir, component=s)
            new = self.hash_file(os.path.join(outdir, f))
            eq_(
                old, new,
                "Checksum %s of regenerated tarball %s does not match original %s"
                % (f, old, new))
Beispiel #14
0
 def test_dscfile_parse(self):
     """Test parsing a valid dsc file"""
     dsc = DscFile.parse(self.dscfile.name)
     self.assertEqual(dsc.version, '0.9.12-4')
def main(argv):
    dirs = dict(top=os.path.abspath(os.curdir))
    needs_repo = False
    ret = 0
    skipped = False

    options, args = parse_args(argv)
    if not options:
        return 1

    try:
        if len(args) != 1:
            gbp.log.err(
                "Need to give exactly one package to import. Try --help.")
            raise GbpError
        else:
            try:
                repo = DebianGitRepository('.')
                is_empty = repo.is_empty()

                (clean, out) = repo.is_clean()
                if not clean and not is_empty:
                    gbp.log.err(
                        "Repository has uncommitted changes, commit these first: "
                    )
                    raise GbpError(out)
            except GitRepositoryError:
                # no repo found, create one
                needs_repo = True
                is_empty = True

            pkg = args[0]
            if options.download:
                dsc = download_source(pkg,
                                      dirs=dirs,
                                      unauth=options.allow_unauthenticated)
            else:
                dsc = pkg

            src = DscFile.parse(dsc)
            if src.pkgformat not in ['1.0', '3.0']:
                raise GbpError(
                    "Importing %s source format not yet supported." %
                    src.pkgformat)
            if options.verbose:
                print_dsc(src)

            if needs_repo:
                if os.path.exists(src.pkg):
                    raise GbpError(
                        "Directory '%s' already exists. If you want to import into it, "
                        "please change into this directory otherwise move it away first."
                        % src.pkg)
                gbp.log.info("No git repository found, creating one.")
                repo = DebianGitRepository.create(src.pkg)
                os.chdir(repo.path)

            if repo.bare:
                disable_pristine_tar(options, "Bare repository")

            dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='..'))
            upstream = DebianUpstreamSource(src.tgz)
            upstream.unpack(dirs['tmp'], options.filters)
            for tarball in src.additional_tarballs.values():
                gbp.log.info("Found component tarball '%s'" %
                             os.path.basename(tarball))
                subtarball = DebianUpstreamSource(tarball)
                subtarball.unpack(upstream.unpacked, options.filters)

            format = [(options.upstream_tag, "Upstream"),
                      (options.debian_tag, "Debian")][src.native]
            tag = repo.version_to_tag(format[0], src.upstream_version)
            msg = "%s version %s" % (format[1], src.upstream_version)

            if repo.find_version(options.debian_tag, src.version):
                gbp.log.warn("Version %s already imported." % src.version)
                if options.allow_same_version:
                    gbp.log.info(
                        "Moving tag of version '%s' since import forced" %
                        src.version)
                    move_tag_stamp(repo, options.debian_tag, src.version)
                else:
                    raise SkipImport

            if not repo.find_version(format[0], src.upstream_version):
                gbp.log.info("Tag %s not found, importing %s tarball" %
                             (tag, format[1]))
                if is_empty:
                    branch = None
                else:
                    branch = [options.upstream_branch,
                              options.debian_branch][src.native]
                    if not repo.has_branch(branch):
                        if options.create_missing_branches:
                            gbp.log.info("Creating missing branch '%s'" %
                                         branch)
                            repo.create_branch(branch)
                        else:
                            gbp.log.err(
                                no_upstream_branch_msg % branch +
                                "\nAlso check the --create-missing-branches option."
                            )
                            raise GbpError

                if src.native:
                    author = get_author_from_changelog(upstream.unpacked)
                    committer = get_committer_from_author(author, options)
                else:
                    author = committer = {}

                commit = repo.commit_dir(upstream.unpacked,
                                         "Imported %s" % msg,
                                         branch,
                                         author=author,
                                         committer=committer)

                if not (src.native and options.skip_debian_tag):
                    repo.create_tag(name=tag,
                                    msg=msg,
                                    commit=commit,
                                    sign=options.sign_tags,
                                    keyid=options.keyid)
                if not src.native:
                    if is_empty:
                        repo.create_branch(options.upstream_branch, commit)
                    if options.pristine_tar:
                        generate_pristine_tarballs(repo, src,
                                                   options.upstream_branch)
                if (not repo.has_branch(options.debian_branch)
                        and (is_empty or options.create_missing_branches)):
                    repo.create_branch(options.debian_branch, commit)
            if not src.native:
                if src.diff or src.deb_tgz:
                    apply_debian_patch(repo, upstream.unpacked, src, options,
                                       tag)
                else:
                    gbp.log.warn("Didn't find a diff to apply.")
            if repo.get_branch() == options.debian_branch or is_empty:
                # Update HEAD if we modified the checked out branch
                repo.force_head(options.debian_branch, hard=True)
    except KeyboardInterrupt:
        ret = 1
        gbp.log.err("Interrupted. Aborting.")
    except gbpc.CommandExecFailed:
        ret = 1
    except GitRepositoryError as msg:
        gbp.log.err("Git command failed: %s" % msg)
        ret = 1
    except GbpError as err:
        if str(err):
            gbp.log.err(err)
        ret = 1
    except SkipImport:
        skipped = True
    finally:
        os.chdir(dirs['top'])

    for d in ['tmp', 'download']:
        if d in dirs:
            gbpc.RemoveTree(dirs[d])()

    if not ret and not skipped:
        gbp.log.info("Version '%s' imported under '%s'" %
                     (src.version, src.pkg))
    return ret
Beispiel #16
0
def main(argv):
    dirs = dict(top=os.path.abspath(os.curdir))
    dscs = []
    ret = 0
    verbose = False
    dsc_key = cmp_to_key(DscCompareVersions())
    use_debsnap = False

    try:
        import_args = argv[1:]

        if '--verbose' in import_args:
            verbose = True
        gbp.log.setup(False, verbose)

        if '--ignore-repo-config' in import_args:
            set_gbp_conf_files()
            import_args.remove('--ignore-repo-config')
        # Not using Configparser since we want to pass all unknown options
        # unaltered to gbp import-dsc
        if '--debsnap' in import_args:
            use_debsnap = True
            import_args.remove('--debsnap')
            if import_args == []:
                print_help()
                raise GbpError
            pkg = import_args[-1]
            import_args = import_args[:-1]
        else:
            for arg in argv[::-1]:
                if arg.endswith('.dsc'):
                    dscs.append(DscFile.parse(arg))
                    import_args.remove(arg)

        if not use_debsnap and not dscs:
            print_help()
            raise GbpError

        if use_debsnap:
            dirs['tmp'] = os.path.abspath(tempfile.mkdtemp())
            dscs = [
                DscFile.parse(f) for f in fetch_snapshots(pkg, dirs['tmp'])
            ]

        dscs.sort(key=dsc_key)
        importer = GitImportDsc(import_args)

        try:
            repo = GitRepository('.')
            (clean, out) = repo.is_clean()
            if not clean:
                gbp.log.err("Repository has uncommitted changes, "
                            "commit these first: ")
                raise GbpError(out)
            else:
                dirs['pkg'] = dirs['top']
        except GitRepositoryError:
            # no git repository there yet
            dirs['pkg'] = os.path.join(dirs['top'], dscs[0].pkg)

        if importer.importdsc(dscs[0]):
            raise GbpError("Failed to import '%s'" % dscs[0].dscfile)
        os.chdir(dirs['pkg'])

        for dsc in dscs[1:]:
            if importer.importdsc(dsc):
                raise GbpError("Failed to import '%s'" % dscs[0].dscfile)
    except KeyboardInterrupt:
        ret = 1
        gbp.log.err("Interrupted. Aborting.")
    except (GbpError, gbpc.CommandExecFailed, GitRepositoryError) as err:
        if str(err):
            gbp.log.err(err)
        ret = 1
    finally:
        if 'tmp' in dirs:
            gbpc.RemoveTree(dirs['tmp'])()
        os.chdir(dirs['top'])

    if not ret:
        gbp.log.info('Everything imported under %s' % dirs['pkg'])
    return ret
Beispiel #17
0
def main(argv):
    dirs = dict(top=os.path.abspath(os.curdir))
    needs_repo = False
    ret = 1
    skipped = False

    options, pkg, target = parse_all(argv)
    if not options:
        return ExitCodes.parse_error

    try:
        try:
            repo = DebianGitRepository('.')
            # remember if the was repo initially empty
            repo.empty = repo.is_empty()

            (clean, out) = repo.is_clean()
            if not clean and not repo.empty:
                raise GbpError("Repository has uncommitted changes, commit these first: %s" % out)
        except GitRepositoryError:
            # no repo found, create one
            needs_repo = True

        if options.download:
            dscfile = download_source(pkg,
                                      dirs=dirs,
                                      unauth=options.allow_unauthenticated)
        else:
            dscfile = pkg

        dsc = DscFile.parse(dscfile)
        if dsc.pkgformat not in ['1.0', '3.0']:
            raise GbpError("Importing %s source format not yet supported." % dsc.pkgformat)
        if options.verbose:
            print_dsc(dsc)

        if needs_repo:
            target = target or dsc.pkg
            if os.path.exists(target):
                raise GbpError("Directory '%s' already exists. If you want to import into it, "
                               "please change into this directory otherwise move it away first."
                               % target)
            gbp.log.info("No git repository found, creating one.")
            repo = DebianGitRepository.create(target)
            repo.empty = True
            os.chdir(repo.path)
            repo_setup.set_user_name_and_email(options.repo_user, options.repo_email, repo)

        if repo.bare:
            disable_pristine_tar(options, "Bare repository")

        # unpack
        dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='..'))
        source = DebianUpstreamSource(dsc.tgz)
        source.unpack(dirs['tmp'], options.filters)
        for (component, tarball) in dsc.additional_tarballs.items():
            gbp.log.info("Found component tarball '%s'" % os.path.basename(tarball))
            unpack_component_tarball(source.unpacked, component, tarball, options.filters)

        if repo.find_version(options.debian_tag, dsc.version):
            gbp.log.warn("Version %s already imported." % dsc.version)
            if options.allow_same_version:
                gbp.log.info("Moving tag of version '%s' since import forced" % dsc.version)
                move_tag_stamp(repo, options.debian_tag, dsc.version)
            else:
                raise SkipImport

        # import
        if dsc.native:
            import_native(repo, source, dsc, options)
        else:
            imported = False
            commit = repo.find_version(options.upstream_tag, dsc.upstream_version)
            if not repo.find_version(options.upstream_tag, dsc.upstream_version):
                commit = import_upstream(repo, source, dsc, options)
                imported = True

            if not repo.has_branch(options.debian_branch):
                if options.create_missing_branches:
                    repo.create_branch(options.debian_branch, commit)
                else:
                    raise GbpError("Branch %s does not exist, use --create-missing-branches" %
                                   options.debian_branch)

            if dsc.diff or dsc.deb_tgz:
                apply_debian_patch(repo, source, dsc, commit, options)
            else:
                gbp.log.warn("Didn't find a diff to apply.")

            if imported and options.pristine_tar:
                repo.create_pristine_tar_commits(commit,
                                                 dsc.tgz,
                                                 dsc.additional_tarballs.items())

        if repo.get_branch() == options.debian_branch or repo.empty:
            # Update HEAD if we modified the checked out branch
            repo.force_head(options.debian_branch, hard=True)
        ret = 0
    except KeyboardInterrupt:
        gbp.log.err("Interrupted. Aborting.")
    except gbpc.CommandExecFailed:
        pass  # command itself printed an error
    except GitRepositoryError as msg:
        gbp.log.err("Git command failed: %s" % msg)
        debug_exc(options)
    except GbpError as err:
        if str(err):
            gbp.log.err(err)
        debug_exc(options)
    except SkipImport:
        skipped = True
        ret = 0
    finally:
        os.chdir(dirs['top'])
        for d in ['tmp', 'download']:
            if d in dirs:
                gbpc.RemoveTree(dirs[d])()

    if not ret and not skipped:
        gbp.log.info("Version '%s' imported under '%s'" % (dsc.version, repo.path))
    return ret
Beispiel #18
0
def main(argv):
    dirs = dict(top=os.path.abspath(os.curdir))
    needs_repo = False
    ret = 0
    skipped = False

    options, args = parse_args(argv)
    if not options:
        return 1

    try:
        if len(args) != 1:
            gbp.log.err("Need to give exactly one package to import. Try --help.")
            raise GbpError
        else:
            pkg = args[0]
            if options.download:
                dsc = download_source(pkg,
                                      dirs=dirs,
                                      unauth=options.allow_unauthenticated,
                                      no_default_keyrings=options.no_default_keyrings,
                                      keyrings=options.keyring)
            else:
                dsc = pkg

            src = DscFile.parse(dsc)
            if src.pkgformat not in [ '1.0', '3.0' ]:
                raise GbpError("Importing %s source format not yet supported." % src.pkgformat)
            if options.verbose:
                print_dsc(src)

            try:
                repo = DebianGitRepository('.')
                is_empty = repo.is_empty()

                (clean, out) = repo.is_clean()
                if not clean and not is_empty:
                    gbp.log.err("Repository has uncommitted changes, commit these first: ")
                    raise GbpError(out)

            except GitRepositoryError:
                # no repo found, create one
                needs_repo = True
                is_empty = True

            if needs_repo:
                gbp.log.info("No git repository found, creating one.")
                repo = DebianGitRepository.create(src.pkg)
                os.chdir(repo.path)

            if repo.bare:
                set_bare_repo_options(options)

            dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='..'))
            upstream = DebianUpstreamSource(src.tgz)
            upstream.unpack(dirs['tmp'], options.filters)

            format = [(options.upstream_tag, "Upstream"), (options.debian_tag, "Debian")][src.native]
            tag = repo.version_to_tag(format[0], src.upstream_version)
            msg = "%s version %s" % (format[1], src.upstream_version)

            if repo.find_version(options.debian_tag, src.version):
                 gbp.log.warn("Version %s already imported." % src.version)
                 if options.allow_same_version:
                    gbp.log.info("Moving tag of version '%s' since import forced" % src.version)
                    move_tag_stamp(repo, options.debian_tag, src.version)
                 else:
                    raise SkipImport

            if not repo.find_version(format[0], src.upstream_version):
                gbp.log.info("Tag %s not found, importing %s tarball" % (tag, format[1]))
                if is_empty:
                    branch = None
                else:
                    branch = [options.upstream_branch,
                              options.debian_branch][src.native]
                    if not repo.has_branch(branch):
                        if options.create_missing_branches:
                            gbp.log.info("Creating missing branch '%s'" % branch)
                            repo.create_branch(branch)
                        else:
                            gbp.log.err(no_upstream_branch_msg % branch +
                                        "\nAlso check the --create-missing-branches option.")
                            raise GbpError

                if src.native:
                    author = get_author_from_changelog(upstream.unpacked)
                    committer = get_committer_from_author(author, options)
                else:
                    author = committer = {}

                commit = repo.commit_dir(upstream.unpacked,
                                         "Imported %s" % msg,
                                         branch,
                                         author=author,
                                         committer=committer)

                if not (src.native and options.skip_debian_tag):
                    repo.create_tag(name=tag,
                                    msg=msg,
                                    commit=commit,
                                    sign=options.sign_tags,
                                    keyid=options.keyid)
                if not src.native:
                    if is_empty:
                        repo.create_branch(options.upstream_branch, commit)
                    if options.pristine_tar:
                        repo.pristine_tar.commit(src.tgz, options.upstream_branch)
                if (not repo.has_branch(options.debian_branch)
                    and (is_empty or options.create_missing_branches)):
                    repo.create_branch(options.debian_branch, commit)
            if not src.native:
                if src.diff or src.deb_tgz:
                    apply_debian_patch(repo, upstream.unpacked, src, options,
                                       tag)
                else:
                    gbp.log.warn("Didn't find a diff to apply.")
            if repo.get_branch() == options.debian_branch or is_empty:
                # Update HEAD if we modified the checked out branch
                repo.force_head(options.debian_branch, hard=True)
    except KeyboardInterrupt:
        ret = 1
        gbp.log.err("Interrupted. Aborting.")
    except gbpc.CommandExecFailed:
        ret = 1
    except GitRepositoryError as msg:
        gbp.log.err("Git command failed: %s" % msg)
        ret = 1
    except GbpError as err:
        if str(err):
            gbp.log.err(err)
        ret = 1
    except SkipImport:
        skipped = True
    finally:
        os.chdir(dirs['top'])

    for d in [ 'tmp', 'download' ]:
        if d in dirs:
            gbpc.RemoveTree(dirs[d])()

    if not ret and not skipped:
        gbp.log.info("Version '%s' imported under '%s'" % (src.version, src.pkg))
    return ret
Beispiel #19
0
 def test_dscfile_parse(self):
     """Test parsing a valid dsc file"""
     dsc = DscFile.parse(self.dscfile.name)
     self.assertEqual(dsc.version, '0.9.12-4')