comparison scripts/hvresources/uploader.py @ 504:b6eb94378ca9 prerelease

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