From 6b923ffbda3c660ea04f61b89dfa2050918b39b8 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Sun, 12 Dec 2021 16:47:21 -0500 Subject: [PATCH] 2021-12-12 Fred Gleason * Added a 'Service()' type class to the 'rivwebpyapi' API. * Modified the 'rivwebpyapi.ListServices()' call to return a list of 'rivwebpyapi.Service' objects. Signed-off-by: Fred Gleason --- ChangeLog | 4 ++++ apis/rivwebpyapi/api/rivwebpyapi.py | 25 ++++++++++++++++++------- apis/rivwebpyapi/tests/list_services.py | 4 ++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 509c433d..64139219 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22775,3 +22775,7 @@ a 'rivwebpyapi.Group' object. * Modified the 'rivwebpyapi.ListGroups()' call to return a list of 'rivwebpyapi.Group' objects. +2021-12-12 Fred Gleason + * Added a 'Service()' type class to the 'rivwebpyapi' API. + * Modified the 'rivwebpyapi.ListServices()' call to return + a list of 'rivwebpyapi.Service' objects. diff --git a/apis/rivwebpyapi/api/rivwebpyapi.py b/apis/rivwebpyapi/api/rivwebpyapi.py index a77fd233..cb96ed75 100755 --- a/apis/rivwebpyapi/api/rivwebpyapi.py +++ b/apis/rivwebpyapi/api/rivwebpyapi.py @@ -238,6 +238,11 @@ SCHEDULER_CODE_FIELDS={ 'description': 'string' } +SERVICE_FIELDS={ + 'name': 'string', + 'description': 'string' +} + class RivWebPyApi_ListHandler(ContentHandler): def __init__(self,base_tag,fields): self.__output=[] @@ -441,6 +446,10 @@ class SchedulerCode(RivendellType): def __init__(self,values={}): super().__init__(SCHEDULER_CODE_FIELDS,values) +class Service(RivendellType): + def __init__(self,values={}): + super().__init__(SERVICE_FIELDS,values) + class rivwebpyapi(object): """ Create a 'RivWebPyApi' object for accessing the Web API. @@ -1641,7 +1650,8 @@ class rivwebpyapi(object): def ListServices(self,trackable): """ - Returns a set of Rivendell services (list of dictionaries). + Returns a set of Rivendell services + (list of rivwebpyapi.Service objects). Takes one argument: @@ -1674,14 +1684,15 @@ class rivwebpyapi(object): # # Generate the output dictionary # - fields={ - 'name': 'string', - 'description': 'string' - } - handler=RivWebPyApi_ListHandler(base_tag='service',fields=fields) + handler=RivWebPyApi_ListHandler(base_tag='service', + fields=SERVICE_FIELDS) xml.sax.parseString(r.text,handler) + out=handler.output() + ret=[] + for item in out: + ret.append(Service(item)) - return handler.output() + return ret def ListSystemSettings(self): """ diff --git a/apis/rivwebpyapi/tests/list_services.py b/apis/rivwebpyapi/tests/list_services.py index 05963424..ca06cb20 100755 --- a/apis/rivwebpyapi/tests/list_services.py +++ b/apis/rivwebpyapi/tests/list_services.py @@ -72,6 +72,6 @@ except rivwebpyapi.RivWebPyError as err: # Display the services list # for svc in services: - print('name: '+svc['name']) - print('description: '+svc['description']) + for key in svc.values(): + print(key+': '+str(svc.values()[key])) print('')