-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathchproduct.py
89 lines (65 loc) · 1.65 KB
/
chproduct.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
import os
import machine
import ujson
DEFAULT_PRODUCT_NAME = 'cyberEye'
DEFAULT_PRODUCT_VERSION = '2000.3000.4000.5021'
DEFAULT_LANGUAGE = 'en'
def registe_event_task(event_task):
global user_event_tasks
global MAX_EVENT_TASK_COUNT
if len(user_event_tasks) < MAX_EVENT_TASK_COUNT:
user_event_tasks.append(event_task)
event_task.start()
def get_system_info(lang=None):
try:
f = open('/flash/system_config', 'r+')
except:
return DEFAULT_PRODUCT_NAME, DEFAULT_PRODUCT_VERSION, DEFAULT_LANGUAGE
content = f.read()
config = ujson.loads(content)
if config['language'] != lang and lang:
config['language']=lang
f.close()
f = open('/flash/system_config', 'w')
f.write(ujson.dumps(config))
f.close()
return config['product_name'], config['product_version'], config['language']
def product_name():
productname, _, _ = get_system_info()
return productname
def product_version():
_, productver, _ = get_system_info()
return productver
def product_lang():
_, _, productlang = get_system_info()
return productlang
def write_file(filename, filecontentstr):
try:
f = open(filename, 'w')
f.write(filecontentstr)
f.close()
except:
pass
def begin_write_file(filename):
try:
os.remove(filename)
f = open(filename, 'w')
f.close()
except Exception as e:
f = open(filename, 'w')
f.close()
print(e)
pass
def append_write_file(filename, filecontentstr):
try:
f = open(filename, 'a+')
f.write(filecontentstr)
f.flush()
f.close()
except Exception as e:
f.flush()
f.close()
print(e)
pass
def reset_machine():
machine.reset()