-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·34 lines (27 loc) · 821 Bytes
/
setup.py
File metadata and controls
executable file
·34 lines (27 loc) · 821 Bytes
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
#!/usr/bin/env python3
import argparse
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from HardwareCheckout.models import Role, db
from HardwareCheckout.config import db_path
parser = argparse.ArgumentParser()
parser.add_argument(
"-c", "--clean", help="remove existing database if it exists", action="store_true"
)
args = parser.parse_args()
if args.clean:
if os.path.isfile(db_path[9:]):
os.unlink(db_path[9:])
else:
db.drop_all()
try:
db.create_all()
session = sessionmaker(bind=create_engine(db_path))
s = session()
s.add(Role(name="Human"))
s.add(Role(name="Device"))
s.add(Role(name="Admin"))
s.commit()
except Exception as e:
print("Caught the following exception. Does the DB already exist?\n{}".format(e))