forked from omaha-consulting/omaha-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac_delete.py
62 lines (52 loc) · 1.56 KB
/
mac_delete.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
from twisted.web import resource
from db_helper import DbHelper
from config import Config
import re, os
class MacDeleteResource(resource.Resource):
pathFromRoot = "/service/admin/mac/delete"
isLeaf = True
def render_GET(self, request):
tr = re.compile('.*/(\d*)$')
m = re.match(tr, request.path)
if len(m.groups()) == 0:
request.setResponseCode(400) # Bad request
return "Error: Bad request."
update_id = m.groups()[0]
macdb = DbHelper()
upd = macdb.fetch_by_id(int(update_id))
if upd == None:
request.setResponseCode(404) # Bad request
return "Error: Not found."
macdb.delete(int(update_id))
try:
activeStream = open(Config.macActiveVersionFile, 'r')
try:
vt = activeStream.readline().strip(' \t\n\r')
finally:
activeStream.close()
if vt == upd['version']:
newLatest = macdb.fetch_latest()
if newLatest == None:
#delete file
os.remove(Config.macActiveVersionFile)
else:
activeStream = open(Config.macActiveVersionFile, 'w')
try:
activeStream.write(newLatest['version'] + '\n')
finally:
activeStream.close()
except IOError:
pass
macdb.cleanup()
return """<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="3;url=/service/admin">
<title>Release notes changed</title>
</head>
<body>
<h1>Success</h1>
<p>Record has been deleted successfully. You will be redirected in 3 seconds.</p>
</body>
</html>
"""