From 5daa9014a8e1380f3ca13f31cc5c56d575ad981b Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Tue, 12 May 2015 11:19:28 +0100 Subject: [PATCH] Adding "agruments" type This type represents arguments that are passed on a command line to an application. It has both string and list representations. --- wlauto/utils/types.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/wlauto/utils/types.py b/wlauto/utils/types.py index a03cf9eb..8d122fc3 100644 --- a/wlauto/utils/types.py +++ b/wlauto/utils/types.py @@ -25,8 +25,10 @@ A lot of these are intened to stpecify type conversions declaratively in place l is not the best language to use for configuration. """ +import os import re import math +import shlex from collections import defaultdict from wlauto.utils.misc import isiterable, to_identifier @@ -246,3 +248,31 @@ class caseless_string(str): def format(self, *args, **kwargs): return caseless_string(super(caseless_string, self).format(*args, **kwargs)) + + +class arguments(list): + """ + Represents command line arguments to be passed to a program. + + """ + + def __init__(self, value=None): + if isiterable(value): + super(arguments, self).__init__(map(str, value)) + elif isinstance(value, basestring): + posix = os.name != 'nt' + super(arguments, self).__init__(shlex.split(value, posix=posix)) + elif value is None: + super(arguments, self).__init__() + else: + super(arguments, self).__init__([str(value)]) + + def append(self, value): + return super(arguments, self).append(str(value)) + + def extend(self, values): + return super(arguments, self).extend(map(str, values)) + + def __str__(self): + return ' '.join(self) +