2018-02-08 16:12:38 +00:00
|
|
|
import os
|
|
|
|
|
2018-02-08 16:22:56 +00:00
|
|
|
class Locker:
|
2018-02-09 12:18:10 +00:00
|
|
|
def createlock(self, lockfile, position, date=0):
|
2018-02-08 16:12:38 +00:00
|
|
|
try:
|
|
|
|
if os.path.exists(lockfile):
|
|
|
|
f = open(lockfile, "r+")
|
|
|
|
return f.read()
|
|
|
|
else:
|
|
|
|
f = open(lockfile, "w")
|
2018-02-09 12:18:10 +00:00
|
|
|
f.write(str(date))
|
2018-02-08 16:12:38 +00:00
|
|
|
except BaseException as e:
|
|
|
|
raise("Can't create or read the lock file: {0}".format(e))
|
|
|
|
|
2018-02-09 12:18:10 +00:00
|
|
|
def unlock(self, lockfile, position):
|
2018-02-08 16:12:38 +00:00
|
|
|
try:
|
|
|
|
os.remove(lockfile)
|
|
|
|
except BaseException as e:
|
2018-02-09 12:18:10 +00:00
|
|
|
if position != "startup":
|
|
|
|
print("Can't delete the lock file: {0}".format(e))
|