-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
55 lines (43 loc) · 1.73 KB
/
__init__.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
import os
import platform
has_venv = os.path.exists('./venv/')
def main():
if not has_venv:
print("Creating venv...")
os.system("python3 -m venv venv")
print("Activating venv...")
# Darwin == Mac
if platform.system() == 'Darwin':
os.system("source venv/bin/activate")
else:
os.system("venv/Scripts/activate")
print("Installing requirements...")
os.system("pip3 install -r requirements.txt")
# run current file again but with installed venv
os.system(f"python3 {os.path.basename(__file__)}")
else:
import pymysql
from dotenv import load_dotenv
from server.models.group import Group
from server.models.task import Task
from server.models.user import User
from server.models.basic_model import db
load_dotenv(os.path.join(os.path.dirname(__file__), '.env'))
print("Creating DATABASE todosy")
conn = pymysql.connect(
host=os.environ.get("DB_HOST"),
user=os.environ.get("DB_USER"),
password=os.environ.get("DB_PASSWORD")
)
conn.cursor().execute('CREATE DATABASE todosy')
conn.close()
print("Creating TABLES user, group, task")
db.connect()
db.create_tables([User, Group, Task])
print("Creating default user and groups (work and leisure)")
user = User.create(email="[email protected]", name="name", surname="surname", password="super mega pass")
Group.create(title="Work", color="#412344", owner=user.id)
Group.create(title="Leisure", color="#2D3923", owner=user.id)
Group.create(title="CMS", color="#f98012", owner=user.id)
if __name__ == "__main__":
main()