-
Notifications
You must be signed in to change notification settings - Fork 30
/
build.py
57 lines (47 loc) · 2.08 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import json
import os
import sys
import subprocess
import tempfile
if __name__ == "__main__":
def get(url):
proc = subprocess.Popen("curl -s %s" % url, shell=True, stdout=subprocess.PIPE)
stdout, stderr = proc.communicate()
return stdout
def run(cmd):
assert(os.system(cmd) == 0)
version = json.load(open('package.json'))['packages'][0]['platforms']['*'][0]['version']
run("javac -source 1.5 -target 1.5 SublimeJava.java")
package_name = "SublimeJava-%s.sublime-package" % version
for arg in sys.argv[1:]:
if arg == "--create":
run("rm -rf release")
run("mkdir release")
run("cp -r sublimecompletioncommon release")
run("find . -maxdepth 1 -type f -exec cp {} release \;")
run("find release -name \".git*\" | xargs rm -rf")
run("find release -name \"*.pyc\" -exec rm {} \;")
run("find release -name \"unittest*\" -exec rm -f {} \;")
run("rm -f release/build.py")
run("cd release && zip -r %s *" % package_name)
elif arg == "--upload":
current_downloads = json.loads(get("https://api.github.com/repos/quarnster/SublimeJava/downloads"))
for download in current_downloads:
assert download['name'] != package_name
f = tempfile.NamedTemporaryFile()
f.write("""{ "name": "%s", "size": %s}""" % (package_name, os.path.getsize("release/%s" % package_name)))
f.flush()
response = json.loads(get("-X POST -d @%s -u quarnster https://api.github.com/repos/quarnster/SublimeJava/downloads" % f.name))
f.close()
args = """\
-F "key=%s" \
-F "acl=%s" \
-F "success_action_status=201" \
-F "Filename=%s" \
-F "AWSAccessKeyId=%s" \
-F "Policy=%s" \
-F "Signature=%s" \
-F "Content-Type=%s" \
-F "file=@release/%s" \
https://github.s3.amazonaws.com/""" % (response["path"], response["acl"], response["name"], response["accesskeyid"], response["policy"], response["signature"], response["mime_type"], package_name)
print(get(args))