-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirmware_list_maker.py
More file actions
executable file
·58 lines (43 loc) · 1.67 KB
/
firmware_list_maker.py
File metadata and controls
executable file
·58 lines (43 loc) · 1.67 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import logging
from bcf.firmware.GithubApi import GithubApi
import yaml
import json
from pprint import pprint
from datetime import datetime
import os
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)s %(levelname)s: %(message)s')
logging.getLogger("urllib3").setLevel(logging.WARNING)
save_path = os.environ.get('SAVE_PATH', '/var/www/firmware')
logging.info("Save path: %s", save_path)
ga = GithubApi(oauth_token=os.environ.get('GIT_OAUTH_TOKEN', None))
# pprint(ga.make_firmware_list_from_repo("hardwario/twr-radio-push-button")); exit()
def sort_firmware_key(firmware):
name = firmware['name']
for i, k in enumerate(('radio-dongle', 'gateway-usb-dongle', 'radio', "lora", "nbiot", "sigfox")):
if k in name:
return str(i) + name
return name
firmware_list = ga.make_firmware_list_for_owner("hardwario", ignore_empty=True)
logging.info("Sort")
firmware_list.sort(key=sort_firmware_key)
for firmware in firmware_list:
if firmware['name'] == "hardwario/bcf-gateway-usb-dongle":
firmware["images"] = [{
"title": "",
"url": "https://cdn.myshoptet.com/usr/shop.bigclown.com/user/shop/detail_alt_1/159-2.png?5a1af76a"
}]
payload = {
"list": firmware_list,
"date": datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"),
"version": 0
}
filename = os.path.join(save_path, 'yml')
logging.info("Save to: %s", filename)
with open(filename, 'w') as f:
yaml.safe_dump(payload, f, indent=2, default_flow_style=False)
filename = os.path.join(save_path, 'json')
logging.info("Save to: %s", filename)
with open(filename, 'w') as f:
json.dump(payload, f, indent=2)