-
Notifications
You must be signed in to change notification settings - Fork 59
/
auto_install.py
98 lines (78 loc) · 2.36 KB
/
auto_install.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
89
90
91
92
93
94
95
96
97
98
import os
import zipfile
import shutil
def find(name, path):
for root, dirs, files in os.walk(path):
if name in files:
return os.path.join(root, name)
return None
def get_config_path():
path = find('.HA_VERSION', '/')
if not path:
return None
path = path[:len(path) - 11]
print("Home Assistant configuration path found: %s" % (path))
return path
def uninstall_old(path):
print("Uninstall molohub old version...")
path += '/custom_components/molohub'
try:
shutil.rmtree(path)
except Exception:
pass
def download_file():
global start_time
print("Downloading file...")
curl = 'curl --show-error --retry 5 https://codeload.github.com/haoctopus/molohub/zip/master >> molohub-master.zip'
os.system(curl)
def extract_file():
print("Extracting file...")
try:
shutil.rmtree('molo_install_temp/')
except Exception:
pass
with zipfile.ZipFile("molohub-master.zip", 'r') as f:
for file in f.namelist():
f.extract(file, "molo_install_temp/")
def copy_file(path):
print("Copying file...")
path += '/custom_components/molohub'
frompath = 'molo_install_temp/molohub-master/molohub'
shutil.copytree(frompath, path)
def configurate(path):
print("Configurating...")
path += '/configuration.yaml'
shutil.copy(path, path + '.bak')
file_str = open(path, 'r').read()
if '\nmolohub:' in file_str:
return
with open(path, 'a') as f:
f.write('\nmolohub:\n')
def delete_file():
delete_list = ['auto_install.py', 'molohub-master.zip', 'molo_install_temp/']
for item in delete_list:
try:
shutil.rmtree(item)
except Exception:
pass
try:
os.remove(item)
except Exception:
pass
if __name__ == '__main__':
path = get_config_path()
if not path:
print("Error finding Home Assistant configuration path!")
print("Install failed.")
exit(0)
uninstall_old(path)
download_file()
extract_file()
copy_file(path)
configurate(path)
delete_file()
print("Successfully installed.")
print("configuration.yaml has backed up to configuration.yaml.bak")
print("For any questions, please contact us:")
print(" - Email: octopus201806@gmail.com")
print(" - QQGroup: 598514359")