Move more shared code to this module.

This commit is contained in:
Philippe Tourigny 2022-07-16 13:51:06 +09:00
parent 5c3a316311
commit e9a91e51b4

View File

@ -21,15 +21,22 @@ def read_config(configfile):
return parser return parser
def set_basepath(candidates): def set_basepath(configpath):
'''Define the default starting path for documents.''' '''Define the default starting path for documents.
Each tool reads the applicable configuration path from the
configuration file and passes it to this function.
'''
# Give priority to path set in config file, if valid. # Give priority to path set in config file, if valid.
# If not, use the user's 'Documents' folder if it exists, # If not, use the user's 'Documents' folder if it exists,
# and the user folder if not, as a default. # and the user folder if not, as a default.
candidates = [configpath, DEFAULT_DOCHOME, USER_HOME]
basepath = None basepath = None
# Read each candidate path in term, and set the first valid path
# as the basepath
while basepath is None: while basepath is None:
if candidates[0].exists(): if candidates[0].exists():
basepath = candidates[0] basepath = candidates[0]