summaryrefslogtreecommitdiff
path: root/gbp
diff options
context:
space:
mode:
authorSoonKyu Park <sk7.park@samsung.com>2016-07-25 20:53:31 +0900
committerSoonKyu Park <sk7.park@samsung.com>2016-07-25 20:53:31 +0900
commit77958da8a32b9f39356684e05842579a74c4a46f (patch)
treeb4babcbfce543e21abfa2fb09049d546cb049481 /gbp
parent31a52b28de3581b2859fd020a0d221d54d8e57f7 (diff)
parent06e10c8b1f4f355e884d52a61b7762e733975d55 (diff)
downloadgit-buildpackage-devel_psk_20160727.tar.gz
git-buildpackage-devel_psk_20160727.tar.bz2
git-buildpackage-devel_psk_20160727.zip
Handle conflicts from git merge masterdevel_psk_20160727
Change-Id: I9dfa02fb546a04f97aade855615ad2843790a2c1
Diffstat (limited to 'gbp')
-rw-r--r--gbp/config.py44
-rw-r--r--gbp/pkg/__init__.py75
-rw-r--r--gbp/rpm/__init__.py66
-rw-r--r--gbp/rpm/git.py4
-rw-r--r--gbp/rpm/lib_rpm.py1
-rwxr-xr-xgbp/scripts/buildpackage_rpm.py15
-rw-r--r--gbp/scripts/common/buildpackage.py2
-rw-r--r--gbp/scripts/common/import_orig.py105
-rw-r--r--gbp/scripts/import_orig.py5
-rwxr-xr-xgbp/scripts/import_srpm.py112
-rwxr-xr-xgbp/scripts/pq_rpm.py33
-rwxr-xr-xgbp/scripts/rpm_ch.py2
12 files changed, 182 insertions, 282 deletions
diff --git a/gbp/config.py b/gbp/config.py
index 987be05d..267400ce 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -584,7 +584,6 @@ class GbpOptionParserDebian(GbpOptionParser):
'export-dir' : '',
} )
-
class GbpOptionParserRpm(GbpOptionParser):
"""
Handles commandline options and parsing of config files for rpm tools
@@ -592,19 +591,21 @@ class GbpOptionParserRpm(GbpOptionParser):
defaults = dict(GbpOptionParser.defaults)
defaults.update({
'tmp-dir' : '/var/tmp/gbp/',
- 'vendor' : 'Downstream',
- 'packaging-branch' : 'master',
- 'packaging-dir' : '',
- 'packaging-tag' : 'packaging/%(version)s',
+ 'vendor' : 'vendor',
+ 'native' : 'auto',
+ 'builder' : 'rpmbuild',
+ 'cleaner' : '/bin/true',
+ 'merge' : 'False',
+ 'packaging-dir' : '',
+ 'packaging-branch' : 'master',
+ 'packaging-tag' : '%(vendor)s/%(version)s',
'upstream-tag' : 'upstream/%(upstreamversion)s',
'pq-branch' : 'development/%(branch)s',
'import-files' : ['.gbp.conf',
'debian/gbp.conf'],
'spec-file' : 'auto',
- 'builder' : 'rpmbuild',
- 'cleaner' : '/bin/true',
+
'export-dir' : '../rpmbuild',
- 'native' : 'auto',
'ignore-untracked' : 'False',
'rpmbuild-builddir' : 'BUILD',
'rpmbuild-rpmdir' : 'RPMS',
@@ -613,14 +614,15 @@ class GbpOptionParserRpm(GbpOptionParser):
'rpmbuild-srpmdir' : 'SRPMS',
'rpmbuild-buildrootdir' : 'BUILDROOT',
'patch-export' : 'False',
+ 'patch-export-ignore-path' : '',
'patch-export-compress' : '0',
- 'patch-export-ignore-path' : '',
'patch-export-squash-until' : '',
+ 'pristine-tarball-name' : 'auto',
+ 'orig-prefix' : 'auto',
'patch-import' : 'True',
'spec-vcs-tag' : '',
- 'merge' : 'False',
- 'pristine-tarball-name' : 'auto',
- 'orig-prefix' : 'auto',
+
+
'changelog-file' : 'auto',
'changelog-revision' : '',
'spawn-editor' : 'always',
@@ -630,24 +632,22 @@ class GbpOptionParserRpm(GbpOptionParser):
help = dict(GbpOptionParser.help)
help.update({
- 'tmp-dir':
- "Base directory under which temporary directories are "
- "created, default is '%(tmp-dir)s'",
+
'vendor':
"Distribution vendor name, default is '%(vendor)s'",
+ 'native':
+ "Treat this package as native, default is '%(native)s'",
'packaging-branch':
"Branch the packaging is being maintained on, rpm counterpart "
"of the 'debian-branch' option, default is "
"'%(packaging-branch)s'",
'packaging-dir':
- "Subdir for RPM packaging files, default is "
- "'%(packaging-dir)s'",
+ "Subdir for RPM packaging files, default is '%(packaging-dir)s'",
'packaging-tag':
"Format string for packaging tags, RPM counterpart of the "
"'debian-tag' option, default is '%(packaging-tag)s'",
'pq-branch':
- "format string for the patch-queue branch name, default is "
- "'%(pq-branch)s'",
+ "format string for the patch-queue branch name, default is '%(pq-branch)s'",
'import-files':
"Comma-separated list of additional file(s) to import from "
"packaging branch. These will appear as one monolithic patch "
@@ -656,8 +656,7 @@ class GbpOptionParserRpm(GbpOptionParser):
"Spec file to use, 'auto' makes gbp to guess, other values "
"make the packaging-dir option to be ignored, default is "
"'%(spec-file)s'",
- 'native':
- "Treat this package as native, default is '%(native)s'",
+
'ignore-untracked':
"build with untracked files in the source tree, default is "
"'%(ignore-untracked)s'",
@@ -700,6 +699,9 @@ class GbpOptionParserRpm(GbpOptionParser):
"default is '%(git-author)s'",
'meta-bts':
"Meta tags for the bts commands, default is '%(meta-bts)s'",
+ 'tmp-dir':
+ "Base directory under which temporary directories are "
+ "created, default is '%(tmp-dir)s'",
})
class GbpOptionParserBB(GbpOptionParserRpm):
diff --git a/gbp/pkg/__init__.py b/gbp/pkg/__init__.py
index 4e99efe9..8162286b 100644
--- a/gbp/pkg/__init__.py
+++ b/gbp/pkg/__init__.py
@@ -142,67 +142,6 @@ class PkgPolicy(object):
return True
return False
- @classmethod
- def guess_upstream_src_version(cls, filename, extra_regex=r''):
- """
- Guess the package name and version from the filename of an upstream
- archive.
-
- @param filename: filename (archive or directory) from which to guess
- @type filename: C{string}
- @param extra_regex: additional regex to apply, needs a 'package' and a
- 'version' group
- @return: (package name, version) or ('', '')
- @rtype: tuple
-
- >>> PkgPolicy.guess_upstream_src_version('foo-bar_0.2.orig.tar.gz')
- ('foo-bar', '0.2')
- >>> PkgPolicy.guess_upstream_src_version('foo-Bar_0.2.orig.tar.gz')
- ('foo-Bar', '0.2.orig')
- >>> PkgPolicy.guess_upstream_src_version('git-bar-0.2.tar.gz')
- ('git-bar', '0.2')
- >>> PkgPolicy.guess_upstream_src_version('git-bar-0.2-rc1.tar.gz')
- ('git-bar', '0.2-rc1')
- >>> PkgPolicy.guess_upstream_src_version('git-bar-0.2:~-rc1.tar.gz')
- ('git-bar', '0.2:~-rc1')
- >>> PkgPolicy.guess_upstream_src_version('git-Bar-0A2d:rc1.tar.bz2')
- ('git-Bar', '0A2d:rc1')
- >>> PkgPolicy.guess_upstream_src_version('git-1.tar.bz2')
- ('git', '1')
- >>> PkgPolicy.guess_upstream_src_version('kvm_87+dfsg.orig.tar.gz')
- ('kvm', '87+dfsg')
- >>> PkgPolicy.guess_upstream_src_version('foo-Bar-a.b.tar.gz')
- ('', '')
- >>> PkgPolicy.guess_upstream_src_version('foo-bar_0.2.orig.tar.xz')
- ('foo-bar', '0.2')
- >>> PkgPolicy.guess_upstream_src_version('foo-bar_0.2.tar.gz')
- ('foo-bar', '0.2')
- >>> PkgPolicy.guess_upstream_src_version('foo-bar_0.2.orig.tar.lzma')
- ('foo-bar', '0.2')
- >>> PkgPolicy.guess_upstream_src_version('foo-bar-0.2.zip')
- ('foo-bar', '0.2')
- >>> PkgPolicy.guess_upstream_src_version('foo-bar-0.2.tlz')
- ('foo-bar', '0.2')
- """
- version_chars = r'[a-zA-Z\d\.\~\-\:\+]'
- basename = parse_archive_filename(os.path.basename(filename))[0]
-
- version_filters = map ( lambda x: x % version_chars,
- ( # Debian upstream tarball: package_'<version>.orig.tar.gz'
- r'^(?P<package>[a-z\d\.\+\-]+)_(?P<version>%s+)\.orig',
- # Upstream 'package-<version>.tar.gz'
- # or Debian native 'package_<version>.tar.gz'
- # or directory 'package-<version>':
- r'^(?P<package>[a-zA-Z\d\.\+\-]+)(-|_)(?P<version>[0-9]%s*)'))
- if extra_regex:
- version_filters = extra_regex + version_filters
-
- for filter in version_filters:
- m = re.match(filter, basename)
- if m:
- return (m.group('package'), m.group('version'))
- return ('', '')
-
@staticmethod
def guess_upstream_src_version(filename, extra_regex=r''):
"""
@@ -441,11 +380,25 @@ class UpstreamSource(object):
@property
def archive_fmt(self):
"""Archive format of the sources, e.g. 'tar'"""
+ """
+ >>> UpstreamSource('foo/bar.tar.gz').archive_fmt
+ 'tar'
+ >>> UpstreamSource('foo.bar.zip').archive_fmt
+ 'zip'
+ >>> UpstreamSource('foo.bar.baz').archive_fmt
+ """
return self._archive_fmt
@property
def compression(self):
"""Compression format of the sources, e.g. 'gzip'"""
+ """
+ >>> UpstreamSource('foo/bar.tar.gz').compression
+ 'gzip'
+ >>> UpstreamSource('foo.bar.zip').compression
+ >>> UpstreamSource('foo.bz2').compression
+ 'bzip2'
+ """
return self._compression
@property
diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py
index 22983d2d..d5fa1ee8 100644
--- a/gbp/rpm/__init__.py
+++ b/gbp/rpm/__init__.py
@@ -901,70 +901,4 @@ def string_to_int(val_str):
else:
return int(val_str)
-
-def split_version_str(version):
- """
- Parse full version string and split it into individual "version
- components", i.e. upstreamversion, epoch and release
-
- @param version: full version of a package
- @type version: C{str}
- @return: individual version components
- @rtype: C{dict}
-
- >>> split_version_str("1")
- {'release': None, 'epoch': None, 'upstreamversion': '1'}
- >>> split_version_str("1.2.3-5.3")
- {'release': '5.3', 'epoch': None, 'upstreamversion': '1.2.3'}
- >>> split_version_str("3:1.2.3")
- {'release': None, 'epoch': '3', 'upstreamversion': '1.2.3'}
- >>> split_version_str("3:1-0")
- {'release': '0', 'epoch': '3', 'upstreamversion': '1'}
- """
- ret = {'epoch': None, 'upstreamversion': None, 'release': None}
-
- e_vr = version.split(":", 1)
- if len(e_vr) == 1:
- v_r = e_vr[0].split("-", 1)
- else:
- ret['epoch'] = e_vr[0]
- v_r = e_vr[1].split("-", 1)
- ret['upstreamversion'] = v_r[0]
- if len(v_r) > 1:
- ret['release'] = v_r[1]
-
- return ret
-
-def compose_version_str(evr):
- """
- Compose a full version string from individual "version components",
- i.e. epoch, version and release
-
- @param evr: dict of version components
- @type evr: C{dict} of C{str}
- @return: full version
- @rtype: C{str}
-
- >>> compose_version_str({'epoch': '', 'upstreamversion': '1.0'})
- '1.0'
- >>> compose_version_str({'epoch': '2', 'upstreamversion': '1.0', 'release': None})
- '2:1.0'
- >>> compose_version_str({'epoch': None, 'upstreamversion': '1', 'release': '0'})
- '1-0'
- >>> compose_version_str({'epoch': '2', 'upstreamversion': '1.0', 'release': '2.3'})
- '2:1.0-2.3'
- >>> compose_version_str({'epoch': '2', 'upstreamversion': '', 'release': '2.3'})
- """
- if 'upstreamversion' in evr and evr['upstreamversion']:
- version = ""
- if 'epoch' in evr and evr['epoch']:
- version += "%s:" % evr['epoch']
- version += evr['upstreamversion']
- if 'release' in evr and evr['release']:
- version += "-%s" % evr['release']
- if version:
- return version
- return None
-
-
# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
diff --git a/gbp/rpm/git.py b/gbp/rpm/git.py
index c7cc023b..92f8b2e0 100644
--- a/gbp/rpm/git.py
+++ b/gbp/rpm/git.py
@@ -19,7 +19,7 @@ import re
from gbp.git import GitRepository, GitRepositoryError
from gbp.pkg.pristinetar import PristineTar
-from gbp.rpm import compose_version_str
+from gbp.rpm.policy import RpmPkgPolicy
class RpmGitRepository(GitRepository):
"""A git repository that holds the source of an RPM package"""
@@ -66,7 +66,7 @@ class RpmGitRepository(GitRepository):
'myvendor/v1.0-2'
"""
version_tag = format % dict(str_fields,
- version=compose_version_str(str_fields))
+ version=RpmPkgPolicy.compose_full_version(str_fields))
return RpmGitRepository._sanitize_tag(version_tag)
@staticmethod
diff --git a/gbp/rpm/lib_rpm.py b/gbp/rpm/lib_rpm.py
index 4bad44e7..da914207 100644
--- a/gbp/rpm/lib_rpm.py
+++ b/gbp/rpm/lib_rpm.py
@@ -25,6 +25,7 @@ try:
# Try to load special RPM lib to be used for GBP (only)
librpm = __import__(RpmPkgPolicy.python_rpmlib_module_name)
except ImportError:
+ gbp.log.getLogger("gbp")
gbp.log.warn("Failed to import '%s' as rpm python module, using host's "
"default rpm library instead" %
RpmPkgPolicy.python_rpmlib_module_name)
diff --git a/gbp/scripts/buildpackage_rpm.py b/gbp/scripts/buildpackage_rpm.py
index f5468401..8fb0b2a4 100755
--- a/gbp/scripts/buildpackage_rpm.py
+++ b/gbp/scripts/buildpackage_rpm.py
@@ -137,10 +137,10 @@ def pristine_tar_build_orig(repo, orig_file, output_dir, options):
raise
return False
-def get_upstream_tree(repo, version, options):
+def get_upstream_tree(repo, spec, options):
"""Determine the upstream tree from the given options"""
if options.upstream_tree.upper() == 'TAG':
- tag_str_fields = {"upstreamversion": version, "vendor": "Upstream"}
+ tag_str_fields = dict(upstreamversion=spec.upstreamversion, vendor="Upstream")
upstream_tree = repo.version_to_tag(options.upstream_tag, tag_str_fields)
elif options.upstream_tree.upper() == 'BRANCH':
if not repo.has_branch(options.upstream_branch):
@@ -257,7 +257,7 @@ def git_archive_build_orig(repo, spec, output_dir, options):
@rtype: C{str}
"""
try:
- upstream_tree = get_upstream_tree(repo, spec.upstreamversion, options)
+ upstream_tree = get_upstream_tree(repo, spec, options)
gbp.log.info("%s does not exist, creating from '%s'" % \
(spec.orig_src['filename'], upstream_tree))
if spec.orig_src['compression']:
@@ -279,7 +279,7 @@ def export_patches(repo, spec, export_treeish, options):
Generate patches and update spec file
"""
try:
- upstream_tree = get_upstream_tree(repo, spec.upstreamversion, options)
+ upstream_tree = get_upstream_tree(repo, spec, options)
update_patch_series(repo, spec, upstream_tree, export_treeish, options)
except (GitRepositoryError, GbpError) as err:
raise GbpAutoGenerateError(str(err))
@@ -353,9 +353,9 @@ def update_tag_str_fields(fields, tag_format_str, repo, commit_info):
break
-def packaging_tag_name(repo, version, commit_info, options):
+def packaging_tag_name(repo, spec, commit_info, options):
"""Compose packaging tag as string"""
- tag_str_fields = dict(version, vendor=options.vendor)
+ tag_str_fields = dict(spec.version, vendor=options.vendor)
update_tag_str_fields(tag_str_fields, options.packaging_tag, repo,
commit_info)
return repo.version_to_tag(options.packaging_tag, tag_str_fields)
@@ -667,7 +667,7 @@ def main(argv):
if options.tag or options.tag_only:
gbp.log.info("Tagging %s" % RpmPkgPolicy.compose_full_version(spec.version))
commit_info = repo.get_commit_info(tree)
- tag = packaging_tag_name(repo, spec.version, commit_info, options)
+ tag = packaging_tag_name(repo, spec, commit_info, options)
if options.retag and repo.has_tag(tag):
repo.delete_tag(tag)
create_packaging_tag(repo, tag, commit=tree, version=spec.version,
@@ -708,6 +708,7 @@ def main(argv):
if not options.tag_only:
if spec and options.notify:
summary = "Gbp-rpm %s" % ["failed", "successful"][not retval]
+ pkg_evr = {'upstreamversion': spec.version}
message = ("Build of %s %s %s" % (spec.name,
RpmPkgPolicy.compose_full_version(spec.version),
["failed", "succeeded"][not retval]))
diff --git a/gbp/scripts/common/buildpackage.py b/gbp/scripts/common/buildpackage.py
index 670f6823..d089df5a 100644
--- a/gbp/scripts/common/buildpackage.py
+++ b/gbp/scripts/common/buildpackage.py
@@ -73,7 +73,6 @@ def compress(cmd, options, output, input_data=None):
except (OSError, IOError) as err:
raise GbpError("Error creating %s: %s" % (output, err))
-
def git_archive_submodules(repo, treeish, output, tmpdir_base, prefix,
comp_type, comp_level, comp_opts, format='tar'):
"""
@@ -143,7 +142,6 @@ def untar_data(outdir, data):
if popen.wait():
raise GbpError("Error extracting tar to %s" % outdir)
-
#{ Functions to handle export-dir
def dump_tree(repo, export_dir, treeish, with_submodules, recursive=True):
"""Dump a git tree-ish to output_dir"""
diff --git a/gbp/scripts/common/import_orig.py b/gbp/scripts/common/import_orig.py
index adbfff5e..16244423 100644
--- a/gbp/scripts/common/import_orig.py
+++ b/gbp/scripts/common/import_orig.py
@@ -78,59 +78,6 @@ def ask_package_version(default, ver_validator_func, err_msg):
# bit clearer.
gbp.log.warn("\nNot a valid upstream version: '%s'.\n%s" % (version, err_msg))
-
-def prepare_pristine_tar(source, pkg_name, pkg_version, pristine_commit_name,
- filters=None, prefix=None, tmpdir=None):
- """
- Prepare the upstream sources for pristine-tar import
-
- @param source: original upstream sources
- @type source: C{UpstreamSource}
- @param pkg_name: package name
- @type pkg_name: C{str}
- @param pkg_version: upstream version of the package
- @type pkg_version: C{str}
- @param pristine_commit_name: archive filename to commit to pristine-tar
- @type pristine_commit_name: C{str} or C{None}
- @param filters: filter to exclude files
- @type filters: C{list} of C{str} or C{None}
- @param prefix: prefix (i.e. leading directory of files) to use in
- pristine-tar, set to C{None} to not mangle orig archive
- @type prefix: C{str} or C{None}
- @param tmpdir: temporary working dir (cleanup left to caller)
- @type tmpdir: C{str}
- @return: prepared source archive
- @rtype: C{UpstreamSource}
- """
- need_repack = False
- if source.is_dir():
- if prefix is None:
- prefix = '%s-%s' % (pkg_name, pkg_version)
- gbp.log.info("Using guessed prefix '%s/' for pristine-tar" % prefix)
- need_repack = True
- else:
- if prefix is not None and prefix == source.prefix:
- prefix = None
- comp = parse_archive_filename(pristine_commit_name)[2]
- if filters or prefix is not None or source.compression != comp:
- if not source.unpacked:
- unpack_dir = tempfile.mkdtemp(prefix='pristine_unpack_',
- dir=tmpdir)
- source.unpack(unpack_dir)
- need_repack = True
- pristine_path = os.path.join(tmpdir, pristine_commit_name)
- if need_repack:
- gbp.log.debug("Packing '%s' from '%s' for pristine-tar" %
- (pristine_path, source.unpacked))
- pristine = source.pack(pristine_path, filters, prefix)
- else:
- # Just create symlink for mangling the pristine tarball name
- os.symlink(source.path, pristine_path)
- pristine = source.__class__(pristine_path)
-
- return pristine
-
-
def prepare_sources(source, pkg_name, pkg_version, pristine_commit_name,
filters, filter_pristine, prefix, tmpdir):
"""
@@ -201,3 +148,55 @@ def prepare_sources(source, pkg_name, pkg_version, pristine_commit_name,
pristine_path = pristine.path if pristine else ''
return (filtered.unpacked, pristine_path)
+def prepare_pristine_tar(source, pkg_name, pkg_version, pristine_commit_name,
+ filters=None, prefix=None, tmpdir=None):
+ """
+ Prepare the upstream sources for pristine-tar import
+
+ @param source: original upstream sources
+ @type source: C{UpstreamSource}
+ @param pkg_name: package name
+ @type pkg_name: C{str}
+ @param pkg_version: upstream version of the package
+ @type pkg_version: C{str}
+ @param pristine_commit_name: archive filename to commit to pristine-tar
+ @type pristine_commit_name: C{str} or C{None}
+ @param filters: filter to exclude files
+ @type filters: C{list} of C{str} or C{None}
+ @param prefix: prefix (i.e. leading directory of files) to use in
+ pristine-tar, set to C{None} to not mangle orig archive
+ @type prefix: C{str} or C{None}
+ @param tmpdir: temporary working dir (cleanup left to caller)
+ @type tmpdir: C{str}
+ @return: prepared source archive
+ @rtype: C{UpstreamSource}
+ """
+ need_repack = False
+ if source.is_dir():
+ if prefix is None:
+ prefix = '%s-%s' % (pkg_name, pkg_version)
+ gbp.log.info("Using guessed prefix '%s/' for pristine-tar" % prefix)
+ need_repack = True
+ else:
+ if prefix is not None and prefix == source.prefix:
+ prefix = None
+ comp = parse_archive_filename(pristine_commit_name)[2]
+ if filters or prefix is not None or source.compression != comp:
+ if not source.unpacked:
+ unpack_dir = tempfile.mkdtemp(prefix='pristine_unpack_',
+ dir=tmpdir)
+ source.unpack(unpack_dir)
+ need_repack = True
+ pristine_path = os.path.join(tmpdir, pristine_commit_name)
+ if need_repack:
+ gbp.log.debug("Packing '%s' from '%s' for pristine-tar" %
+ (pristine_path, source.unpacked))
+ pristine = source.pack(pristine_path, filters, prefix)
+ else:
+ # Just create symlink for mangling the pristine tarball name
+ os.symlink(source.path, pristine_path)
+ pristine = source.__class__(pristine_path)
+
+ return pristine
+
+
diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py
index be857e35..56b1d9dc 100644
--- a/gbp/scripts/import_orig.py
+++ b/gbp/scripts/import_orig.py
@@ -33,9 +33,8 @@ from gbp.format import format_msg
import gbp.log
from gbp.pkg import compressor_opts
from gbp.scripts.common.import_orig import (cleanup_tmp_tree, ask_package_name,
- ask_package_version,
- prepare_sources)
-
+ ask_package_version,
+ prepare_sources)
def upstream_import_commit_msg(options, version):
return options.import_msg % dict(version=version)
diff --git a/gbp/scripts/import_srpm.py b/gbp/scripts/import_srpm.py
index ff946194..85f1225f 100755
--- a/gbp/scripts/import_srpm.py
+++ b/gbp/scripts/import_srpm.py
@@ -30,7 +30,8 @@ import urllib2
import gbp.tmpfile as tempfile
import gbp.command_wrappers as gbpc
from gbp.rpm import (parse_srpm, guess_spec, SpecFile, NoSpecError,
- RpmUpstreamSource, compose_version_str)
+ RpmUpstreamSource)
+from gbp.rpm.policy import RpmPkgPolicy
from gbp.rpm.git import (RpmGitRepository, GitRepositoryError)
from gbp.git.modifier import GitModifier
from gbp.config import (GbpOptionParserRpm, GbpOptionGroup,
@@ -42,8 +43,9 @@ from gbp.scripts.common.pq import apply_and_commit_patch
from gbp.pkg import parse_archive_filename
no_packaging_branch_msg = """
-Repository does not have branch '%s' for packaging/distribution sources.
-You need to reate it or use --packaging-branch to specify it.
+Repository does not have branch '%s' for packaging/distribution sources. If there is none see
+file:///usr/share/doc/git-buildpackage/manual-html/gbp.import.html#GBP.IMPORT.CONVERT
+on howto create it otherwise use --packaging-branch to specify it.
"""
PATCH_AUTODELETE_COMMIT_MSG = """
@@ -160,7 +162,6 @@ def import_spec_patches(repo, spec, dirs):
def force_to_branch_head(repo, branch):
- """Checkout branch and reset --hard"""
if repo.get_branch() == branch:
# Update HEAD if we modified the checked out branch
repo.force_head(branch, hard=True)
@@ -196,10 +197,10 @@ def parse_args(argv):
parser.add_config_file_option(option_name="color-scheme",
dest="color_scheme")
parser.add_config_file_option(option_name="tmp-dir", dest="tmp_dir")
- parser.add_config_file_option(option_name="vendor", action="store",
- dest="vendor")
parser.add_option("--download", action="store_true", dest="download",
default=False, help="download source package")
+ parser.add_config_file_option(option_name="vendor", action="store",
+ dest="vendor")
branch_group.add_config_file_option(option_name="packaging-branch",
dest="packaging_branch")
branch_group.add_config_file_option(option_name="upstream-branch",
@@ -354,22 +355,22 @@ def main(argv):
# Unpack orig source archive
if spec.orig_src:
orig_tarball = os.path.join(dirs['src'], spec.orig_src['filename'])
- sources = RpmUpstreamSource(orig_tarball)
- sources = sources.unpack(dirs['origsrc'], options.filters)
+ upstream = RpmUpstreamSource(orig_tarball)
+ upstream = upstream.unpack(dirs['origsrc'], options.filters)
else:
- sources = None
+ upstream = None
- src_tag_format = options.packaging_tag if options.native \
- else options.upstream_tag
- tag_str_fields = dict(spec.version, vendor=options.vendor.lower())
- src_tag = repo.version_to_tag(src_tag_format, tag_str_fields)
- ver_str = compose_version_str(spec.version)
+ tag_format = [(options.upstream_tag, "Upstream"),
+ (options.packaging_tag, options.vendor)][options.native]
+ tag_str_fields = dict(spec.version, vendor=options.vendor)
+ tag = repo.version_to_tag(tag_format[0], tag_str_fields)
if repo.find_version(options.packaging_tag, tag_str_fields):
- gbp.log.warn("Version %s already imported." % ver_str)
+ gbp.log.warn("Version %s already imported." %
+ RpmPkgPolicy.compose_full_version(spec.version))
if options.allow_same_version:
gbp.log.info("Moving tag of version '%s' since import forced" %
- ver_str)
+ RpmPkgPolicy.compose_full_version(spec.version))
move_tag_stamp(repo, options.packaging_tag, tag_str_fields)
else:
raise SkipImport
@@ -378,10 +379,10 @@ def main(argv):
options.create_missing_branches = True
# Determine author and committer info, currently same info is used
- # for both sources and packaging files
+ # for both upstream sources and packaging files
author = None
if spec.packager:
- match = re.match(r'(?P<name>.*[^ ])\s*<(?P<email>\S*)>',
+ match = re.match('(?P<name>.*[^ ])\s*<(?P<email>\S*)>',
spec.packager.strip())
if match:
author = GitModifier(match.group('name'), match.group('email'))
@@ -390,11 +391,12 @@ def main(argv):
gbp.log.debug("Couldn't determine packager info")
committer = committer_from_author(author, options)
- # Import sources
- if sources:
- src_commit = repo.find_version(src_tag_format, tag_str_fields)
- if not src_commit:
- gbp.log.info("Tag %s not found, importing sources" % src_tag)
+ # Import upstream sources
+ if upstream:
+ upstream_commit = repo.find_version(tag_format[0], tag_str_fields)
+ if not upstream_commit:
+ gbp.log.info("Tag %s not found, importing %s upstream sources"
+ % (tag, tag_format[1]))
branch = [options.upstream_branch,
options.packaging_branch][options.native]
@@ -406,22 +408,22 @@ def main(argv):
gbp.log.err(no_upstream_branch_msg % branch + "\n"
"Also check the --create-missing-branches option.")
raise GbpError
- src_vendor = "Native" if options.native else "Upstream"
- msg = "%s version %s" % (src_vendor, spec.upstreamversion)
+
+ msg = "%s version %s" % (tag_format[1], spec.upstreamversion)
if options.vcs_tag:
parents = [repo.rev_parse("%s^{}" % options.vcs_tag)]
else:
parents = None
- src_commit = repo.commit_dir(sources.unpacked,
- "Imported %s" % msg,
- branch,
- other_parents=parents,
- author=author,
- committer=committer,
- create_missing_branch=options.create_missing_branches)
- repo.create_tag(name=src_tag,
+ upstream_commit = repo.commit_dir(upstream.unpacked,
+ "Imported %s" % msg,
+ branch,
+ other_parents=parents,
+ author=author,
+ committer=committer,
+ create_missing_branch=options.create_missing_branches)
+ repo.create_tag(name=tag,
msg=msg,
- commit=src_commit,
+ commit=upstream_commit,
sign=options.sign_tags,
keyid=options.keyid)
@@ -440,7 +442,7 @@ def main(argv):
# Import packaging files. For native packages we assume that also
# packaging files are found in the source tarball
- if not options.native or not sources:
+ if not options.native or not upstream:
gbp.log.info("Importing packaging files")
branch = options.packaging_branch
if not repo.has_branch(branch):
@@ -452,35 +454,37 @@ def main(argv):
"option.")
raise GbpError
+ tag_str_fields = dict(spec.version, vendor=options.vendor)
tag = repo.version_to_tag(options.packaging_tag, tag_str_fields)
- msg = "%s release %s" % (options.vendor, ver_str)
+ msg = "%s release %s" % (options.vendor,
+ RpmPkgPolicy.compose_full_version(spec.version))
- if options.orphan_packaging or not sources:
+ if options.orphan_packaging or not upstream:
commit = repo.commit_dir(dirs['packaging_base'],
- "Imported %s" % msg,
- branch,
- author=author,
- committer=committer,
- create_missing_branch=options.create_missing_branches)
+ "Imported %s" % msg,
+ branch,
+ author=author,
+ committer=committer,
+ create_missing_branch=options.create_missing_branches)
else:
# Copy packaging files to the unpacked sources dir
try:
- pkgsubdir = os.path.join(sources.unpacked,
+ pkgsubdir = os.path.join(upstream.unpacked,
options.packaging_dir)
os.mkdir(pkgsubdir)
except OSError as err:
if err.errno != errno.EEXIST:
raise
- for fname in os.listdir(dirs['packaging']):
- shutil.copy2(os.path.join(dirs['packaging'], fname),
+ for fn in os.listdir(dirs['packaging']):
+ shutil.copy2(os.path.join(dirs['packaging'], fn),
pkgsubdir)
- commit = repo.commit_dir(sources.unpacked,
- "Imported %s" % msg,
- branch,
- other_parents=[src_commit],
- author=author,
- committer=committer,
- create_missing_branch=options.create_missing_branches)
+ commit = repo.commit_dir(upstream.unpacked,
+ "Imported %s" % msg,
+ branch,
+ other_parents=[upstream_commit],
+ author=author,
+ committer=committer,
+ create_missing_branch=options.create_missing_branches)
# Import patches on top of the source tree
# (only for non-native packages with non-orphan packaging)
force_to_branch_head(repo, options.packaging_branch)
@@ -524,7 +528,9 @@ def main(argv):
gbpc.RemoveTree(dirs['tmp_base'])()
if not ret and not skipped:
- gbp.log.info("Version '%s' imported under '%s'" % (ver_str, spec.name))
+ gbp.log.info("Version '%s' imported under '%s'" %
+ (RpmPkgPolicy.compose_full_version(spec.version),
+ spec.name))
return ret
if __name__ == '__main__':
diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py
index d8fcbf2f..32ffadee 100755
--- a/gbp/scripts/pq_rpm.py
+++ b/gbp/scripts/pq_rpm.py
@@ -26,12 +26,12 @@ import sys
import re
import gzip
import bz2
+import tarfile
import subprocess
-
import gbp.tmpfile as tempfile
from gbp.config import GbpOptionParserRpm
from gbp.rpm.git import GitRepositoryError, RpmGitRepository
-from gbp.git.modifier import GitModifier
+from gbp.git.modifier import GitModifier, GitTz
from gbp.command_wrappers import GitCommand, CommandExecFailed
from gbp.errors import GbpError
import gbp.log
@@ -243,13 +243,14 @@ def parse_spec(options, repo, treeish=None):
return spec
-def find_upstream_commit(repo, upstreamversion, upstream_tag):
+def find_upstream_commit(repo, spec, upstream_tag):
"""Find commit corresponding upstream version"""
- tag_str_fields = {'upstreamversion': upstreamversion,
+ tag_str_fields = {'upstreamversion': spec.upstreamversion,
'vendor': 'Upstream'}
upstream_commit = repo.find_version(upstream_tag, tag_str_fields)
if not upstream_commit:
- raise GbpError("Couldn't find upstream version %s" % upstreamversion)
+ raise GbpError("Couldn't find upstream version %s" %
+ spec.upstreamversion)
return upstream_commit
@@ -265,10 +266,11 @@ def export_patches(repo, options):
else:
spec = parse_spec(options, repo)
pq_branch = pq_branch_name(current, options, spec.version)
- upstream_commit = find_upstream_commit(repo, spec.upstreamversion,
- options.upstream_tag)
+ upstream_commit = find_upstream_commit(repo, spec, options.upstream_tag)
export_treeish = options.export_rev if options.export_rev else pq_branch
+ if not repo.has_treeish(export_treeish):
+ raise GbpError('Invalid treeish object %s' % export_treeish)
update_patch_series(repo, spec, upstream_commit, export_treeish, options)
@@ -299,6 +301,9 @@ def safe_patches(queue, tmpdir_base):
gbp.log.debug("Uncompressing '%s'" % os.path.basename(patch.path))
src = uncompressors[comp](patch.path, 'r')
dst_name = os.path.join(tmpdir, os.path.basename(base))
+ if _archive_fmt:
+ tar_name = dst_name
+ dst_name += '.tar'
elif comp:
raise GbpError("Unsupported patch compression '%s', giving up"
% comp)
@@ -310,6 +315,11 @@ def safe_patches(queue, tmpdir_base):
dst.writelines(src)
src.close()
dst.close()
+ if _archive_fmt:
+ t = tarfile.open(dst_name, 'r:')
+ t.extractall(path = tmpdir)
+ t.close()
+ dst_name = tar_name
safequeue.append(patch)
safequeue[-1].path = dst_name
@@ -377,8 +387,7 @@ def import_spec_patches(repo, options):
spec = parse_spec(options, repo)
spec_treeish = None
base = current
- upstream_commit = find_upstream_commit(repo, spec.upstreamversion,
- options.upstream_tag)
+ upstream_commit = find_upstream_commit(repo, spec, options.upstream_tag)
packager = get_packager(spec)
pq_branch = pq_branch_name(base, options, spec.version)
@@ -435,8 +444,7 @@ def rebase_pq(repo, options):
else:
base = current
spec = parse_spec(options, repo)
- upstream_commit = find_upstream_commit(repo, spec.upstreamversion,
- options.upstream_tag)
+ upstream_commit = find_upstream_commit(repo, spec, options.upstream_tag)
switch_to_pq_branch(repo, base, options)
GitCommand("rebase")([upstream_commit])
@@ -502,8 +510,7 @@ def convert_package(repo, options):
pq_branch = pq_branch_name(old_packaging, options, spec.version)
raise GbpError(err_msg_base + "pq branch %s already exists" % pq_branch)
# Check that the current branch is based on upstream
- upstream_commit = find_upstream_commit(repo, spec.upstreamversion,
- options.upstream_tag)
+ upstream_commit = find_upstream_commit(repo, spec, options.upstream_tag)
if not is_ancestor(repo, upstream_commit, old_packaging):
raise GbpError(err_msg_base + "%s is not based on upstream version %s" %
(old_packaging, spec.upstreamversion))
diff --git a/gbp/scripts/rpm_ch.py b/gbp/scripts/rpm_ch.py
index 5bbf6155..33058372 100755
--- a/gbp/scripts/rpm_ch.py
+++ b/gbp/scripts/rpm_ch.py
@@ -330,7 +330,7 @@ def update_changelog(changelog, entries, repo, spec, options):
# Get fake information for the to-be-created git commit
commit_info = {'author': GitModifier(date=now),
'committer': GitModifier(date=now)}
- tag = packaging_tag_name(repo, spec.version, commit_info, options)
+ tag = packaging_tag_name(repo, spec, commit_info, options)
else:
commit_info = {'author': None, 'committer': None}
tag = repo.describe('HEAD', longfmt=True, always=True)