From f84af4af3ab722e975912e9ad3249a5b80eef3f4 Mon Sep 17 00:00:00 2001 From: tmaeno Date: Tue, 9 Feb 2021 08:58:32 +0100 Subject: [PATCH] 1.4.50 --- pandatools/Client.py | 16 +++++++++++----- pandatools/PLogger.py | 5 ++--- pandatools/PandaToolsPkgInfo.py | 2 +- pandatools/idds_api.py | 17 ++++++++++++----- pandatools/idds_common.py | 29 ----------------------------- 5 files changed, 26 insertions(+), 43 deletions(-) delete mode 100644 pandatools/idds_common.py diff --git a/pandatools/Client.py b/pandatools/Client.py index b08a997a..367a2627 100755 --- a/pandatools/Client.py +++ b/pandatools/Client.py @@ -26,7 +26,6 @@ from .MiscUtils import commands_get_status_output, commands_get_output, pickle_loads from . import PLogger from . import openidc_utils -from . import idds_common # configuration try: @@ -1250,18 +1249,19 @@ def get_user_name_from_token(): # call idds command -def call_idds_command(command_name, args=None, kwargs=None, verbose=False): +def call_idds_command(command_name, args=None, kwargs=None, dumper=None, verbose=False): """Call an iDDS command through PanDA args: command_name: command name args: a list of positional arguments kwargs: a dictionary of keyword arguments + dumper: function object for json.dump verbose: True to see verbose message returns: status code 0: communication succeeded to the panda server 255: communication failure - response from iDDS, or diagnostic message if failed + a tuple of (True, response from iDDS), or (False, diagnostic message) if failed """ tmp_log = PLogger.getPandaLogger() # instantiate curl @@ -1275,9 +1275,15 @@ def call_idds_command(command_name, args=None, kwargs=None, verbose=False): data = dict() data['command_name'] = command_name if args: - data['args'] = json.dumps(args, cls=idds_common.EnumEncoder) + if dumper is None: + data['args'] = json.dumps(args) + else: + data['args'] = dumper(args) if kwargs: - data['kwargs'] = json.dumps(kwargs, cls=idds_common.EnumEncoder) + if dumper is None: + data['kwargs'] = json.dumps(kwargs) + else: + data['kwargs'] = dumper(kwargs) status, output = curl.post(url, data) if status != 0: return EC_Failed, output diff --git a/pandatools/PLogger.py b/pandatools/PLogger.py index 5df1e516..63f92c70 100644 --- a/pandatools/PLogger.py +++ b/pandatools/PLogger.py @@ -16,12 +16,11 @@ def getPandaLogger(): # use root logger global rootLog if rootLog is None: - rootLog = logging.getLogger('') + rootLog = logging.getLogger('panda-client') # add StreamHandler if no handler if rootLog.handlers == []: rootLog.setLevel(logging.DEBUG) - console = logging.StreamHandler() - #formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') + console = logging.StreamHandler(sys.stdout) formatter = logging.Formatter('%(levelname)s : %(message)s') console.setFormatter(formatter) rootLog.addHandler(console) diff --git a/pandatools/PandaToolsPkgInfo.py b/pandatools/PandaToolsPkgInfo.py index 8a09ad42..c5029596 100644 --- a/pandatools/PandaToolsPkgInfo.py +++ b/pandatools/PandaToolsPkgInfo.py @@ -1 +1 @@ -release_version = "1.4.50" +release_version = "1.4.51" diff --git a/pandatools/idds_api.py b/pandatools/idds_api.py index 87b54d50..82e420d6 100644 --- a/pandatools/idds_api.py +++ b/pandatools/idds_api.py @@ -4,20 +4,26 @@ # API call class class IddsApi(object): - def __init__(self, name): + def __init__(self, name, dumper, verbose): self.name = name + self.dumper = dumper + self.verbose = verbose def __call__(self, *args, **kwargs): - return Client.call_idds_command(self.name, args, kwargs) + return Client.call_idds_command(self.name, args, kwargs, self.dumper, self.verbose) # interface to API class IddsApiInteface(object): def __init__(self): - pass + self.dumper = None def __getattr__(self, item): - return IddsApi(item) + return IddsApi(item, self.dumper, self.verbose) + + def setup(self, dumper, verbose): + self.dumper = dumper + self.verbose = verbose # entry for API @@ -25,5 +31,6 @@ def __getattr__(self, item): del IddsApiInteface -def get_api(): +def get_api(dumper=None, verbose=False): + api.setup(dumper, verbose) return api \ No newline at end of file diff --git a/pandatools/idds_common.py b/pandatools/idds_common.py deleted file mode 100644 index 5aee0642..00000000 --- a/pandatools/idds_common.py +++ /dev/null @@ -1,29 +0,0 @@ -import json - - -# utility class to map idds constants to strings -class IddsConst(object): - - def __init__(self, name): - self.name = name - - def __getattr__(self, item): - if self.name: - return IddsConst('.'.join([self.name, item])) - return IddsConst(item) - - def __str__(self): - return self.name - - -# entry for mapping -constants = IddsConst('') - - -# json encoder for idds enum constants -class EnumEncoder(json.JSONEncoder): - def default(self, obj): - if isinstance(obj, IddsConst): - return {"__idds_const__": str(obj)} - return json.JSONEncoder.default(self, obj) -