aboutsummaryrefslogtreecommitdiffhomepage
path: root/gbp
diff options
context:
space:
mode:
authorGuido Guenther <agx@sigxcpu.org>2007-02-11 23:07:41 +0100
committerGuido Guenther <agx@bogon.sigxcpu.org>2007-02-11 23:07:41 +0100
commit41e6419dfd337165e679ece4ae3ba310abc94db3 (patch)
tree1136e2bd547b8c9894e1d1ab0fb7501518f788b6 /gbp
parent8517e0965163ce6b9ae22cb3e6e3ba09a9be8a68 (diff)
use GBPError everywhere and move commands from __init__ to command_wrappers.py
Furthermore pass '-v' in git import-orig on to git_load_dirs
Diffstat (limited to 'gbp')
-rw-r--r--gbp/__init__.py188
-rw-r--r--gbp/command_wrappers.py191
-rw-r--r--gbp/config.py5
-rw-r--r--gbp/deb_utils.py5
-rw-r--r--gbp/errors.py10
-rw-r--r--gbp/git_utils.py4
6 files changed, 212 insertions, 191 deletions
diff --git a/gbp/__init__.py b/gbp/__init__.py
index 99251094..fe0ca3dd 100644
--- a/gbp/__init__.py
+++ b/gbp/__init__.py
@@ -1,187 +1,5 @@
-# -*- coding: utf-8 -*-
+# vim: set fileencoding=utf-8 :
#
-# (C) 2006 Guido Guenther <agx@sigxcpu.org>
-"""Simple class wrappers for the various commands needed by git-buildpackage"""
+# (C) 2006,2007 Guido Guenther <agx@sigxcpu.org>
+"""The various things needed by git-buildpackage and friends"""
-import subprocess
-import sys
-
-
-class CommandExecFailed(Exception):
- """Exception raised by the Command class"""
- pass
-
-
-class Command(object):
- """
- Wraps a shell command, so we don't have to store any kind of command line options in
- one of the git-buildpackage commands
- """
- verbose = False
-
- def __init__(self, cmd, args=[], shell=False):
- self.cmd = cmd
- self.args = args
- self.run_error = "Couldn't run '%s'" % (" ".join([self.cmd] + self.args))
- self.shell = shell
-
- def __run(self, args):
- """run self.cmd adding args as additional arguments"""
- try:
- if self.verbose:
- print self.cmd, self.args, args
- cmd = [ self.cmd ] + self.args + args
- if self.shell: # subprocess.call only cares about the first argument if shell=True
- cmd = " ".join(cmd)
- retcode = subprocess.call(cmd, shell=self.shell)
- if retcode < 0:
- print >>sys.stderr, "%s was terminated by signal %d" % (self.cmd, -retcode)
- elif retcode > 0:
- print >>sys.stderr, "%s returned %d" % (self.cmd, retcode)
- except OSError, e:
- print >>sys.stderr, "Execution failed:", e
- retcode = 1
- if retcode:
- print >>sys.stderr,self.run_error
- return retcode
-
- def __call__(self, args=[]):
- if self.__run(args):
- raise CommandExecFailed
-
-
-class UnpackTGZ(Command):
- """Wrap tar to Unpack a gzipped tar archive"""
- def __init__(self, tgz, dir):
- self.tgz = tgz
- self.dir = dir
- Command.__init__(self, 'tar', [ '-C', dir, '-zxf', tgz ])
- self.run_error = "Couldn't unpack %s" % self.tgz
-
-
-class RemoveTree(Command):
- "Wrap rm to remove a whole directory tree"
- def __init__(self, tree):
- self.tree = tree
- Command.__init__(self, 'rm', [ '-rf', tree ])
- self.run_error = "Couldn't remove %s" % self.tree
-
-
-class Dch(Command):
- """Wrap dch and set a specific version"""
- def __init__(self, version, msg):
- args = ['-v', version]
- if msg:
- args.append(msg)
- Command.__init__(self, 'dch', args)
- self.run_error = "Dch failed."
-
-
-class DpkgSourceExtract(Command):
- """
- Wrap dpkg-source to extract a Debian source package into a certain
- directory, this needs
- """
- def __init__(self):
- Command.__init__(self, 'dpkg-source', ['-x'])
-
- def __call__(self, dsc, output_dir):
- self.run_error = "Couldn't extract %s" % dsc
- Command.__call__(self, [dsc, output_dir])
-
-
-class GitLoadDirs(Command):
- """Wrap git_load_dirs"""
- def __init__(self):
- Command.__init__(self, 'git_load_dirs')
-
- def __call__(self, dir, log=''):
- self.dir = dir
- self.run_error = "Couldn't import %s" % self.dir
- args = [ [], ['-L', log] ] [len(log) > 0]
- Command.__call__(self, args+[dir])
-
-
-class GitCommand(Command):
- "Mother/Father of all git commands"
- def __init__(self, cmd, args=[]):
- Command.__init__(self, 'git-'+cmd, args)
-
-
-class GitInitDB(GitCommand):
- """Wrap git-init-db"""
- def __init__(self):
- GitCommand.__init__(self, 'init-db')
- self.run_error = "Couldn't init git repository"
-
-
-class GitShowBranch(GitCommand):
- """Wrap git-show-branch"""
- def __init__(self):
- GitCommand.__init__(self, 'branch')
- self.run_error = "Couldn't list branches"
-
-
-class GitBranch(GitCommand):
- """Wrap git-branch"""
- def __init__(self):
- GitCommand.__init__(self, 'branch')
-
- def __call__(self, branch):
- self.run_error = "Couldn't create branch %s" % (branch,)
- GitCommand.__call__(self, [branch])
-
-
-class GitCheckoutBranch(GitCommand):
- """Wrap git-checkout in order tos switch to a certain branch"""
- def __init__(self, branch):
- GitCommand.__init__(self, 'checkout', [branch])
- self.branch = branch
- self.run_error = "Couldn't switch to %s branch" % self.branch
-
-
-class GitPull(GitCommand):
- """Wrap git-pull"""
- def __init__(self, repo, branch):
- GitCommand.__init__(self, 'pull', [repo, branch])
- self.run_error = "Couldn't pull %s to %s" % (branch, repo)
-
-
-class GitTag(GitCommand):
- """Wrap git-tag"""
- def __init__(self, sign_tag=False, keyid=None):
- GitCommand.__init__(self,'tag')
- self.sign_tag = sign_tag
- self.keyid = keyid
-
- def __call__(self, version, msg="Tagging %(version)s"):
- self.run_error = "Couldn't tag %s" % (version,)
- if self.sign_tag:
- if self.keyid:
- sign_opts = [ '-u', self.keyid ]
- else:
- sign_opts = [ '-s' ]
- else:
- sign_opts = []
- GitCommand.__call__(self, sign_opts+[ '-m', msg % locals(), version])
-
-
-class GitAdd(GitCommand):
- """Wrap git-add to add new files"""
- def __init__(self):
- GitCommand.__init__(self,'add')
- self.run_error = "Couldn't add files"
-
-
-class GitCommitAll(GitCommand):
- """Wrap git-commit to commit all changes"""
- def __init__(self):
- GitCommand.__init__(self, 'commit', ['-a'])
-
- def __call__(self, msg=''):
- args = [ [], ['-m', msg] ][len(msg) > 0]
- self.run_error = "Couldn't commit -a %s" % " ".join(args)
- GitCommand.__call__(self, args)
-
-
-# vim:et:ts=4:sw=4:
diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py
new file mode 100644
index 00000000..58da2906
--- /dev/null
+++ b/gbp/command_wrappers.py
@@ -0,0 +1,191 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2007 Guido Guenther <agx@sigxcpu.org>
+"""
+Simple class wrappers for the various external commands needed by
+git-buildpackage and friends
+"""
+
+import subprocess
+import sys
+
+class CommandExecFailed(Exception):
+ """Exception raised by the Command class"""
+ pass
+
+
+class Command(object):
+ """
+ Wraps a shell command, so we don't have to store any kind of command line options in
+ one of the git-buildpackage commands
+ """
+ verbose = False
+
+ def __init__(self, cmd, args=[], shell=False):
+ self.cmd = cmd
+ self.args = args
+ self.run_error = "Couldn't run '%s'" % (" ".join([self.cmd] + self.args))
+ self.shell = shell
+
+ def __run(self, args):
+ """run self.cmd adding args as additional arguments"""
+ try:
+ if self.verbose:
+ print self.cmd, self.args, args
+ cmd = [ self.cmd ] + self.args + args
+ if self.shell: # subprocess.call only cares about the first argument if shell=True
+ cmd = " ".join(cmd)
+ retcode = subprocess.call(cmd, shell=self.shell)
+ if retcode < 0:
+ print >>sys.stderr, "%s was terminated by signal %d" % (self.cmd, -retcode)
+ elif retcode > 0:
+ print >>sys.stderr, "%s returned %d" % (self.cmd, retcode)
+ except OSError, e:
+ print >>sys.stderr, "Execution failed:", e
+ retcode = 1
+ if retcode:
+ print >>sys.stderr,self.run_error
+ return retcode
+
+ def __call__(self, args=[]):
+ if self.__run(args):
+ raise CommandExecFailed
+
+
+class UnpackTGZ(Command):
+ """Wrap tar to Unpack a gzipped tar archive"""
+ def __init__(self, tgz, dir):
+ self.tgz = tgz
+ self.dir = dir
+ Command.__init__(self, 'tar', [ '-C', dir, '-zxf', tgz ])
+ self.run_error = "Couldn't unpack %s" % self.tgz
+
+
+class RemoveTree(Command):
+ "Wrap rm to remove a whole directory tree"
+ def __init__(self, tree):
+ self.tree = tree
+ Command.__init__(self, 'rm', [ '-rf', tree ])
+ self.run_error = "Couldn't remove %s" % self.tree
+
+
+class Dch(Command):
+ """Wrap dch and set a specific version"""
+ def __init__(self, version, msg):
+ args = ['-v', version]
+ if msg:
+ args.append(msg)
+ Command.__init__(self, 'dch', args)
+ self.run_error = "Dch failed."
+
+
+class DpkgSourceExtract(Command):
+ """
+ Wrap dpkg-source to extract a Debian source package into a certain
+ directory, this needs
+ """
+ def __init__(self):
+ Command.__init__(self, 'dpkg-source', ['-x'])
+
+ def __call__(self, dsc, output_dir):
+ self.run_error = "Couldn't extract %s" % dsc
+ Command.__call__(self, [dsc, output_dir])
+
+
+class GitLoadDirs(Command):
+ """Wrap git_load_dirs"""
+ def __init__(self, verbose=False):
+ Command.__init__(self, 'git_load_dirs')
+ if verbose:
+ self.args = [ '-v' ]
+
+ def __call__(self, dir, log=''):
+ self.dir = dir
+ self.run_error = "Couldn't import %s" % self.dir
+ args = [ [], ['-L', log] ] [len(log) > 0]
+ Command.__call__(self, self.args + args + [dir])
+
+
+class GitCommand(Command):
+ "Mother/Father of all git commands"
+ def __init__(self, cmd, args=[]):
+ Command.__init__(self, 'git-'+cmd, args)
+
+
+class GitInitDB(GitCommand):
+ """Wrap git-init-db"""
+ def __init__(self):
+ GitCommand.__init__(self, 'init-db')
+ self.run_error = "Couldn't init git repository"
+
+
+class GitShowBranch(GitCommand):
+ """Wrap git-show-branch"""
+ def __init__(self):
+ GitCommand.__init__(self, 'branch')
+ self.run_error = "Couldn't list branches"
+
+
+class GitBranch(GitCommand):
+ """Wrap git-branch"""
+ def __init__(self):
+ GitCommand.__init__(self, 'branch')
+
+ def __call__(self, branch):
+ self.run_error = "Couldn't create branch %s" % (branch,)
+ GitCommand.__call__(self, [branch])
+
+
+class GitCheckoutBranch(GitCommand):
+ """Wrap git-checkout in order tos switch to a certain branch"""
+ def __init__(self, branch):
+ GitCommand.__init__(self, 'checkout', [branch])
+ self.branch = branch
+ self.run_error = "Couldn't switch to %s branch" % self.branch
+
+
+class GitPull(GitCommand):
+ """Wrap git-pull"""
+ def __init__(self, repo, branch):
+ GitCommand.__init__(self, 'pull', [repo, branch])
+ self.run_error = "Couldn't pull %s to %s" % (branch, repo)
+
+
+class GitTag(GitCommand):
+ """Wrap git-tag"""
+ def __init__(self, sign_tag=False, keyid=None):
+ GitCommand.__init__(self,'tag')
+ self.sign_tag = sign_tag
+ self.keyid = keyid
+
+ def __call__(self, version, msg="Tagging %(version)s"):
+ self.run_error = "Couldn't tag %s" % (version,)
+ if self.sign_tag:
+ if self.keyid:
+ sign_opts = [ '-u', self.keyid ]
+ else:
+ sign_opts = [ '-s' ]
+ else:
+ sign_opts = []
+ GitCommand.__call__(self, sign_opts+[ '-m', msg % locals(), version])
+
+
+class GitAdd(GitCommand):
+ """Wrap git-add to add new files"""
+ def __init__(self):
+ GitCommand.__init__(self,'add')
+ self.run_error = "Couldn't add files"
+
+
+class GitCommitAll(GitCommand):
+ """Wrap git-commit to commit all changes"""
+ def __init__(self):
+ GitCommand.__init__(self, 'commit', ['-a'])
+
+ def __call__(self, msg=''):
+ args = [ [], ['-m', msg] ][len(msg) > 0]
+ self.run_error = "Couldn't commit -a %s" % " ".join(args)
+ GitCommand.__call__(self, args)
+
+
+# vim:et:ts=4:sw=4:
diff --git a/gbp/config.py b/gbp/config.py
index eeffd440..09297c6b 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -1,5 +1,6 @@
-# -*- coding: utf-8 -*-
-# (C) 2006 Guido Guenther <agx@sigxcpu.org>
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2006,2007 Guido Guenther <agx@sigxcpu.org>
"""handles command line and config file option parsing for the gbp commands"""
from optparse import OptionParser
diff --git a/gbp/deb_utils.py b/gbp/deb_utils.py
index 8121ca70..8c4fd917 100644
--- a/gbp/deb_utils.py
+++ b/gbp/deb_utils.py
@@ -1,5 +1,6 @@
-# -*- coding: utf-8 -*-
-# (C) 2006 Guido Guenther <agx@sigxcpu.org>
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2006,2007 Guido Guenther <agx@sigxcpu.org>
"""provides some debian source package related helpers"""
import email
diff --git a/gbp/errors.py b/gbp/errors.py
new file mode 100644
index 00000000..be92b99f
--- /dev/null
+++ b/gbp/errors.py
@@ -0,0 +1,10 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2006,2007 Guido Guenther <agx@sigxcpu.org>
+"""Thinks common to all gbp commands"""
+
+class GbpError(Exception):
+ """Generic exception raised in git-buildpackage commands"""
+ pass
+
+# vim:et:ts=4:sw=4:
diff --git a/gbp/git_utils.py b/gbp/git_utils.py
index 4859a71d..19e280a1 100644
--- a/gbp/git_utils.py
+++ b/gbp/git_utils.py
@@ -1,6 +1,6 @@
-# -*- coding: utf-8 -*-
+# vim: set fileencoding=utf-8 :
#
-# (C) 2006 Guido Guenther <agx@sigxcpu.org>
+# (C) 2006,2007 Guido Guenther <agx@sigxcpu.org>
"""provides some git repository related helpers"""
import subprocess