Improve test for current broch mode

merge-requests/18/head
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) 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 """After broch mode is enabled it automatically
elapses after a period of time elapses after a period of time
""" """
allowFilename = baseDir + '/accounts/allowedinstances.txt' allowFilename = baseDir + '/accounts/allowedinstances.txt'
if not os.path.isfile(allowFilename): if not os.path.isfile(allowFilename):
return return False
lastModified = fileLastModified(allowFilename) lastModified = fileLastModified(allowFilename)
modifiedDate = None modifiedDate = None
brochMode = True
try: try:
modifiedDate = \ modifiedDate = \
datetime.strptime(lastModified, "%Y-%m-%dT%H:%M:%SZ") datetime.strptime(lastModified, "%Y-%m-%dT%H:%M:%SZ")
except BaseException: except BaseException:
return return brochMode
if not modifiedDate: if not modifiedDate:
return return brochMode
currTime = datetime.datetime.utcnow() currTime = datetime.datetime.utcnow()
daysSinceBroch = (currTime - modifiedDate).days daysSinceBroch = (currTime - modifiedDate).days
if daysSinceBroch >= lapseDays: if daysSinceBroch >= lapseDays:
try: try:
os.remove(allowFilename) os.remove(allowFilename)
setConfigParam(baseDir, "brochMode", False) brochMode = False
setConfigParam(baseDir, "brochMode", brochMode)
print('Broch mode has elapsed') print('Broch mode has elapsed')
except BaseException: except BaseException:
pass pass
return brochMode

View File

@ -4548,7 +4548,9 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('brochMode'): if fields.get('brochMode'):
if fields['brochMode'] == 'on': if fields['brochMode'] == 'on':
brochMode = True brochMode = True
if brochMode != self.server.brochMode: currBrochMode = \
getConfigParam(baseDir, "brochMode")
if brochMode != currBrochMode:
setBrochMode(self.server.baseDir, setBrochMode(self.server.baseDir,
self.server.domainFull, self.server.domainFull,
brochMode) brochMode)