-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
89 lines (67 loc) · 2.05 KB
/
Copy pathsetup.py
File metadata and controls
89 lines (67 loc) · 2.05 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
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
import datetime
import json
import re
import sqlite3
import time
import uuid
import pvporcupine
import openai
import tqdm
from Config import Config
import os
import shutil
import speech_recognition as sr
from pvrecorder import PvRecorder
import speech_recognition as sr
import geocoder
def rmtree_hard(path, _prev=""):
try:
shutil.rmtree(path)
except PermissionError as e:
if e == _prev:
return
match = re.search(r"Access is denied: '(.*)'", str(e))
if match:
file_path = match.group(1)
os.chmod(file_path, 0o777)
# Delete the file
os.remove(file_path)
rmtree_hard(path, _prev=e)
else:
raise e
def setup_database():
open("skills.db", "w").close()
if not os.path.exists("./temp"):
os.makedirs("./temp")
init_temp_path = os.path.join("./temp", str(uuid.uuid4()))
shutil.copy2("./Skills/__init__.py", init_temp_path)
for file in os.listdir("./Skills"):
if os.path.isdir(os.path.join(os.path.abspath("./Skills"), file)):
rmtree_hard(os.path.join(os.path.abspath("./Skills"), file))
shutil.move(init_temp_path, "./Skills/__init__.py")
con = sqlite3.connect("skills.db")
cur = con.cursor()
try:
cur.execute(
"CREATE TABLE actions(skill, action_uuid, action_id, action_name, action_paramiters)"
)
cur.execute("CREATE TABLE installedSkills(skill, version)")
cur.execute("CREATE TABLE requirements(url, name, requiredBy)")
except:
print("already exists")
con.commit()
con.close()
def setup():
config = Config()
setup_database()
g = geocoder.ip("me")
config["TEMPATURE"] = 0.5
config["PV_MIC"] = 1
config["SR_MIC"] = 1
config["CITY"] = g.city
config["COUNTRY"] = g.country
# Check if config is all setup
while True:
if config.isReady():
config["CURRENT_STAGE"] = 2
break