|
| 1 | +#!/usr/bin/python |
| 2 | + |
| 3 | +import requests |
| 4 | +import json |
| 5 | +from pprint import pprint |
| 6 | +from glob import glob |
| 7 | + |
| 8 | +from semantic_version import Version |
| 9 | +import getpass |
| 10 | +import sys |
| 11 | + |
| 12 | +def main(): |
| 13 | + |
| 14 | + version = "" |
| 15 | + with open('files/version.txt') as f: |
| 16 | + version = f.read().strip() |
| 17 | + |
| 18 | + base_url = 'https://api.github.com/repos/jyapayne/Web2Executable/releases' |
| 19 | + |
| 20 | + req = requests.get(base_url+'/tags/'+version) |
| 21 | + |
| 22 | + update = False |
| 23 | + rel_id = None |
| 24 | + upload_url = None |
| 25 | + |
| 26 | + github_user = raw_input('Github user:') |
| 27 | + |
| 28 | + password = getpass.getpass('Password:') |
| 29 | + |
| 30 | + if req.status_code == 200: |
| 31 | + json_data = json.loads(req.text) |
| 32 | + tag = json_data.get('tag_name', '') |
| 33 | + cur_ver = Version(tag[1:-1]) |
| 34 | + new_ver = Version(version[1:-1]) |
| 35 | + if new_ver <= cur_ver: |
| 36 | + update = True |
| 37 | + rel_id = json_data['id'] |
| 38 | + upload_url = json_data['upload_url'].replace('{?name,label}', '') |
| 39 | + |
| 40 | + if not update: |
| 41 | + data = {'tag_name': version, |
| 42 | + 'target_commitish': 'master', |
| 43 | + 'name': 'Web2Executable ' + version} |
| 44 | + post_res = requests.post(base_url, data=json.dumps(data), auth=(github_user, password)) |
| 45 | + if post_res.status_code == 201: |
| 46 | + json_data = json.loads(post_res.text) |
| 47 | + upload_url = json_data['upload_url'].replace('{?name,label}', '') |
| 48 | + rel_id = json_data['id'] |
| 49 | + else: |
| 50 | + print 'Authentication failed!' |
| 51 | + |
| 52 | + if rel_id: |
| 53 | + zip_files = glob('*.zip') |
| 54 | + for zip_file in zip_files: |
| 55 | + with open(zip_file, 'rb') as zipf: |
| 56 | + file_data = zipf.read() |
| 57 | + print 'Uploading file {}...'.format(zip_file) |
| 58 | + data = {'name': zip_file} |
| 59 | + headers = {'Content-Type': 'application/zip'} |
| 60 | + r = requests.post(upload_url, params=data, data=file_data, headers=headers, auth=(github_user, password)) |
| 61 | + if r.status_code == 201: |
| 62 | + print 'Success!' |
| 63 | + else: |
| 64 | + print 'Error:', r.text |
| 65 | + |
| 66 | + |
| 67 | +if __name__ == '__main__': |
| 68 | + main() |
0 commit comments