88#
99###################################################################################################
1010
11- __version__ = (0 , 8 , 12 )
11+ __version__ = (0 , 9 , 1 )
1212
1313import sys
14+ import re
1415
1516from .restapi import hydrateAnInstance
1617from .restapi import getResourceByOID
@@ -101,9 +102,6 @@ def __getattr__(self, name):
101102 if response .status_code != 200 :
102103 raise UnreferenceableOIDError , ("%s OID %s" % (rallyEntityTypeName , self .oid ))
103104 item = response .content [rallyEntityTypeName ]
104- #del item[u'Errors'] # this cruft from REST GET not actually part of the entity's attributes
105- #del item[u'Warnings'] # ditto
106-
107105##
108106## print "calling hydrateAnInstance from the __getattr__ of %s for %s" % (name, self._type)
109107## sys.stdout.flush()
@@ -126,13 +124,14 @@ def __getattr__(self, name):
126124
127125class Subscription (Persistable ): pass
128126
127+ class AllowedAttributeValue (Persistable ): pass # only used in an AttributeDefinition
128+ class AllowedQueryOperator (Persistable ): pass # only used in an AttributeDefinition
129+ # (for AllowedQueryOperators)
130+
129131class DomainObject (Persistable ):
130132 """ This is an Abstract Base class """
131133 pass
132134
133- class AllowedAttributeValue (Persistable ): pass # only used in an AttributeDefinition
134- class AllowedQueryOperator (Persistable ): pass # only used in an AttributeDefinition (for AllowedQueryOperators)
135-
136135class User (DomainObject ): pass
137136class UserProfile (DomainObject ): pass
138137class Workspace (DomainObject ): pass
@@ -142,8 +141,75 @@ class WorkspacePermission (UserPermission): pass
142141class ProjectPermission (UserPermission ): pass
143142
144143class WorkspaceDomainObject (DomainObject ):
145- """ This is an Abstract Base class """
146- pass
144+ """
145+ This is an Abstract Base class, with a convenience method (details) that
146+ formats the attrbutes and corresponding values into an easily viewable
147+ mulitiline string representation.
148+ """
149+ COMMON_ATTRIBUTES = ['_type' ,
150+ 'ObjectID' , '_ref' , '_CreatedAt' ,
151+ 'oid' , 'ref' , '_hydrated' ,
152+ 'Name' , 'Subscription' , 'Workspace'
153+ ]
154+
155+ def details (self ):
156+ """
157+ order we want to have the attributes appear in...
158+
159+ Class Name (aka _type)
160+ oid
161+ ref
162+ _ref
163+ _hydrated
164+ _CreatedAt
165+ ObjectID
166+ Name ** not all items will have this...
167+ Subscription (oid, Name)
168+ Workspace (oid, Name)
169+
170+ alphabetical from here on out
171+ """
172+ tank = ['%s' % self ._type ]
173+ for attribute_name in self .COMMON_ATTRIBUTES [1 :]:
174+ value = getattr (self , attribute_name )
175+ if 'pyral.entity.' not in str (type (value )):
176+ anv = ' %-16.16s : %s' % (attribute_name , value )
177+ else :
178+ mo = re .search (r' \'pyral.entity.(\w+)\'>' , str (type (value )))
179+ if mo :
180+ cln = mo .group (1 )
181+ anv = " %-16.16s : %-16.16s (OID %s Name: %s)" % \
182+ (attribute_name , cln + '.ref' , value .oid , value .Name )
183+ else :
184+ anv = " %-16.16s : %s" % value
185+ tank .append (anv )
186+ tank .append ("" )
187+ other_attributes = set (self .attributes ()) - set (self .COMMON_ATTRIBUTES )
188+ for attribute_name in sorted (other_attributes ):
189+ value = getattr (self , attribute_name )
190+ if not isinstance (value , Persistable ):
191+ anv = " %-16.16s : %s" % (attribute_name , value )
192+ else :
193+ mo = re .search (r' \'pyral.entity.(\w+)\'>' , str (type (value )))
194+ if not mo :
195+ anv = " %-16.16s : %s" % (attribute_name , value )
196+ continue
197+
198+ cln = mo .group (1 )
199+ anv = " %-16.16s : %-27.27s" % (attribute_name , cln + '.ref' )
200+ if isinstance (value , Artifact ):
201+ # also want the OID, FormattedID
202+ anv = "%s (OID %s FomattedID %s)" % (anv , value .oid , value .FormattedID )
203+ elif isinstance (value , User ):
204+ # also want the className, OID, UserName, DisplayName
205+ anv = " %-16.16s : %s.ref (OID %s UserName %s DisplayName %s)" % \
206+ (attribute_name , cln , value .oid , value .UserName , value .DisplayName )
207+ else :
208+ # also want the className, OID, Name)
209+ anv = "%s (OID %s Name %s)" % (anv , value .oid , value .Name )
210+ tank .append (anv )
211+ return "\n " .join (tank )
212+
147213
148214class WorkspaceConfiguration (WorkspaceDomainObject ): pass
149215class Type (WorkspaceDomainObject ): pass
0 commit comments