|
4 | 4 | import os.path
|
5 | 5 | import sys
|
6 | 6 | import uritemplate
|
| 7 | +import glob |
7 | 8 |
|
8 | 9 | sys.path.append("adabot")
|
9 | 10 | import github_requests as github
|
10 | 11 |
|
11 | 12 | exit_status = 0
|
12 | 13 |
|
13 |
| -for dirpath, dirnames, filenames in os.walk("../bin"): |
14 |
| - if not filenames: |
15 |
| - continue |
16 |
| - for filename in filenames: |
17 |
| - full_filename = os.path.join(dirpath, filename) |
18 |
| - label = filename.replace("adafruit-circuitpython-", "") |
19 |
| - url_vars = {} |
20 |
| - url_vars["name"] = filename |
21 |
| - url_vars["label"] = label |
22 |
| - url = uritemplate.expand(os.environ["UPLOAD_URL"], url_vars) |
23 |
| - headers = {"content-type": "application/octet-stream"} |
24 |
| - print(url) |
25 |
| - with open(full_filename, "rb") as f: |
26 |
| - response = github.post(url, data=f, headers=headers) |
27 |
| - if not response.ok: |
28 |
| - if response.status_code == 422 and response.json().get("errors", [{"code":""}])[0]["code"] == "already_exists": |
29 |
| - print("File already uploaded. Skipping.") |
30 |
| - continue |
31 |
| - print("Upload of {} failed with {}.".format(filename, response.status_code)) |
32 |
| - print(response.text) |
33 |
| - sys.exit(response.status_code) |
| 14 | +filepaths = list(glob.iglob('../bin/*/*', recursive=True)) |
| 15 | +filepaths.sort() |
| 16 | + |
| 17 | +for full_filename in filepaths: |
| 18 | + filename = os.path.basename(full_filename) |
| 19 | + url_vars = {} |
| 20 | + url_vars["name"] = filename |
| 21 | + url = uritemplate.expand(os.environ["UPLOAD_URL"], url_vars) |
| 22 | + headers = {"content-type": "application/octet-stream"} |
| 23 | + print(url) |
| 24 | + with open(full_filename, "rb") as f: |
| 25 | + response = github.post(url, data=f, headers=headers) |
| 26 | + if not response.ok: |
| 27 | + if response.status_code == 422 and response.json().get("errors", [{"code":""}])[0]["code"] == "already_exists": |
| 28 | + print("File already uploaded. Skipping.") |
| 29 | + continue |
| 30 | + print("Upload of {} failed with {}.".format(filename, response.status_code)) |
| 31 | + print(response.text) |
| 32 | + sys.exit(response.status_code) |
34 | 33 |
|
35 | 34 | sys.exit(exit_status)
|
0 commit comments