mirror of https://gitlab.com/bashrc2/epicyon
Improve test for current broch mode
parent
df550f8e65
commit
1adc343ebd
13
blocking.py
13
blocking.py
|
@ -415,28 +415,31 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None:
|
|||
setConfigParam(baseDir, "brochMode", enabled)
|
||||
|
||||
|
||||
def brochModeLapses(baseDir: str, lapseDays=7) -> None:
|
||||
def brochModeLapses(baseDir: str, lapseDays=7) -> bool:
|
||||
"""After broch mode is enabled it automatically
|
||||
elapses after a period of time
|
||||
"""
|
||||
allowFilename = baseDir + '/accounts/allowedinstances.txt'
|
||||
if not os.path.isfile(allowFilename):
|
||||
return
|
||||
return False
|
||||
lastModified = fileLastModified(allowFilename)
|
||||
modifiedDate = None
|
||||
brochMode = True
|
||||
try:
|
||||
modifiedDate = \
|
||||
datetime.strptime(lastModified, "%Y-%m-%dT%H:%M:%SZ")
|
||||
except BaseException:
|
||||
return
|
||||
return brochMode
|
||||
if not modifiedDate:
|
||||
return
|
||||
return brochMode
|
||||
currTime = datetime.datetime.utcnow()
|
||||
daysSinceBroch = (currTime - modifiedDate).days
|
||||
if daysSinceBroch >= lapseDays:
|
||||
try:
|
||||
os.remove(allowFilename)
|
||||
setConfigParam(baseDir, "brochMode", False)
|
||||
brochMode = False
|
||||
setConfigParam(baseDir, "brochMode", brochMode)
|
||||
print('Broch mode has elapsed')
|
||||
except BaseException:
|
||||
pass
|
||||
return brochMode
|
||||
|
|
|
@ -4548,7 +4548,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
if fields.get('brochMode'):
|
||||
if fields['brochMode'] == 'on':
|
||||
brochMode = True
|
||||
if brochMode != self.server.brochMode:
|
||||
currBrochMode = \
|
||||
getConfigParam(baseDir, "brochMode")
|
||||
if brochMode != currBrochMode:
|
||||
setBrochMode(self.server.baseDir,
|
||||
self.server.domainFull,
|
||||
brochMode)
|
||||
|
|
Loading…
Reference in New Issue