-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrmDeviceType.py
More file actions
executable file
·41 lines (26 loc) · 962 Bytes
/
rmDeviceType.py
File metadata and controls
executable file
·41 lines (26 loc) · 962 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
35
36
37
38
39
40
41
#!/usr/bin/env python3
import sys
from argparse import ArgumentParser
from HardwareCheckout.models import DeviceType
from HardwareCheckout.config import db_path
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
parser = ArgumentParser()
parser.add_argument("-t", "--type", help="Device type to add", required=True)
session = sessionmaker(bind=create_engine(db_path))
s = session()
def removeDeviceType(deviceType):
device = s.query(DeviceType).filter_by(name=deviceType).first()
if not device:
print("no device type found - {}!".format(deviceType))
sys.exit(0)
s.delete(device)
s.commit()
def main():
if input("ARE YOU SURE YOU KNOW WHAT YOU ARE DOING? DEVICES COULD BE LOST LIKE THIS! [y/N] ").lower() != 'y':
print("Good, think about what you almost did!")
exit(0)
args = parser.parse_args()
removeDeviceType(args.type)
if __name__ == "__main__":
main()