Skip to content

Commit

Permalink
Fix py3 compatibility problem for UAI Train
Browse files Browse the repository at this point in the history
Signed-off-by Xiang Song<[email protected]>
  • Loading branch information
System Administrator authored and System Administrator committed Nov 20, 2017
1 parent 6133523 commit 1b09138
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 37 deletions.
32 changes: 1 addition & 31 deletions uai/cmd/base_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,44 +296,14 @@ def _cmd_common_request(self):
self.cmd_params)
uai_logger.info("Call http request: {0} ".format(get_request(self.cmd_url, params=self.cmd_params)))
r = requests.get(self.cmd_url, params=self.cmd_params)
self.rsp = json.loads(r.text, 'utf-8')
self.rsp = json.loads(r.text, encoding='utf-8')
if self.rsp["RetCode"] != 0:
uai_logger.error("{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], self.rsp["RetCode"], self.rsp["Message"].encode('utf-8')))
raise RuntimeError("{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], self.rsp["RetCode"], self.rsp["Message"].encode('utf-8')))
else:
del self.rsp['Action']
uai_logger.info("{0} Success: {1}".format(self.cmd_params["Action"], get_response(self.rsp,0)))


# def _cmd_writefile_package(self, filepath):
# if self.cmd_params.has_key('Signature'):
# self.cmd_params.pop('Signature')
# self.cmd_params['Signature'] = _verfy_ac(self.conf_params['private_key'],
# self.cmd_params)
# uai_logger.info("Call http request: {0} ".format(get_request(self.cmd_url, params=self.cmd_params)))
# r = requests.get(self.cmd_url, params=self.cmd_params)
# rsp = json.loads(r.text, 'utf-8')
# if rsp["RetCode"] != 0:
# uai_logger.error("{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], rsp["RetCode"], rsp["Message"].encode('utf-8')))
# raise RuntimeError(
# "{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], rsp["RetCode"], rsp["Message"].encode('utf-8')))
# else:
# with open(filepath, 'w') as f:
# json.dump(rsp["PkgSet"], f)


# def cmd(self, params):
# """ Create the task of specified task id
# """
# self.conf_params = params
# print "+++++in cmd func+++++"
# print self.conf_params
# if not self.conf_params:
# print "HERE!"
# self._load_args()
# self._format_request_param()
# self._cmd_request()

def cmd(self):
""" Create the task of specified task id
"""
Expand Down
4 changes: 2 additions & 2 deletions uaitrain/api/base_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ def __init__(self, action, pub_key, priv_key, project_id, region, zone):
pass

def _cmd_common_request(self):
if self.cmd_params.has_key('Signature'):
if ('Signature' in self.cmd_params) is True:
self.cmd_params.pop('Signature')
self.cmd_params['Signature'] = _verfy_ac(self.priv_key,
self.cmd_params)
uai_logger.info("Signature: {0}".format(self.cmd_params['Signature']))
uai_logger.info(self.cmd_params)
uai_logger.info("Call http request: {0} ".format(get_request(self.cmd_url, params=self.cmd_params)))
r = requests.get(self.cmd_url, params=self.cmd_params)
rsp = json.loads(r.text, 'utf-8')
rsp = json.loads(r.text, encoding='utf-8')
if rsp['RetCode'] != 0:
uai_logger.error("{0} Fail: [{1}]{2}".format(self.cmd_params[PARAM_ACTION], rsp['RetCode'],
rsp['Message'].encode('utf-8')))
Expand Down
8 changes: 4 additions & 4 deletions uaitrain/cmd/base_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ def _cmd_request(self):
self._cmd_common_request()

def _cmd_common_request(self):
if self.cmd_params.has_key('Signature'):
if ('Signature' in self.cmd_params) is True:
self.cmd_params.pop('Signature')
self.cmd_params['Signature'] = _verfy_ac(self.conf_params['private_key'],
self.cmd_params)
uai_logger.info("Call http request: {0} ".format(get_request(self.cmd_url, params=self.cmd_params)))
r = requests.get(self.cmd_url, params=self.cmd_params)
self.rsp = json.loads(r.text, 'utf-8')
self.rsp = json.loads(r.text, encoding='utf-8')
if self.rsp["RetCode"] != 0:
uai_logger.error("{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], self.rsp["RetCode"], self.rsp["Message"].encode('utf-8')))
raise RuntimeError("{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], self.rsp["RetCode"], self.rsp["Message"].encode('utf-8')))
Expand All @@ -126,13 +126,13 @@ def _cmd_common_request(self):


def _cmd_writefile_package(self, filepath):
if self.cmd_params.has_key('Signature'):
if ('Signature' in self.cmd_params) is True:
self.cmd_params.pop('Signature')
self.cmd_params['Signature'] = _verfy_ac(self.conf_params['private_key'],
self.cmd_params)
uai_logger.info("Call http request: {0} ".format(get_request(self.cmd_url, params=self.cmd_params)))
r = requests.get(self.cmd_url, params=self.cmd_params)
rsp = json.loads(r.text, 'utf-8')
rsp = json.loads(r.text, encoding='utf-8')
if rsp["RetCode"] != 0:
uai_logger.error("{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], rsp["RetCode"], rsp["Message"].encode('utf-8')))
raise RuntimeError(
Expand Down

0 comments on commit 1b09138

Please sign in to comment.