epicyon/webapp_minimalbutton.py

45 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+"
2026-01-02 11:36:24 +00:00
__version__ = "1.7.0"
2021-06-25 15:41:31 +00:00
__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
2026-05-02 09:43:35 +00:00
from data import erase_file
2026-04-28 14:36:12 +00:00
from data import save_flag_file
2026-05-02 11:34:27 +00:00
from data import is_a_file
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'
2026-05-02 11:34:27 +00:00
if is_a_file(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'
2026-05-02 11:34:27 +00:00
minimal_file_exists = is_a_file(minimal_filename)
2022-01-03 23:36:57 +00:00
if minimal and minimal_file_exists:
2026-05-02 09:43:35 +00:00
erase_file(minimal_filename,
'EX: set_minimal unable to delete ' + minimal_filename)
2022-01-03 23:36:57 +00:00
elif not minimal and not minimal_file_exists:
2026-04-28 14:36:12 +00:00
save_flag_file(minimal_filename,
'EX: unable to write minimal ' + minimal_filename)