Mercurial > hg > beaglert
comparison scripts/hvresources/uploader.py @ 403:83e1acf38d35 prerelease
Updated build_pd_heavy to support the release flag
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Wed, 15 Jun 2016 02:37:34 +0100 |
parents | c768ed1055b0 |
children | b6eb94378ca9 |
comparison
equal
deleted
inserted
replaced
402:c29f07b7350e | 403:83e1acf38d35 |
---|---|
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 """ |
69 parser.add_argument( | 74 parser.add_argument( |
70 "-o", "--out", | 75 "-o", "--out", |
71 nargs="+", | 76 nargs="+", |
72 default=["./"], # by default | 77 default=["./"], # by default |
73 help="List of destination directories for retrieved files. Order should be the same as for --gen.") | 78 help="List of destination directories for retrieved files. Order should be the same as for --gen.") |
79 parser.add_argument( | |
80 "-r", "--release", | |
81 help="Optionally request a specific release of Heavy to use while compiling.") | |
74 parser.add_argument( | 82 parser.add_argument( |
75 "-d", "--domain", | 83 "-d", "--domain", |
76 default="https://enzienaudio.com", | 84 default="https://enzienaudio.com", |
77 help="Domain. Default is https://enzienaudio.com.") | 85 help="Domain. Default is https://enzienaudio.com.") |
78 parser.add_argument( | 86 parser.add_argument( |
118 "password": getpass.getpass("Enter password: ") | 126 "password": getpass.getpass("Enter password: ") |
119 } | 127 } |
120 | 128 |
121 tick = time.time() | 129 tick = time.time() |
122 | 130 |
131 # parse the optional release argument | |
132 if args.release: | |
133 post_data["release"] = args.release | |
134 | |
123 # make a temporary directory | 135 # make a temporary directory |
124 temp_dir = tempfile.mkdtemp(prefix="lroyal-") | 136 temp_dir = tempfile.mkdtemp(prefix="lroyal-") |
125 | 137 |
126 # zip up the pd directory into the temporary directory | 138 # zip up the pd directory into the temporary directory |
127 try: | 139 try: |
129 raise Exception("Root Pd directory does not contain a file named _main.pd.") | 141 raise Exception("Root Pd directory does not contain a file named _main.pd.") |
130 zip_path = __zip_dir( | 142 zip_path = __zip_dir( |
131 args.input_dir, | 143 args.input_dir, |
132 os.path.join(temp_dir, "archive.zip"), | 144 os.path.join(temp_dir, "archive.zip"), |
133 file_filter={"pd"}) | 145 file_filter={"pd"}) |
146 if os.stat(zip_path).st_size > __HV_MAX_UPLOAD_SIZE: | |
147 raise Exception("The target directory, zipped, is {0} bytes. The maximum upload size of 1MB.".format( | |
148 os.stat(zip_path).st_size)) | |
134 except Exception as e: | 149 except Exception as e: |
135 print e | 150 print "{0}Error:{1} {2}".format(Colours.red, Colours.end, e) |
136 shutil.rmtree(temp_dir) # clean up the temporary directory | 151 shutil.rmtree(temp_dir) # clean up the temporary directory |
137 return | 152 return |
138 | 153 |
139 post_data["name"] = args.name | 154 post_data["name"] = args.name |
140 | 155 |
144 "pdext", "pdext-osx", | 159 "pdext", "pdext-osx", |
145 "unity", "unity-osx", "unity-win-x86", "unity-win-x86_64", | 160 "unity", "unity-osx", "unity-win-x86", "unity-win-x86_64", |
146 "wwise", "wwise-win-x86_64", | 161 "wwise", "wwise-win-x86_64", |
147 "vst2", "vst2-osx", "vst2-win-x86_64", | 162 "vst2", "vst2-osx", "vst2-win-x86_64", |
148 } | 163 } |
149 post_data["gen"] = list(({"c"} | set(args.gen)) & __SUPPORTED_GENERATOR_SET) | 164 post_data["gen"] = list(({"c"} | {s.lower() for s in set(args.gen)}) & __SUPPORTED_GENERATOR_SET) |
150 | 165 |
151 # upload the job, get the response back | 166 # upload the job, get the response back |
152 # NOTE(mhroth): multipart-encoded file can only be sent as a flat dictionary, | 167 # 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. | 168 # but we want to send a json encoded deep dictionary. So we do a bit of a hack. |
154 r = requests.post( | 169 r = requests.post( |