def test_directory(self): """Upstream source is a directory""" source = UpstreamSource(self.upstream_dir) self.assertEqual(source.is_orig(), False) self.assertEqual(source.path, self.upstream_dir) self.assertEqual(source.unpacked, self.upstream_dir) self.assertEqual(source.guess_version(), ('test', '1.0'))
def test_unpack(self): source = UpstreamSource(self.zipfile) self.assertEqual(source.is_orig(), False) self.assertEqual(source.is_dir(), False) self.assertEqual(source.unpacked, None) source.unpack(str(self.tmpdir)) self.assertNotEqual(source.unpacked, None)
def test_dir(self): """Basic test for unpacked sources, no filtering etc""" tmpdir = tempfile.mkdtemp(dir=self._tmpdir, prefix='dir_basic_') source = UpstreamSource(self._origs['dir']) orig, prist = prepare_sources(source, 'test', '1.0', None, None, False, None, tmpdir) self.assertEqual(ls_dir(self._origs['dir']), ls_dir(orig)) self.assertEqual(prist, '')
def test_pack_mangle_prefix(self): """Check if mangling prefix works""" source = UpstreamSource(os.path.abspath("gbp/")) target = self.tmpdir.join("gbp_0.1.tar.bz2") repacked = source.pack(target, newprefix="foobar") self._check_tar(repacked, ["foobar/errors.py", "foobar/__init__.py"]) repacked2 = source.pack(target, newprefix="") self._check_tar(repacked2, ["./errors.py", "./__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.unpacked, None) self.assertEqual(source.guess_version(), ('gbp', '0.1')) source.unpack(str(self.tmpdir)) self.assertNotEqual(source.unpacked, None)
def test_tar_pristine_prefix(self): """Test tarball import with prefix mangling""" tmpdir = tempfile.mkdtemp(dir=self._tmpdir, prefix='tar_prefix_') source = UpstreamSource(self._origs['tar']) _orig, prist = prepare_sources(source, 'test', '1.0', 'test.tgz', None, False, 'np', tmpdir) src_ls = ls_tar(self._origs['tar']) prist_ref = set([fname.replace('test-1.0', 'np') for fname in src_ls]) self.assertEqual(prist_ref, ls_tar(prist))
def test_dir_filter(self): """Test filtering of unpacked sources""" tmpdir = tempfile.mkdtemp(dir=self._tmpdir, prefix='dir_filter_') source = UpstreamSource(self._origs['dir']) orig, prist = prepare_sources(source, 'test', '1.0', None, ['pkg'], False, None, tmpdir) orig_filt_ref = set([ fname for fname in ls_dir(self._origs['dir']) if not fname.startswith('pkg') ]) self.assertEqual(orig_filt_ref, ls_dir(orig)) self.assertEqual(prist, '')
def test_unpack(self): source = UpstreamSource(self.zipfile) self.assertEqual(source.is_orig(), False) self.assertEqual(source.is_tarball(), False) self.assertEqual(source.is_dir(), False) self.assertEqual(source.unpacked, None) self.assertEqual(source.guess_version(), ('gbp', '0.1')) self.assertEqual(source.archive_fmt, 'zip') self.assertEqual(source.compression, None) self.assertEqual(source.prefix, 'gbp') source.unpack(str(self.tmpdir)) self.assertNotEqual(source.unpacked, None)
def test_tar(self): """Basic test for tarball sources, with pristine-tar""" tmpdir = tempfile.mkdtemp(dir=self._tmpdir, prefix='tar_basic_') source = UpstreamSource(self._origs['tar']) orig, prist = prepare_sources(source, 'test', '1.0', 'test.tgz', None, False, 'test-1.0', tmpdir) src_ls = ls_tar(self._origs['tar']) orig_ref = set([ fname.replace('test-1.0/', '') for fname in src_ls if fname != 'test-1.0' ]) self.assertEqual(orig_ref, ls_dir(orig)) self.assertEqual(src_ls, ls_tar(prist))
def test_dir_pristine_filter(self): """Test filtering pristine-tar and mangling prefix""" tmpdir = tempfile.mkdtemp(dir=self._tmpdir, prefix='dir_filter3_') source = UpstreamSource(self._origs['dir']) orig, prist = prepare_sources(source, 'test', '1.0', 'test.tar.gz', ['pkg'], True, 'newpref', tmpdir) src_ls = ls_dir(self._origs['dir']) orig_filt_ref = set( [fname for fname in src_ls if not fname.startswith('pkg')]) prist_ref = set(['newpref/%s' % fname for fname in orig_filt_ref] + ['newpref']) self.assertEqual(orig_filt_ref, ls_dir(orig)) self.assertEqual(prist_ref, ls_tar(prist))
def test_dir_pristine_nofilter(self): """Test filtering of unpacked sources, not filtering pristine-tar""" tmpdir = tempfile.mkdtemp(dir=self._tmpdir, prefix='dir_filter2_') source = UpstreamSource(self._origs['dir']) orig, prist = prepare_sources(source, 'test', '1.0', 'test.tar.gz', ['pkg'], False, None, tmpdir) src_ls = ls_dir(self._origs['dir']) orig_filt_ref = set( [fname for fname in src_ls if not fname.startswith('pkg')]) prist_ref = set(['test-1.0/%s' % fname for fname in src_ls] + ['test-1.0']) self.assertEqual(orig_filt_ref, ls_dir(orig)) self.assertEqual(prist_ref, ls_tar(prist))
def test_tar_filter_pristine_prefix(self): """Filter tarball, pristine-tar prefix mangling but not filter""" tmpdir = tempfile.mkdtemp(dir=self._tmpdir, prefix='tar_filter_') source = UpstreamSource(self._origs['tar']) orig, prist = prepare_sources(source, 'test', '1.0', 'test.tgz', ['pkg'], False, 'newp', tmpdir) src_ls = ls_tar(self._origs['tar']) orig_ref = set([ fname.replace('test-1.0/', '') for fname in src_ls if fname != 'test-1.0' and not fname.startswith('test-1.0/pkg') ]) prist_ref = set( [fname.replace('test-1.0', 'newp') for fname in src_ls]) self.assertEqual(orig_ref, ls_dir(orig)) self.assertEqual(prist_ref, ls_tar(prist))
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 = UpstreamSource(orig_tarball) upstream.unpack(dest_dir) # Check if tarball extracts into a single folder or not: 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)
def main(argv): dirs = dict(top=os.path.abspath(os.curdir)) needs_repo = False ret = 0 skipped = False parents = None 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) 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 = UpstreamSource(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 len(err.__str__()): gbp.log.err(err) ret = 1 except SkipImport: skipped = True finally: os.chdir(dirs['top']) for d in ['tmp', 'download']: if dirs.has_key(d): gbpc.RemoveTree(dirs[d])() if not ret and not skipped: gbp.log.info("Version '%s' imported under '%s'" % (src.version, src.pkg)) return ret
def setUp(self): self.tmpdir = context.new_tmpdir(__name__) self.source = UpstreamSource(os.path.join(context.projectdir, "gbp"))