This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cores.py
88 lines (73 loc) · 2.13 KB
/
cores.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import json
import paramiko
import shutil
import os
import config
import logger
import mister
import ssh
SETTINGS = config.get_config()
ipaddress = SETTINGS['main']['mister_ip']
username = SETTINGS['main']['mister_username']
password = SETTINGS['main']['mister_password']
map_file = "cores.json"
cores = {}
def build_system_map():
stdout = ssh.send_command('find /media/fat -type f -name "*.rbf"')
stdout.sort()
cores = {}
for line in stdout:
line = line.split('/')[-1].strip()
corename = line.replace(".rbf","")
if "_" in line:
corename = line.split("_")[0]
core = {}
core['description'] = "{} core".format(corename)
core['scene'] = "{} Scene".format(corename)
cores[corename] = core
return cores
def get_cores():
return cores
def read_file_map():
global map_file
if os.path.exists(map_file):
with open(map_file) as map_json:
maps = json.load(map_json)
return maps
else:
return {}
def merge_maps():
if os.path.exists(map_file):
logger.info("Backing up {} ...".format(map_file))
shutil.copyfile(map_file, '{}.bak'.format(map_file))
else:
logger.info("No map file exists, only using map from system.")
system_map = build_system_map()
file_map = read_file_map()
merged_map = system_map
for map in file_map:
merged_map[map] = file_map[map]
added_maps = []
for map in system_map:
if map not in file_map:
added_maps.append(map)
if len(added_maps) > 0:
logger.info("The following cores have been added to the cores.json: {}".format(added_maps))
with open(map_file, "w") as write_file:
json.dump(merged_map, write_file, indent=4)
def load_map_to_memory():
global map_file
global cores
if os.path.exists(map_file):
with open(map_file) as map_json:
maps = json.load(map_json)
cores = maps
def get_map(corename):
if corename in cores:
return cores[corename]
else:
return {}
merge_maps()
load_map_to_memory()
if __name__ == "__main__":
pass