File: gh-push.py

package info (click to toggle)
tikzit 2.1.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,104 kB
  • sloc: cpp: 8,492; yacc: 226; lex: 194; sh: 77; python: 68; makefile: 9; xml: 7
file content (34 lines) | stat: -rwxr-xr-x 774 bytes parent folder | download | duplicates (3)
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
#!/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.')