Mercurial > hg > beaglert
comparison scripts/hvresources/uploader.py @ 522:a084456960c9 prerelease
updated heavy uploader
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Thu, 23 Jun 2016 03:46:56 +0100 |
parents | b6eb94378ca9 |
children | 67a746eea29e |
comparison
equal
deleted
inserted
replaced
521:545087a05bc8 | 522:a084456960c9 |
---|---|
5 import json | 5 import json |
6 import os | 6 import os |
7 import requests | 7 import requests |
8 import shutil | 8 import shutil |
9 import stat | 9 import stat |
10 import sys | |
11 import tempfile | 10 import tempfile |
12 import time | 11 import time |
13 import urlparse | 12 import urlparse |
14 import zipfile | 13 import zipfile |
15 | 14 |
148 raise Exception("The target directory, zipped, is {0} bytes. The maximum upload size of 1MB.".format( | 147 raise Exception("The target directory, zipped, is {0} bytes. The maximum upload size of 1MB.".format( |
149 os.stat(zip_path).st_size)) | 148 os.stat(zip_path).st_size)) |
150 except Exception as e: | 149 except Exception as e: |
151 print "{0}Error:{1} {2}".format(Colours.red, Colours.end, e) | 150 print "{0}Error:{1} {2}".format(Colours.red, Colours.end, e) |
152 shutil.rmtree(temp_dir) # clean up the temporary directory | 151 shutil.rmtree(temp_dir) # clean up the temporary directory |
153 sys.exit(1) | 152 return |
154 | 153 |
155 post_data["name"] = args.name | 154 post_data["name"] = args.name |
156 | 155 |
157 # the outputs to generate (always include c) | 156 # the outputs to generate (always include c) |
158 __SUPPORTED_GENERATOR_SET = { | 157 __SUPPORTED_GENERATOR_SET = { |
270 if len(r_json.get("errors",[])) > 0: | 269 if len(r_json.get("errors",[])) > 0: |
271 shutil.rmtree(temp_dir) # clean up the temporary directory | 270 shutil.rmtree(temp_dir) # clean up the temporary directory |
272 for i,x in enumerate(r_json["errors"]): | 271 for i,x in enumerate(r_json["errors"]): |
273 print "{3}) {0}Error:{1} {2}".format( | 272 print "{3}) {0}Error:{1} {2}".format( |
274 Colours.red, Colours.end, x["detail"], i+1) | 273 Colours.red, Colours.end, x["detail"], i+1) |
275 sys.exit(2) | 274 return |
276 | 275 |
277 # retrieve all requested files | 276 # retrieve all requested files |
278 for i,g in enumerate(args.gen): | 277 for i,g in enumerate(args.gen): |
279 file_url = __get_file_url_for_generator(reply_json, g) | 278 file_url = __get_file_url_for_generator(reply_json, g) |
280 if file_url is not None and (len(args.out) > i or args.b): | 279 if file_url is not None and (len(args.out) > i or args.b): |
313 # delete the temporary directory | 312 # delete the temporary directory |
314 shutil.rmtree(temp_dir) | 313 shutil.rmtree(temp_dir) |
315 | 314 |
316 print "Job URL:", reply_json["data"]["links"]["self"] | 315 print "Job URL:", reply_json["data"]["links"]["self"] |
317 print "Total request time: {0}ms".format(int(1000.0*(time.time()-tick))) | 316 print "Total request time: {0}ms".format(int(1000.0*(time.time()-tick))) |
318 print "Heavy version:", reply_json["meta"]["version"] | 317 print "Heavy release:", reply_json.get("meta",{}).get("release", "default") |
319 sys.exit(0) # success! | |
320 | 318 |
321 def __get_file_url_for_generator(json_api, g): | 319 def __get_file_url_for_generator(json_api, g): |
322 """Returns the file link for a specific generator. | 320 """Returns the file link for a specific generator. |
323 Returns None if no link could be found. | 321 Returns None if no link could be found. |
324 """ | 322 """ |