aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Guenther <agx@sigxcpu.org>2006-11-23 17:30:05 +0100
committerGuido Guenther <agx@bogon.sigxcpu.org>2006-11-23 17:30:05 +0100
commit18d7b62627881ff9d7d52ba3319b9f3fdf502494 (patch)
tree1efbb573e7e32bfaa402272ffc181f65526ff9c3
parent4e137d3929c43f773779d981f4befb915a34d272 (diff)
generate orig.tar.gz if it doesn't exist
-rw-r--r--debian/changelog6
-rwxr-xr-xgit-buildpackage58
-rw-r--r--git_buildpackage/deb_utils.py16
-rw-r--r--git_buildpackage/git_utils.py2
4 files changed, 70 insertions, 12 deletions
diff --git a/debian/changelog b/debian/changelog
index a39ebd7..95036ea 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+git-buildpackage (0.2.9buildorig0) git-buildpackage; urgency=low
+
+ * build an orig.tar.gz if nones there
+
+ -- Guido Guenther <agx@sigxcpu.org> Sun, 19 Nov 2006 14:17:40 +0100
+
git-buildpackage (0.2.9) git-buildpackage; urgency=low
* depend on a fixed git-load-dirs that contains the git_load_dirs executable
diff --git a/git-buildpackage b/git-buildpackage
index c94e8b3..3fa4029 100755
--- a/git-buildpackage
+++ b/git-buildpackage
@@ -22,16 +22,42 @@ import sys,os,commands,re
import optparse
from git_buildpackage import GitTag, Command, CommandExecFailed
from git_buildpackage.git_utils import *
+from git_buildpackage.deb_utils import *
build_cmd='debuild'
+output_dir='../'
-def get_version():
- versionre=re.compile('^Version:\s+(?P<version>.+)\s*$')
- (status, out) = commands.getstatusoutput('dpkg-parsechangelog')
- for line in out.split('\n'):
- m=versionre.match(line)
- if m:
- return m.group('version')
+
+def orig_file(cp):
+ "The name of the orig.tar.gz belongig to changelog cp"
+ return "%s_%s.orig.tar.gz" % (cp['Source'], cp['Upstream-Version'])
+
+
+def is_native(cp):
+ "Is this a debian native package"
+ return [ True, False ]['-' in cp['Version']]
+
+
+def has_orig(cp, dir):
+ "Check if orig.tar.gz exists in dir"
+ try:
+ os.stat("%s%s" % (dir,orig_file(cp)))
+ except OSError:
+ return False
+ return True
+
+
+def create_orig(cp, dir, branch):
+ "create an orig.tar.gz"
+ output='%s%s' % (dir, orig_file(cp))
+ try: # subprocess modules uses memory buffers, so we use '|' directly here:
+ os.system('git-archive --format=tar --prefix=%s-%s/ %s | gzip -c -9 > %s'
+ % (cp['Source'], cp['Upstream-Version'], branch, output))
+ except:
+ print("Error creating %s" % (output))
+ return False
+ return True
+
def main(argv):
args = [ arg for arg in argv[1:] if arg.find('--git-') == 0 ]
@@ -49,6 +75,8 @@ def main(argv):
help="command to build the package e.g. default is 'debuild'")
parser.add_option("--git-verbose", action="store_true", dest="verbose", default=False,
help="verbose command execution")
+ parser.add_option("--upstream-branch", dest="upstream_branch", default='upstream',
+ help="name of the upstream branch, default is 'upstream'")
(options, args) = parser.parse_args(args)
if options.verbose:
@@ -67,16 +95,24 @@ def main(argv):
print >>sys.stderr, out
print >>sys.stderr, "Use --git-ignore_new to ignore."
return 1
+ cp = parse_changelog('debian/changelog')
+ if not is_native(cp) and not has_orig(cp, output_dir):
+ print "%s does not exist, creating from branch %s" % (orig_file(cp), options.upstream_branch)
+ if not create_orig(cp, output_dir, options.upstream_branch):
+ return 1
Command(options.build_cmd,[ '-i.git', '-I.git' ]+dpkg_args)()
if options.tag:
- version=get_version()
- if version:
+ try:
+ version=cp['Version']
+ except KeyError:
+ print >>sys.stderr,"Can't parse version from changes file"
+ return 1
+ else:
print "Tagging", version
if not GitTag()(sanitize_version(version)): return 1
- else:
- print >>sys.stderr,"Can't parse version from changes file"
except CommandExecFailed:
return 1
+ return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))
diff --git a/git_buildpackage/deb_utils.py b/git_buildpackage/deb_utils.py
index d293c67..7568e20 100644
--- a/git_buildpackage/deb_utils.py
+++ b/git_buildpackage/deb_utils.py
@@ -2,7 +2,23 @@
# utility functions for git-buildpackge and friends
# (C) 2006 Guido Guenther <agx@sigxcpu.org>
+import email
+import commands
+
# When trying to parse a version-number from a dsc or changes file, these are
# the valid characters.
debian_version_chars='a-zA-Z\d.~+-'
+def parse_changelog(changelog):
+ """parse changelog file changelog"""
+ status, output = commands.getstatusoutput('dpkg-parsechangelog -l%s' % (changelog, ))
+ if status:
+ return None
+ cl=email.message_from_string(output)
+ if '-' in cl['Version']:
+ cl['Upstream-Version'], cl['Debian-Version'] = cl['Version'].rsplit('-',1)
+ else:
+ cl['Debian-Version']=cl['Version']
+ return cl
+
+# vim:et:ts=4:sw=4:
diff --git a/git_buildpackage/git_utils.py b/git_buildpackage/git_utils.py
index 089e58a..d18ead2 100644
--- a/git_buildpackage/git_utils.py
+++ b/git_buildpackage/git_utils.py
@@ -23,7 +23,7 @@ def is_repository_clean(path):
return (ret, "".join(out))
def is_repository(path):
- """Is there a git repository at path?"""
+ """Is there a git repository at path"""
if not path:
return False
try: