summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/gh-get.py22
-rw-r--r--scripts/gh-list.py11
-rw-r--r--scripts/gh-push.py34
-rw-r--r--scripts/gh.py32
4 files changed, 99 insertions, 0 deletions
diff --git a/scripts/gh-get.py b/scripts/gh-get.py
new file mode 100644
index 0000000..bf95d97
--- /dev/null
+++ b/scripts/gh-get.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+from gh import gh, pr
+import sys, os
+
+filter = None
+if len(sys.argv) == 2:
+ filter = sys.argv[1]
+
+tok = os.getenv('GITHUB_TOKEN')
+
+draft = [r for r in gh('releases') if r['draft']][0]
+
+for a in draft['assets']:
+ if filter == None or filter in a['name']:
+ print('Downloading ' + a['name'])
+ b = gh('releases/assets/%s?access_token=%s' % (a['id'], tok),
+ ['-L', '-H', 'Accept: application/octet-stream'],
+ parse=False, quiet=False, auth=False)
+ f = open(a['name'], 'w')
+ f.write(b)
+ f.close()
diff --git a/scripts/gh-list.py b/scripts/gh-list.py
new file mode 100644
index 0000000..a2e7955
--- /dev/null
+++ b/scripts/gh-list.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+
+from gh import gh, pr
+import os
+
+tok = os.getenv('GITHUB_TOKEN')
+
+draft = [r for r in gh('releases') if r['draft']][0]
+
+for a in draft['assets']:
+ print(a['browser_download_url'])
diff --git a/scripts/gh-push.py b/scripts/gh-push.py
new file mode 100644
index 0000000..dd3b940
--- /dev/null
+++ b/scripts/gh-push.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+
+import sys, os, re
+from gh import gh
+
+if len(sys.argv) != 2:
+ print("Usage: python gh-push.py FILENAME")
+ sys.exit(1)
+
+f = sys.argv[1]
+fname = os.path.basename(f)
+
+print('Pulling info on draft release...')
+draft = [r for r in gh('releases') if r['draft']][0]
+print('Found: ' + draft['name'])
+
+existing = [a for a in draft['assets'] if a['name'] == fname]
+if (len(existing) > 0):
+ print('Asset %s exists, deleting.' % fname)
+ gh('releases/assets/' + str(existing[0]['id']),
+ ['-X', 'DELETE'])
+
+print('Uploading %s...' % f)
+
+upload_url = re.sub(
+ '\\{.*\\}', '?name=' + fname,
+ draft['upload_url'])
+
+resp = gh(upload_url, [
+ '-H', 'Content-type: application/octet-stream',
+ '--data-binary', '@' + f
+ ])
+
+print('Done.')
diff --git a/scripts/gh.py b/scripts/gh.py
new file mode 100644
index 0000000..81db1b2
--- /dev/null
+++ b/scripts/gh.py
@@ -0,0 +1,32 @@
+import sys, os, json
+from subprocess import Popen, PIPE
+
+api_url = 'https://api.github.com/repos/tikzit/tikzit'
+
+tok = os.getenv('GITHUB_TOKEN', '')
+
+if tok == '':
+ print("Must set GITHUB_TOKEN environment variable.")
+ sys.exit(1)
+
+# pretty-print JSON responses
+def pr(j): print(json.dumps(j, indent=2))
+
+# call GitHub API with curl
+def gh(s, args=[], quiet=True, parse=True, auth=True):
+ cmd = (["curl"] +
+ (["-s"] if quiet else []) +
+ args +
+ (["-H", "Authorization: token " + tok] if auth else []) +
+ [s if 'https://' in s else api_url + '/' + s])
+ # ONLY UN-COMMENT FOR TESTING:
+ # print(' '.join(cmd))
+ p = Popen(cmd, stdout=PIPE)
+ resp = p.stdout.read()
+ if parse: return json.loads(resp if resp else '{}')
+ else: return resp
+
+def get_release(n):
+ rs = [r for r in gh('releases') if r['name'] == n]
+ if len(rs) > 0: return rs[0]
+ else: return None