Skip to content

Commit

Permalink
1.4.50
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaeno committed Feb 9, 2021
1 parent bb83723 commit f84af4a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 43 deletions.
16 changes: 11 additions & 5 deletions pandatools/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions pandatools/PLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pandatools/PandaToolsPkgInfo.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
release_version = "1.4.50"
release_version = "1.4.51"
17 changes: 12 additions & 5 deletions pandatools/idds_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@
# 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
api = IddsApiInteface()
del IddsApiInteface


def get_api():
def get_api(dumper=None, verbose=False):
api.setup(dumper, verbose)
return api
29 changes: 0 additions & 29 deletions pandatools/idds_common.py

This file was deleted.

0 comments on commit f84af4a

Please sign in to comment.