11PY2 = sys.version_info[0] == 2
12PY3 = sys.version_info[0] == 3
17 """Converts the value into a byte string.
19 if isinstance(v, unicode):
20 return v.encode(sys.getfilesystemencoding())
25 """Converts the value into a unicode string.
27 if isinstance(v, str):
28 return v.decode(sys.getfilesystemencoding())
33 """Print a unicode string with arguments.
38 """Print a byte string with arguments.
43 """Returns a formatted unicode string.
46 if isinstance(args, tuple):
47 args = [
U(a)
for a
in args]
48 return U(v).format(*args)
50 return U(v).format(
U(args))
55 """Print a string formatted with local variables.
59 localdict = inspect.currentframe().f_back.f_locals
64 """Print a byte string formatted with local variables.
68 localdict = inspect.currentframe().f_back.f_locals
73 """Returns a string formatted with local variables.
76 localdict = inspect.currentframe().f_back.f_locals
80 for k, v
in localdict.iteritems():
81 if isinstance(v, str):
82 udict[k] = v.decode(sys.getfilesystemencoding())
86 return U(s).format(**udict)
91 """Converts the value into a byte string.
93 if not isinstance(v, bytes):
94 return bytes(v, sys.getfilesystemencoding())
99 """Converts the value into a unicode string.
101 if not isinstance(v, str):
102 return str(v, sys.getfilesystemencoding())
107 """Prints the string with arguments.
112 """Returns a string with converted arguments.
115 if isinstance(args, tuple):
116 return v.format(*args)
118 return v.format(args)
122 def PrintL(v, localdict = None):
123 """Prints a string formatted with local variables.
126 localdict = inspect.currentframe().f_back.f_locals
130 def PrintLf(v, localdict = None):
131 """Returns a string formatted with local variables.
134 localdict = inspect.currentframe().f_back.f_locals
136 return v.format(**localdict)
139 """Runs a command and returns unicode output
141 cmdlist = [U(t) for t
in cmdlist]
142 return U(subprocess.check_output(cmdlist))
145 """Runs a command in the background
147 cmdlist = [U(t) for t
in cmdlist]
148 subprocess.Popen(cmdlist)
151def V(d, k, default = None):
152 """Utility function to get a value from a dict or object given its
153 name. Will return default if it can't be found.
155 The V functions are convenience functions designed to ensure that
156 a value is the correct type before being used for any work.
169def IntV(d, k, min = None, max = None, default = 0):
170 """Utility function to get an int from a dict or object given its
171 name. Will return default if it can't be found.
173 The V functions are convenience functions designed to ensure that
174 a value is the correct type before being used for any work.
182 v = int(getattr(d, k))
186 if min
is not None and v < min:
189 if max
is not None and v > max:
195def FloatV(d, k, min = None, max = None, default = 0.0):
196 """Utility function to get a float from a dict or object given its
197 name. Will return default if it can't be found.
199 The V functions are convenience functions designed to ensure that
200 a value is the correct type before being used for any work.
208 v = float(getattr(d, k))
212 if min
is not None and v < min:
215 if max
is not None and v > max:
222 """Utility function to get a string from a dict or object given its
223 name. Will return default if it can't be found.
225 The V functions are convenience functions designed to ensure that
226 a value is the correct type before being used for any work.
234 v = str(getattr(d, k))
242 """Utility function to get an array from a dict or object given its
243 name. Will return default if it can't be found.
245 The V functions are convenience functions designed to ensure that
246 a value is the correct type before being used for any work.
258 if not isinstance(v, list)
and not isinstance(v, tuple):
265 """Utility function to get a dict from a dict or object given its
266 name. Will return default if it can't be found.
268 The V functions are convenience functions designed to ensure that
269 a value is the correct type before being used for any work.
281 if not isinstance(v, dict):
def PrintLf(s, localdict=None)
Returns a string formatted with local variables.
def S(v)
Converts the value into a byte string.
def FloatV(d, k, min=None, max=None, default=0.0)
Utility function to get a float from a dict or object given its name.
def StrV(d, k, default='')
Utility function to get a string from a dict or object given its name.
def PrintL(v, localdict=None)
Print a string formatted with local variables.
def U(v)
Converts the value into a unicode string.
def Print(v, *args)
Print a unicode string with arguments.
def PrintBL(v, localdict=None)
Print a byte string formatted with local variables.
def DictV(d, k, default={})
Utility function to get a dict from a dict or object given its name.
def ArrayV(d, k, default=[])
Utility function to get an array from a dict or object given its name.
def RunCommand(cmdlist)
Runs a command and returns unicode output.
def IntV(d, k, min=None, max=None, default=0)
Utility function to get an int from a dict or object given its name.
def PrintB(v, *args)
Print a byte string with arguments.
def Printf(v, *args)
Returns a formatted unicode string.
def RunDaemon(cmdlist)
Runs a command in the background.
def V(d, k, default=None)
Utility function to get a value from a dict or object given its name.