@@ -196,6 +196,28 @@ class BugzillaError(Exception):
196196 pass
197197
198198
199+ class _FieldAlias (object ):
200+ """
201+ Track API attribute names that differ from what we expose in users.
202+
203+ For example, originally 'short_desc' was the name of the property that
204+ maps to 'summary' on modern bugzilla. We want pre-existing API users
205+ to be able to continue to use Bug.short_desc, and
206+ query({"short_desc": "foo"}). This class tracks that mapping.
207+
208+ @oldname: The old attribute name
209+ @newname: The modern attribute name
210+ @is_api: If True, use this mapping for values sent to the xmlrpc API
211+ (like the query example)
212+ @is_bug: If True, use this mapping for Bug attribute names.
213+ """
214+ def __init__ (self , newname , oldname , is_api = True , is_bug = True ):
215+ self .newname = newname
216+ self .oldname = oldname
217+ self .is_api = is_api
218+ self .is_bug = is_bug
219+
220+
199221class BugzillaBase (object ):
200222 '''An object which represents the data and methods exported by a Bugzilla
201223 instance. Uses xmlrpclib to do its thing. You'll want to create one thusly:
@@ -309,6 +331,29 @@ def __init__(self, url=None, user=None, password=None, cookiefile=-1,
309331 cookiefile = os .path .expanduser ('~/.bugzillacookies' )
310332 self .cookiefile = cookiefile
311333
334+ # List of field aliases. Maps old style RHBZ parameter
335+ # names to actual upstream values. Used for createbug() and
336+ # query include_fields at least.
337+ self ._field_aliases = []
338+ self ._add_field_alias ('summary' , 'short_desc' )
339+ self ._add_field_alias ('description' , 'comment' )
340+ self ._add_field_alias ('platform' , 'rep_platform' )
341+ self ._add_field_alias ('severity' , 'bug_severity' )
342+ self ._add_field_alias ('status' , 'bug_status' )
343+ self ._add_field_alias ('id' , 'bug_id' )
344+ self ._add_field_alias ('blocks' , 'blockedby' )
345+ self ._add_field_alias ('blocks' , 'blocked' )
346+ self ._add_field_alias ('depends_on' , 'dependson' )
347+ self ._add_field_alias ('creator' , 'reporter' )
348+ self ._add_field_alias ('url' , 'bug_file_loc' )
349+ self ._add_field_alias ('dupe_of' , 'dupe_id' )
350+ self ._add_field_alias ('dupe_of' , 'dup_id' )
351+ self ._add_field_alias ('comments' , 'longdescs' )
352+ self ._add_field_alias ('creation_time' , 'opendate' )
353+ self ._add_field_alias ('creation_time' , 'creation_ts' )
354+ self ._add_field_alias ('whiteboard' , 'status_whiteboard' )
355+ self ._add_field_alias ('last_change_time' , 'delta_ts' )
356+
312357 if url :
313358 self .connect (url )
314359
@@ -362,6 +407,17 @@ def _product_name_to_id(self, product):
362407 return p ['id' ]
363408 raise ValueError ('No product named "%s"' % product )
364409
410+ def _add_field_alias (self , * args , ** kwargs ):
411+ self ._field_aliases .append (_FieldAlias (* args , ** kwargs ))
412+
413+ def _get_bug_aliases (self ):
414+ return [(f .newname , f .oldname )
415+ for f in self ._field_aliases if f .is_bug ]
416+
417+ def _get_api_aliases (self ):
418+ return [(f .newname , f .oldname )
419+ for f in self ._field_aliases if f .is_api ]
420+
365421
366422 ###################
367423 # Cookie handling #
@@ -763,31 +819,6 @@ def _find_comps():
763819 # like this, for upstream bz it returns all info for every Bug.get()
764820 getbug_extra_fields = []
765821
766- # List of field aliases. Maps old style RHBZ parameter names to actual
767- # upstream values. Used for createbug() and query include_fields at
768- # least.
769- #
770- # Format is (currentname, oldname)
771- field_aliases = (
772- ('summary' , 'short_desc' ),
773- ('description' , 'comment' ),
774- ('platform' , 'rep_platform' ),
775- ('severity' , 'bug_severity' ),
776- ('status' , 'bug_status' ),
777- ('id' , 'bug_id' ),
778- ('blocks' , 'blockedby' ),
779- ('blocks' , 'blocked' ),
780- ('depends_on' , 'dependson' ),
781- ('creator' , 'reporter' ),
782- ('url' , 'bug_file_loc' ),
783- ('dupe_of' , 'dupe_id' ),
784- ('dupe_of' , 'dup_id' ),
785- ('comments' , 'longdescs' ),
786- ('creation_time' , 'opendate' ),
787- ('creation_time' , 'creation_ts' ),
788- ('whiteboard' , 'status_whiteboard' ),
789- ('last_change_time' , 'delta_ts' ),
790- )
791822
792823 def _getbugs (self , idlist , simple = False , permissive = True ):
793824 '''
@@ -1432,11 +1463,11 @@ def _validate_createbug(self, *args, **kwargs):
14321463
14331464 # If we're getting a call that uses an old fieldname, convert it to the
14341465 # new fieldname instead.
1435- for newfield , oldfield in self .field_aliases :
1436- if (newfield in self .createbug_required and
1437- newfield not in data and
1438- oldfield in data ):
1439- data [newfield ] = data .pop (oldfield )
1466+ for newname , oldname in self ._get_api_aliases () :
1467+ if (newname in self .createbug_required and
1468+ newname not in data and
1469+ oldname in data ):
1470+ data [newname ] = data .pop (oldname )
14401471
14411472 # Back compat handling for check_args
14421473 if "check_args" in data :
0 commit comments