Improve test for current broch mode

main
Bob Mottram 2021-02-15 23:01:07 +00:00
parent df550f8e65
commit 1adc343ebd
2 changed files with 11 additions and 6 deletions

View File

@ -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

View File

@ -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)