From ef49109a881e0301887a218e825b2a8631e8b016 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 29 Jan 2017 15:19:28 -0800 Subject: [PATCH] remote job submission: fix error if no input files also use hashlib instead of md5 in python code to avoid deprecation warning --- lib/submit_api.py | 10 ++++++---- tools/submit_api_test.py | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/submit_api.py b/lib/submit_api.py index 78b67a5da8..a73d52289d 100644 --- a/lib/submit_api.py +++ b/lib/submit_api.py @@ -23,6 +23,7 @@ import copy import xml.etree.ElementTree as ET import requests # you'll need to "yip install requests" +import hashlib # describes an input file # @@ -58,8 +59,9 @@ class JOB_DESC: xml += '\n%s\n\n'%self.wu_template if hasattr(self, 'result_template'): xml += '\n%s\n\n'%self.result_template - for file in self.files: - xml += file.to_xml() + if hasattr(self, 'files'): + for file in self.files: + xml += file.to_xml() xml += '\n' return xml @@ -173,13 +175,13 @@ def query_job(req): return do_http_post(req_xml, req.project) def get_output_file(req): - auth_str = md5.new(req.authenticator+req.instance_name).hexdigest() + auth_str = hashlib.md5(req.authenticator+req.instance_name).hexdigest() name = req.instance_name file_num = req.file_num return req.project+"/get_output.php?cmd=result_file&result_name=%s&file_num=%s&auth_str=%s"%(name, file_num, auth_str) def get_output_files(req): - auth_str = md5.new(req.authenticator+req.batch_id).hexdigest() + auth_str = hashlib.md5(req.authenticator+str(req.batch_id)).hexdigest() return req.project+"/get_output.php?cmd=batch_files&batch_id=%s&auth_str=%s"%(req.batch_id, auth_str) def retire_batch(req): diff --git a/tools/submit_api_test.py b/tools/submit_api_test.py index 0ce9a4f7ad..6f66343f3d 100644 --- a/tools/submit_api_test.py +++ b/tools/submit_api_test.py @@ -177,4 +177,21 @@ def test_query_files(): for f in r[0]: print f.text -test_upload_files() +def test_get_output_file(): + req = REQUEST() + req.project = project_url + req.authenticator = get_auth() + req.instance_name = 'uppercase_32275_1484961754.784017_0_0'; + req.file_num = 1; + r = get_output_file(req) + print(r) + +def test_get_output_files(): + req = REQUEST() + req.project = project_url + req.authenticator = get_auth() + req.batch_id = 271 + r = get_output_files(req) + print(r) + +test_get_output_files()