comparison scripts/hvresources/uploader.py @ 299:df710a88e355

Updated Heavy uploader.py file
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 27 May 2016 13:23:37 +0100
parents c768ed1055b0
children
comparison
equal deleted inserted replaced
296:ff1d22e2c5a0 299:df710a88e355
22 red = "\033[91m" 22 red = "\033[91m"
23 bold = "\033[1m" 23 bold = "\033[1m"
24 underline = "\033[4m" 24 underline = "\033[4m"
25 end = "\033[0m" 25 end = "\033[0m"
26 26
27 # the maxmimum file upload size of 1MB
28 __HV_MAX_UPLOAD_SIZE = 1024*1024
29
27 def __zip_dir(in_dir, zip_path, file_filter=None): 30 def __zip_dir(in_dir, zip_path, file_filter=None):
31 """Recursively zip an entire directory with an optional file filter
32 """
28 zf = zipfile.ZipFile(zip_path, mode="w", compression=zipfile.ZIP_DEFLATED) 33 zf = zipfile.ZipFile(zip_path, mode="w", compression=zipfile.ZIP_DEFLATED)
29 for subdir, dirs, files in os.walk(in_dir): 34 for subdir, dirs, files in os.walk(in_dir):
30 for file in files: 35 for f in files:
31 if (file_filter is None) or (len(file_filter) > 0 and file.lower().split(".")[-1] in file_filter): 36 if (file_filter is None) or (f.lower().split(".")[-1] in file_filter):
32 zf.write( 37 zf.write(
33 filename=os.path.join(subdir,file), 38 filename=os.path.join(subdir,f),
34 arcname=os.path.relpath(os.path.join(subdir,file), start=in_dir)) 39 arcname=os.path.relpath(os.path.join(subdir,f), start=in_dir))
35 return zip_path 40 return zip_path
36 41
37 def __unzip(zip_path, target_dir): 42 def __unzip(zip_path, target_dir):
38 """Unzip a file to a given directory. All destination files are overwritten. 43 """Unzip a file to a given directory. All destination files are overwritten.
39 """ 44 """
129 raise Exception("Root Pd directory does not contain a file named _main.pd.") 134 raise Exception("Root Pd directory does not contain a file named _main.pd.")
130 zip_path = __zip_dir( 135 zip_path = __zip_dir(
131 args.input_dir, 136 args.input_dir,
132 os.path.join(temp_dir, "archive.zip"), 137 os.path.join(temp_dir, "archive.zip"),
133 file_filter={"pd"}) 138 file_filter={"pd"})
139 if os.stat(zip_path).st_size > __HV_MAX_UPLOAD_SIZE:
140 raise Exception("The target directory, zipped, is {0} bytes. The maximum upload size of 1MB.".format(
141 os.stat(zip_path).st_size))
134 except Exception as e: 142 except Exception as e:
135 print e 143 print "{0}Error:{1} {2}".format(Colours.red, Colours.end, e)
136 shutil.rmtree(temp_dir) # clean up the temporary directory 144 shutil.rmtree(temp_dir) # clean up the temporary directory
137 return 145 return
138 146
139 post_data["name"] = args.name 147 post_data["name"] = args.name
140 148
144 "pdext", "pdext-osx", 152 "pdext", "pdext-osx",
145 "unity", "unity-osx", "unity-win-x86", "unity-win-x86_64", 153 "unity", "unity-osx", "unity-win-x86", "unity-win-x86_64",
146 "wwise", "wwise-win-x86_64", 154 "wwise", "wwise-win-x86_64",
147 "vst2", "vst2-osx", "vst2-win-x86_64", 155 "vst2", "vst2-osx", "vst2-win-x86_64",
148 } 156 }
149 post_data["gen"] = list(({"c"} | set(args.gen)) & __SUPPORTED_GENERATOR_SET) 157 post_data["gen"] = list(({"c"} | {s.lower() for s in set(args.gen)}) & __SUPPORTED_GENERATOR_SET)
150 158
151 # upload the job, get the response back 159 # upload the job, get the response back
152 # NOTE(mhroth): multipart-encoded file can only be sent as a flat dictionary, 160 # NOTE(mhroth): multipart-encoded file can only be sent as a flat dictionary,
153 # but we want to send a json encoded deep dictionary. So we do a bit of a hack. 161 # but we want to send a json encoded deep dictionary. So we do a bit of a hack.
154 r = requests.post( 162 r = requests.post(