1
2
3
4
5
6
7
8
9
10 from pysys import log
11 from pysys.constants import *
12 from pysys.exceptions import *
13
14
16 """
17 @deprecated: Internal helper function: do not use, will be removed in a future release.
18
19 Converts a unicode string or a utf-8 bit string into a unicode string.
20
21 """
22 if isinstance(s, unicode):
23 return s
24 else:
25 return unicode(s, "utf8")
26
27
29 """
30
31 @deprecated: Internal helper class: do not use, will be removed in a future release.
32
33 Class to store all supported xargs method arguments used in the helper classes.
34
35 Methods in the Apama helper classes define process related methods with a signature including
36 named parameters for the most commonly used options to the process, and an **xargs parameter to allow
37 passing through of additional supported named parameters, e.g. workingDir, state, timeout, stdout, stderr and
38 arguments. The XArgsHolder class takes the **xargs parameter from a method call (which is treated by
39 python as a dictionary of name value pairs) and default values for the workingDir, state, timeout, stdout, stderr
40 and arguments; these are used to set data attributes to the class instance with the default values. The class then
41 iterates over the **xargs and over-writes the default values if they exist in the parameter. This allows a
42 user of the class to create an instance to hold the additional arguments with default values in the first
43 case, but for these to be replaced if an alternative value is supplied via **xargs, e.g. the user of the method wants
44 to explicitly set the sdtout etc.
45
46 """
47
48 - def __init__(self, xargs, workingDir=None, state=FOREGROUND, timeout=None, stdout=None, stderr=None, arguments=[]):
49 """Create an instance of the XArgsHolder class.
50
51 @param xargs: The variable argument list passed into the method
52 @param workingDir: The default value for the working directory of a process
53 @param state: The default state of the process (L{pysys.constants.BACKGROUND} | L{pysys.constants.FOREGROUND})
54 @param timeout: The default value of the process timeout
55 @param stdout: The default value of the process stdout
56 @param stderr: The default value of the process stderr
57 @param arguments: List of extra arguments to be passed to the process
58
59 """
60 self.workingDir = workingDir
61 self.state = state
62 self.timeout = timeout
63 self.stdout = stdout
64 self.stderr = stderr
65 self.arguments = arguments
66
67
68 for key in xargs:
69 try:
70 getattr(self, key)
71 except AttributeError:
72 pass
73 else:
74 setattr(self, key, xargs[key])
75