This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
uploadrelease.py
62 lines (50 loc) · 1.89 KB
/
uploadrelease.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
54
55
56
57
58
59
60
61
62
from os import walk
import requests
from requests.auth import HTTPBasicAuth
path = "./releases"
releaseID = ""
token = ""
# Get list of assets from dev branch
r = requests.get('https://api.github.com/repos/cedricve/kios/releases/%s/assets' % releaseID)
releases = r.json()
for release in releases:
headers = {
'content-type': 'application/json',
'Authorization': 'token %s' % token
}
url = "https://api.github.com/repos/cedricve/kios/releases/assets/%s" % str(release['id'])
response = requests.delete(url, headers=headers)
print response
# Get last release
dates = []
for (dirpath, dirnames, filenames) in walk(path):
dirParts = dirpath.split('/')
if len(dirParts) > 3 :
if dirParts[3] not in dates:
dates.append(dirParts[3])
dates.sort(key=int)
lastRelease = dates[-1]
# Get files from last release and take only the web.tar.gz
# from the rpi3 release (no need to upload the different ones).
filesToUpload = []
for (dirpath, dirnames, filenames) in walk(path):
for filename in filenames:
fullPath = dirpath + "/" + filename
pathParts = fullPath.split("/")
if len(pathParts) > 4 and pathParts[3] == lastRelease:
if (pathParts[2] != "rpi3" and pathParts[4] == "web.tar.gz") or pathParts[4] == ".DS_Store" :
continue
else:
filesToUpload.append(fullPath)
print filesToUpload
# Upload assets (files) to develop release
# POST https://<upload_url>/repos/:owner/:repo/releases/:id/assets?name=foo.zip
for file in filesToUpload:
headers = {
'content-type': 'application/octet-stream',
'Authorization': 'token %s' % token
}
pathParts = file.split("/")
url = "https://uploads.github.com/repos/cedricve/kios/releases/%s/assets?name=%s" % (releaseID, pathParts[4])
response = requests.post(url, data=open(file,'rb'), headers=headers)
print response