__filename__ = "webapp_minimalbutton.py" __author__ = "Bob Mottram" __license__ = "AGPL3+" __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@libreserver.org" __status__ = "Production" __module_group__ = "Timeline" import os from utils import acct_dir def isMinimal(base_dir: str, domain: str, nickname: str) -> bool: """Returns true if minimal buttons should be shown for the given account """ accountDir = acct_dir(base_dir, nickname, domain) if not os.path.isdir(accountDir): return True minimalFilename = accountDir + '/.notminimal' if os.path.isfile(minimalFilename): return False return True def setMinimal(base_dir: str, domain: str, nickname: str, minimal: bool) -> None: """Sets whether an account should display minimal buttons """ accountDir = acct_dir(base_dir, nickname, domain) if not os.path.isdir(accountDir): return minimalFilename = accountDir + '/.notminimal' minimalFileExists = os.path.isfile(minimalFilename) if minimal and minimalFileExists: try: os.remove(minimalFilename) except OSError: print('EX: setMinimal unable to delete ' + minimalFilename) elif not minimal and not minimalFileExists: try: with open(minimalFilename, 'w+') as fp: fp.write('\n') except OSError: print('EX: unable to write minimal ' + minimalFilename)