1
2
3
4
5
6 from Ganga.GPIDev.Base.Objects import GangaObject
7 from Ganga.GPIDev.Base.Proxy import isProxy, isType, runProxyMethod
8
10 """A quoting function. Used to get consistent formatting"""
11
12 if type(value) == type(''):
13 if selection == 'copyable':
14
15 value = value.replace('"',R'\"')
16 value = value.replace("'",R"\'")
17
18
19
20
21
22
23
24
25 if 1 + value.find( "\n" ):
26
27 return "'''" + value + "'''"
28
29 return "'"+value+"'"
30
31 return value
32
34 return ' '*(level-1)*3
35
36
38
39
40
41
42
43
44 - def __init__(self,out=None,selection=''):
45 self.level = 0
46 self.nocomma = 1
47 self.selection = selection
48 if out:
49 self.out = out
50 else:
51 import sys
52 self.out = sys.stdout
53
54 self.empty_body = 0
55
58
60 if not self.nocomma or force:
61 print >> self.out, ","
62
63 self.nocomma = 0
64
66 self.level += 1
67 print >> self.out,node._schema.name,'('
68 self.nocomma = 1
69 self.empty_body = 1
70
72 if self.empty_body:
73 print >> self.out, self.indent(), ')',
74 self.nocomma = 0
75 else:
76 if self.nocomma:
77
78 print >> self.out, ')',
79 else:
80
81 print >> self.out,'\n',self.indent(),')',
82
83 self.level -= 1
84 if self.level == 0: print >> self.out,'\n'
85
87 visible = False
88 if self.selection == 'all':
89 visible = True
90 elif self.selection == 'copyable':
91 if node._schema.getItem(name)['copyable']:
92 if not node._schema.getItem(name)['hidden']:
93 visible = True
94 else:
95 if not node._schema.getItem(name)['hidden']:
96 visible = True
97 return visible
98
112
114 if s is None:
115 print >> self.out, None,
116 else:
117 runProxyMethod(s,'accept',self)
118
120 if self.showAttribute( node, name ):
121 self.empty_body = 0
122 self.comma()
123 print >> self.out, self.indent(), name, '=',
124 if sequence:
125 print >> self.out, '[',
126 for s in subnode:
127 self.acceptOptional(s)
128 print >> self.out,',',
129 print >> self.out, ']',
130 else:
131 self.acceptOptional(subnode)
132
135
137 """A class for printing summeries of object properties in a customisable way."""
138
139 - def __init__(self,level, verbosity_level, whitespace_marker, out=None,selection=''):
140 super(VSummaryPrinter,self).__init__(out,selection)
141 self.level = level
142 self.verbosity_level = verbosity_level
143 self.whitespace_marker = whitespace_marker
144
146 """Checks to see whether there is a summary_print function pointer
147 available in the schema object. If so it uses it and returns True
148 otherwise it returns False.
149 """
150 function_pointer_available = False
151
152
153 print_summary = node._schema.getItem(name)['summary_print']
154 if print_summary != None:
155 fp = getattr(node,print_summary)
156 str_val = fp(value,self.verbosity_level)
157 self.empty_body = 0
158 self.comma()
159 print >> self.out, self.indent(), name, '=', self.quote(str_val),
160 function_pointer_available = True
161 return function_pointer_available
162
164 import StringIO
165 sio = StringIO.StringIO()
166 runProxyMethod(obj, 'printSummaryTree',self.level, self.verbosity_level, self.indent(), sio, self.selection)
167 result = sio.getvalue()
168 if result.endswith('\n'):
169 result = result[0:-1]
170 print >>self.out, result,
171
173 """Overrides the baseclass method. Tries to print a summary of the attribute."""
174 if not self.showAttribute( node, name ):
175 return
176 if self._CallSummaryPrintMember(node,name,getattr(node,name)):
177 return
178
179 if sequence:
180 self.empty_body = 0
181 self.comma()
182 print >> self.out, self.indent(), name, '=',
183 self._CallPrintSummaryTree(value)
184 return
185
186
187 super(VSummaryPrinter,self).simpleAttribute(node, name, value, sequence)
188
190 if not self.showAttribute( node, name ):
191 return
192 if self._CallSummaryPrintMember(node,name,subnode):
193 return
194 from Objects import GangaObject
195 if isType(subnode,GangaObject):
196 self.empty_body = 0
197 self.comma()
198 print >> self.out, self.indent(), name, '=',
199 self._CallPrintSummaryTree(subnode)
200 return
201
202
203 super(VSummaryPrinter,self).componentAttribute(node, name, subnode, sequence)
204
206 """Print the full contents of a GPI object without abbreviation."""
207 import sys
208 if out == None:
209 out = sys.stdout
210
211 from Ganga.GPIDev.Lib.GangaList import GangaList
212 if isType(obj,GangaList):
213 obj_len = len(obj)
214 if obj_len == 0:
215 print >>out, '[]',
216 else:
217 import StringIO
218 outString = '['
219 count = 0
220 for x in obj:
221 if isinstance(x, GangaObject):
222 sio = StringIO.StringIO()
223 x.printTree(sio)
224 result = sio.getvalue()
225
226 outString += result.rstrip()
227 else:
228 result = str(x)
229
230 outString += result.rstrip()
231 count += 1
232 if count != obj_len: outString += ', '
233 outString += ']'
234 print >>out, outString,
235 return
236
237 if isProxy(obj):
238 import StringIO
239 sio = StringIO.StringIO()
240 runProxyMethod(obj,'printTree',sio)
241 print >>out, sio.getvalue(),
242 else:
243 print >>out, str(obj),
244