epicyon/webapp_minimalbutton.py

47 lines
1.5 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
"""
2022-01-03 23:36:57 +00:00
account_dir = acct_dir(base_dir, nickname, domain)
if not os.path.isdir(account_dir):
2021-06-25 15:41:31 +00:00
return True
2022-01-03 23:36:57 +00:00
minimal_filename = account_dir + '/.notminimal'
if os.path.isfile(minimal_filename):
2021-06-25 15:41:31 +00:00
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
"""
2022-01-03 23:36:57 +00:00
account_dir = acct_dir(base_dir, nickname, domain)
if not os.path.isdir(account_dir):
2021-06-25 15:41:31 +00:00
return
2022-01-03 23:36:57 +00:00
minimal_filename = account_dir + '/.notminimal'
minimal_file_exists = os.path.isfile(minimal_filename)
if minimal and minimal_file_exists:
try:
2022-01-03 23:36:57 +00:00
os.remove(minimal_filename)
2021-11-25 18:42:38 +00:00
except OSError:
2022-01-03 23:36:57 +00:00
print('EX: set_minimal unable to delete ' + minimal_filename)
elif not minimal and not minimal_file_exists:
2021-11-25 18:42:38 +00:00
try:
2022-01-03 23:36:57 +00:00
with open(minimal_filename, 'w+') as fp_min:
fp_min.write('\n')
2021-11-25 18:42:38 +00:00
except OSError:
2022-01-03 23:36:57 +00:00
print('EX: unable to write minimal ' + minimal_filename)