summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2009-08-22 14:31:51 +0200
committerGuido Günther <agx@sigxcpu.org>2009-08-23 17:28:49 +0200
commit4cd72bc7efc04fddf39b208b3d0bb7293bc904d9 (patch)
treed2e6d46f98126af7dc556a05c6adaf4d1714ab03
parent75eedb84533d5bdc90b601beb99e3bdef8ae3690 (diff)
add doctest for Command.__call__()
-rw-r--r--gbp/command_wrappers.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py
index 8f6f7fe4..b73549b3 100644
--- a/gbp/command_wrappers.py
+++ b/gbp/command_wrappers.py
@@ -1,6 +1,6 @@
# vim: set fileencoding=utf-8 :
#
-# (C) 2007 Guido Guenther <agx@sigxcpu.org>
+# (C) 2007,2009 Guido Guenther <agx@sigxcpu.org>
"""
Simple class wrappers for the various external commands needed by
git-buildpackage and friends
@@ -54,7 +54,7 @@ class Command(object):
run self.cmd adding args as additional arguments
be verbose about errors and encode them in the return value, don't pass
- on exceptons
+ on exceptons
"""
try:
retcode = self.__call(args)
@@ -72,7 +72,13 @@ class Command(object):
def __call__(self, args=[]):
"""run the command, convert all errors into CommandExecFailed, assumes
that the lower levels printed an error message - only usefull if you
- only expect 0 as result"""
+ only expect 0 as result
+ >>> Command("/bin/true")(["foo", "bar"])
+ >>> Command("/foo/bar")()
+ Traceback (most recent call last):
+ ...
+ CommandExecFailed
+ """
if self.__run(args):
raise CommandExecFailed
@@ -85,7 +91,6 @@ class Command(object):
return ret
-
class RunAtCommand(Command):
"""Run a command in a specific directory"""
def __call__(self, dir='.', *args):
@@ -132,6 +137,7 @@ class UnpackTarArchive(Command):
Command.__init__(self, 'tar', exclude + ['-C', dir, decompress, '-xf', archive ])
self.run_error = 'Couldn\'t unpack "%s"' % self.archive
+
class RepackTarArchive(Command):
"""Wrap tar to Repack a gzipped tar archive"""
def __init__(self, archive, dir, dest):
@@ -146,6 +152,7 @@ class RepackTarArchive(Command):
Command.__init__(self, 'tar', ['-C', dir, compress, '-cf', archive, dest])
self.run_error = 'Couldn\'t repack "%s"' % self.archive
+
class RemoveTree(Command):
"Wrap rm to remove a whole directory tree"
def __init__(self, tree):