epicyon/webapp_minimalbutton.py

47 lines
1.4 KiB
Python
Raw Normal View History

2021-06-25 15:41:31 +00:00
__filename__ = "webapp_minimalbutton.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.2.0"
__maintainer__ = "Bob Mottram"
2021-09-10 16:14:50 +00:00
__email__ = "bob@libreserver.org"
2021-06-25 15:41:31 +00:00
__status__ = "Production"
2021-06-26 11:27:14 +00:00
__module_group__ = "Timeline"
2021-06-25 15:41:31 +00:00
import os
2021-12-26 12:02:29 +00:00
from utils import acct_dir
2021-06-25 15:41:31 +00:00
2021-12-29 21:55:09 +00:00
def is_minimal(base_dir: str, domain: str, nickname: str) -> bool:
2021-06-25 15:41:31 +00:00
"""Returns true if minimal buttons should be shown
for the given account
"""
2021-12-26 12:02:29 +00:00
accountDir = acct_dir(base_dir, nickname, domain)
2021-06-25 15:41:31 +00:00
if not os.path.isdir(accountDir):
return True
minimalFilename = accountDir + '/.notminimal'
if os.path.isfile(minimalFilename):
return False
return True
2021-12-29 21:55:09 +00:00
def set_minimal(base_dir: str, domain: str, nickname: str,
minimal: bool) -> None:
2021-06-25 15:41:31 +00:00
"""Sets whether an account should display minimal buttons
"""
2021-12-26 12:02:29 +00:00
accountDir = acct_dir(base_dir, nickname, domain)
2021-06-25 15:41:31 +00:00
if not os.path.isdir(accountDir):
return
minimalFilename = accountDir + '/.notminimal'
minimalFileExists = os.path.isfile(minimalFilename)
if minimal and minimalFileExists:
try:
os.remove(minimalFilename)
2021-11-25 18:42:38 +00:00
except OSError:
2021-12-29 21:55:09 +00:00
print('EX: set_minimal unable to delete ' + minimalFilename)
2021-06-25 15:41:31 +00:00
elif not minimal and not minimalFileExists:
2021-11-25 18:42:38 +00:00
try:
with open(minimalFilename, 'w+') as fp:
fp.write('\n')
except OSError:
2021-11-25 22:22:54 +00:00
print('EX: unable to write minimal ' + minimalFilename)