aboutsummaryrefslogtreecommitdiffhomepage
path: root/gbp/scripts
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-11-25 15:51:52 +0100
committerGuido Günther <agx@sigxcpu.org>2011-11-28 22:29:48 +0100
commitc9a1595a666cc83f9e9e523f0b4f27502f61b998 (patch)
tree83334959f3559d8836d8caecc5db7205b795a3bf /gbp/scripts
parentf7a6b073a43e144d43550e92fc111d456c8bc973 (diff)
Add ChangeLog class
making it easier to query versions. Add tests.
Diffstat (limited to 'gbp/scripts')
-rw-r--r--gbp/scripts/buildpackage.py29
-rw-r--r--gbp/scripts/create_remote_repo.py6
-rw-r--r--gbp/scripts/dch.py11
-rw-r--r--gbp/scripts/import_dsc.py5
-rw-r--r--gbp/scripts/import_orig.py16
5 files changed, 34 insertions, 33 deletions
diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py
index 9e199376..91347fe2 100644
--- a/gbp/scripts/buildpackage.py
+++ b/gbp/scripts/buildpackage.py
@@ -31,6 +31,7 @@ from gbp.command_wrappers import (Command,
RunAtCommand, CommandExecFailed, PristineTar,
RemoveTree, CatenateTarArchive)
from gbp.config import (GbpOptionParser, GbpOptionGroup)
+from gbp.deb.changelog import ChangeLog, NoChangeLogError, ParseChangeLogError
from gbp.errors import GbpError
from glob import glob
import gbp.log
@@ -175,7 +176,7 @@ def export_source(repo, cp, options, dest_dir, tarball_dir):
# Extract orig tarball if git-overlay option is selected:
if options.overlay:
- if du.is_native(cp):
+ if cp.is_native():
raise GbpError, "Cannot overlay Debian native package"
extract_orig(os.path.join(tarball_dir, du.orig_file(cp, options.comp_type)), dest_dir)
@@ -504,16 +505,14 @@ def main(argv):
raise GbpError, "Use --git-ignore-branch to ignore or --git-debian-branch to set the branch name."
try:
- cp = du.parse_changelog(filename=changelog)
- version = cp['Version']
- version_no_epoch = cp['NoEpoch-Version']
- if du.is_native(cp):
+ cp = ChangeLog(filename=changelog)
+ if cp.is_native():
major = cp['Debian-Version']
else:
major = cp['Upstream-Version']
- except du.NoChangelogError:
+ except NoChangeLogError:
raise GbpError, "'%s' does not exist, not a debian package" % changelog
- except du.ParseChangeLogError, err:
+ except ParseChangeLogError, err:
raise GbpError, "Error parsing Changelog: %s" % err
except KeyError:
raise GbpError, "Can't parse version from changelog"
@@ -527,7 +526,7 @@ def main(argv):
# sources and create different tarballs (#640382)
# We don't delay it in general since we want to fail early if the
# tarball is missing.
- if not du.is_native(cp):
+ if not cp.is_native():
if options.postexport:
gbp.log.info("Postexport hook set, delaying tarball creation")
else:
@@ -545,14 +544,14 @@ def main(argv):
extra_env={'GBP_GIT_DIR': repo.git_dir,
'GBP_TMP_DIR': tmp_dir})(dir=tmp_dir)
- cp = du.parse_changelog(filename=os.path.join(tmp_dir, 'debian', 'changelog'))
+ cp = ChangeLog(filename=os.path.join(tmp_dir, 'debian', 'changelog'))
export_dir = os.path.join(output_dir, "%s-%s" % (cp['Source'], major))
gbp.log.info("Moving '%s' to '%s'" % (tmp_dir, export_dir))
move_old_export(export_dir)
os.rename(tmp_dir, export_dir)
# Delayed tarball creation in case a postexport hook is used:
- if not du.is_native(cp) and options.postexport:
+ if not cp.is_native() and options.postexport:
prepare_upstream_tarball(repo, cp, options, tarball_dir,
output_dir)
@@ -573,20 +572,20 @@ def main(argv):
if options.postbuild:
arch = os.getenv('ARCH', None) or du.get_arch()
changes = os.path.abspath("%s/../%s_%s_%s.changes" %
- (build_dir, cp['Source'], version_no_epoch, arch))
+ (build_dir, cp['Source'], cp.noepoch, arch))
gbp.log.debug("Looking for changes file %s" % changes)
if not os.path.exists(changes):
changes = os.path.abspath("%s/../%s_%s_source.changes" %
- (build_dir, cp['Source'], version_no_epoch))
+ (build_dir, cp['Source'], cp.noepoch))
Command(options.postbuild, shell=True,
extra_env={'GBP_CHANGES_FILE': changes,
'GBP_BUILD_DIR': build_dir})()
if options.tag or options.tag_only:
- gbp.log.info("Tagging %s" % version)
- tag = build_tag(options.debian_tag, version)
+ gbp.log.info("Tagging %s" % cp.version)
+ tag = build_tag(options.debian_tag, cp.version)
if options.retag and repo.has_tag(tag):
repo.delete_tag(tag)
- repo.create_tag(name=tag, msg="Debian release %s" % version,
+ repo.create_tag(name=tag, msg="Debian release %s" % cp.version,
sign=options.sign_tags, keyid=options.keyid)
if options.posttag:
sha = repo.rev_parse("%s^{}" % tag)
diff --git a/gbp/scripts/create_remote_repo.py b/gbp/scripts/create_remote_repo.py
index 00f3410d..09158252 100644
--- a/gbp/scripts/create_remote_repo.py
+++ b/gbp/scripts/create_remote_repo.py
@@ -26,7 +26,7 @@ import urlparse
import subprocess
import tty, termios
import re
-import gbp.deb as du
+from gbp.deb.changelog import ChangeLog, NoChangeLogError
from gbp.command_wrappers import (CommandExecFailed, PristineTar, GitCommand)
from gbp.config import (GbpOptionParser, GbpOptionGroup)
from gbp.errors import GbpError
@@ -181,9 +181,9 @@ def main(argv):
branches += [ PristineTar.branch ]
try:
- cp = du.parse_changelog(filename=changelog)
+ cp = ChangeLog(filename=changelog)
pkg = cp['Source']
- except gbp.deb.NoChangelogError:
+ except NoChangeLogError:
pkg = None
if not pkg:
diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py
index a82c1bdc..b502e216 100644
--- a/gbp/scripts/dch.py
+++ b/gbp/scripts/dch.py
@@ -29,7 +29,8 @@ import gbp.log
from gbp.git import (GitRepositoryError, GitRepository, build_tag, tag_to_version)
from gbp.config import GbpOptionParser, GbpOptionGroup
from gbp.errors import GbpError
-from gbp.deb import parse_changelog, NoChangelogError, is_native, compare_versions
+from gbp.deb import compare_versions
+from gbp.deb.changelog import ChangeLog, NoChangeLogError
user_customizations = {}
snapshot_re = re.compile("\s*\*\* SNAPSHOT build @(?P<commit>[a-z0-9]+)\s+\*\*")
@@ -105,7 +106,7 @@ def add_changelog_section(msg, distribution, repo, options, cp,
"add a new changelog section"
# If no version(change) was specified guess the new version based on the
# latest upstream version on the upstream branch
- if not version and not is_native(cp):
+ if not version and not cp.is_native():
pattern = options.upstream_tag.replace('%(version)s', '*')
try:
tag = repo.find_tag('HEAD', pattern=pattern)
@@ -212,7 +213,7 @@ def do_snapshot(changelog, repo, next_snapshot):
"""
commit = repo.head
- cp = parse_changelog(filename=changelog)
+ cp = ChangeLog(filename=changelog)
(release, snapshot) = snapshot_version(cp['Version'])
snapshot = int(eval(next_snapshot))
@@ -387,7 +388,7 @@ def main(argv):
gbp.log.err("You are not on branch '%s' but on '%s'" % (options.debian_branch, branch))
raise GbpError, "Use --ignore-branch to ignore or --debian-branch to set the branch name."
- cp = parse_changelog(filename=changelog)
+ cp = ChangeLog(filename=changelog)
if options.since:
since = options.since
@@ -488,7 +489,7 @@ def main(argv):
if editor_cmd:
gbpc.Command(editor_cmd, ["debian/changelog"])()
- except (GbpError, GitRepositoryError, NoChangelogError), err:
+ except (GbpError, GitRepositoryError, NoChangeLogError), err:
if len(err.__str__()):
gbp.log.err(err)
ret = 1
diff --git a/gbp/scripts/import_dsc.py b/gbp/scripts/import_dsc.py
index 94013e25..10721c12 100644
--- a/gbp/scripts/import_dsc.py
+++ b/gbp/scripts/import_dsc.py
@@ -26,8 +26,9 @@ import pipes
import time
from email.Utils import parseaddr
import gbp.command_wrappers as gbpc
-from gbp.deb import (debian_version_chars, parse_changelog,
+from gbp.deb import (debian_version_chars,
parse_dsc, DscFile, UpstreamSource)
+from gbp.deb.changelog import ChangeLog
from gbp.git import (build_tag, GitRepository,
GitRepositoryError, rfc822_date_to_git)
from gbp.config import GbpOptionParser, GbpOptionGroup, no_upstream_branch_msg
@@ -95,7 +96,7 @@ def apply_debian_patch(repo, unpack_dir, src, options, parents):
os.chmod('debian/rules', 0755)
os.chdir(repo.path)
- dch = parse_changelog(filename=os.path.join(unpack_dir, 'debian/changelog'))
+ dch = ChangeLog(filename=os.path.join(unpack_dir, 'debian/changelog'))
date= rfc822_date_to_git(dch['Date'])
author, email = parseaddr(dch['Maintainer'])
if not (author and email):
diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py
index 445d1a6d..f6c8aa5e 100644
--- a/gbp/scripts/import_orig.py
+++ b/gbp/scripts/import_orig.py
@@ -25,12 +25,12 @@ import re
import subprocess
import tempfile
import gbp.command_wrappers as gbpc
-from gbp.deb import (parse_changelog, UpstreamSource,
- NoChangelogError, has_epoch,
+from gbp.deb import (UpstreamSource,
do_uscan,
parse_changelog_repo, is_valid_packagename,
packagename_msg, is_valid_upstreamversion,
upstreamversion_msg)
+from gbp.deb.changelog import ChangeLog, NoChangeLogError
from gbp.git import (GitRepositoryError, GitRepository, build_tag)
from gbp.config import GbpOptionParser, GbpOptionGroup, no_upstream_branch_msg
from gbp.errors import (GbpError, GbpNothingImported)
@@ -118,16 +118,16 @@ def detect_name_and_version(repo, source, options):
# Try to find the source package name
try:
- cp = parse_changelog(filename='debian/changelog')
+ cp = ChangeLog(filename='debian/changelog')
sourcepackage = cp['Source']
- except NoChangelogError:
+ except NoChangeLogError:
try:
# Check the changelog file from the repository, in case
# we're not on the debian-branch (but upstream, for
# example).
cp = parse_changelog_repo(repo, options.debian_branch, 'debian/changelog')
sourcepackage = cp['Source']
- except NoChangelogError:
+ except NoChangeLogError:
if options.interactive:
sourcepackage = ask_package_name(guessed_package)
else:
@@ -422,9 +422,9 @@ def main(argv):
# No need to check the changelog file from the
# repository, since we're certain that we're on
# the debian-branch
- cp = parse_changelog(filename='debian/changelog')
- if has_epoch(cp):
- epoch = '%s:' % cp['Epoch']
+ cp = ChangeLog(filename='debian/changelog')
+ if cp.has_epoch():
+ epoch = '%s:' % cp.epoch
info = { 'version': "%s%s-1" % (epoch, version) }
env = { 'GBP_BRANCH': options.debian_branch }
gbpc.Command(options.postimport % info, extra_env=env, shell=True)()