-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlockServer.py
More file actions
46 lines (38 loc) · 1.2 KB
/
lockServer.py
File metadata and controls
46 lines (38 loc) · 1.2 KB
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
import PortManager
import shelve
urls = ('/lockServer/(.*)','lockServer')
class lockServer:
def GET(self,fileName):
print(fileName + "From Lock server %%%%%%%%%%%%%%%%%")
shelv = shelve.open("lock_Directory.dat")
value = shelv[fileName]
print(value)
try:
if value == 0:
shelv[fileName] = 1
print("**********Success ************")
return 'FileLocked'
elif value == 1:
print("************else ************")
return 'Not'
except:
print('Error while locking')
finally:
shelv.close()
def POST(self,fileName):
print(fileName)
shelv = shelve.open("lock_Directory.dat")
value = shelv[fileName]
#print(value)
try:
if value == 1:
shelv[fileName] = 0
print("*******Success ***********")
return 'FileUnLocked'
except:
print('Error while locking')
finally:
shelv.close()
if __name__=="__main__":
app = PortManager.changePort(urls,globals())
app.run(port=8083)