summaryrefslogtreecommitdiff
path: root/gbp/git
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2012-07-06 16:25:37 +0300
committerGuido Günther <agx@sigxcpu.org>2012-08-22 10:41:27 +0200
commitdc3b3b6485b4df7b2ea4af70b8d89acff362113a (patch)
tree4a9d7c1e3acbaa958367bd675d0f9e8dff001db9 /gbp/git
parent7524bbb37c3a1312f382db24d04e0234b7ff07b3 (diff)
downloadgit-buildpackage-dc3b3b6485b4df7b2ea4af70b8d89acff362113a.tar.gz
git-buildpackage-dc3b3b6485b4df7b2ea4af70b8d89acff362113a.tar.bz2
git-buildpackage-dc3b3b6485b4df7b2ea4af70b8d89acff362113a.zip
GitArgs/add: support iterable and non-string args
Support giving iterables (other than basestring, e.g. list(s)) as an argument to GitArgs.add(). Also, add support non-iterable arguments that support the str() conversion. Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'gbp/git')
-rw-r--r--gbp/git/args.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/gbp/git/args.py b/gbp/git/args.py
index ff9077ea..f894085d 100644
--- a/gbp/git/args.py
+++ b/gbp/git/args.py
@@ -15,6 +15,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+import collections
+
class GitArgs(object):
"""
Handle arguments to git commands
@@ -23,6 +25,8 @@ class GitArgs(object):
['-h', '--no-foo']
>>> GitArgs().add('--more-foo', '--less-bar').args
['--more-foo', '--less-bar']
+ >>> GitArgs().add(['--foo', '--bar']).args
+ ['--foo', '--bar']
>>> GitArgs().add_cond(1 > 2, '--opt', '--no-opt').args
['--no-opt']
>>> GitArgs().add_true(True, '--true').args
@@ -44,7 +48,15 @@ class GitArgs(object):
"""
Add arguments to argument list
"""
- self._args += list(args)
+ for arg in args:
+ if isinstance(arg, basestring):
+ self._args.append(arg)
+ elif isinstance(arg, collections.Iterable):
+ for i in iter(arg):
+ self._args.append(str(i))
+ else:
+ self._args.append(str(arg))
+
return self
def add_true(self, condition, *args):