-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.py
executable file
·95 lines (71 loc) · 2.47 KB
/
controller.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
from database import db_session
from models import User, Process, START, SCANNED, END, convertTime
import time
import os
from sqlalchemy import or_
def verify_password(user_id, password):
query = db_session.query(User)
result = query.filter(User.user_id == user_id).filter(User.password == password).first()
if result:
return result
else:
return None
def verify_register(user):
query = db_session.query(User)
result = query.filter(User.user_id == user.user_id).first()
print('result {0}'.format(result))
if result != None:
return False
else:
return True
def getInstanceOfUser(user_id):
query = db_session.query(User)
result = query.get(user_id)
return result
def add_user(user):
db_session.add(user)
db_session.commit()
##Process
def addNewProcess(user_id, process_id):
process = Process(process_id, user_id)
db_session.add(process)
db_session.commit()
def scanProcess(process_id):
query = db_session.query(Process)
print('process_id {0} need to be scanned'.format(process_id))
result = query.filter(Process.process_id==process_id).first()
print('scanProcess {0}'.format(result) )
result.status = SCANNED
db_session.commit()
def endProcess(user_id):
query = db_session.query(Process)
results = query.filter(Process.user_id==user_id).all()
##找出属于这个用户的所有进程,然后一个一个判断是否进程存在,存在就杀掉,不存在抛出异常继续
for result in results:
try:
result.status = END
result.end_time = convertTime(time.time())
print("process_id to be killed is {0}".format(result.process_id))
checkProcess = os.kill(result.process_id, 0)
except OSError:
continue
else:
os.kill(result.process_id, 9)
db_session.commit()
def checkWhetherScanned(user_id):
query =db_session.query(Process)
result = query.filter(Process.user_id == user_id).filter(Process.status == SCANNED).first()
print(result)
if result != None:
return True
else:
return False
def startNewProcessPermission(user_id):
query = db_session.query(Process)
result = query.filter(Process.user_id == user_id).filter(or_(Process.status == START, Process.status == SCANNED)).first()
if result is None:
return True
else:
print ("user_id={0}".format(user_id))
print(result)
return False