def setup_sync_dir(self):
self.cache_dir = appdirs.user_cache_dir("studip", "fknorr")
self.create_path(self.cache_dir)
history_file_name = os.path.join(appdirs.user_cache_dir("studip", "fknorr"), "history")
history = []
try:
with open(history_file_name, "r", encoding="utf-8") as file:
history = list(filter(None, file.read().splitlines()))
except Exception:
pass
skipped_history = 0
if "sync_dir" in self.command_line:
sync_dir = self.command_line["sync_dir"]
else:
if history and os.path.isdir(history[0]):
sync_dir = history[0]
print("Using last sync directory {} ...".format(sync_dir))
else:
skipped_history = 1
default_dir = "~/StudIP"
for entry in history[1:]:
skipped_history += 1
if os.path.isdir(entry):
default_dir = entry
sync_dir = input("Sync directory [{}]: ".format(default_dir))
if not sync_dir:
sync_dir = default_dir
sync_dir = os.path.abspath(os.path.expanduser(sync_dir))
history = history[skipped_history:]
while sync_dir in history:
history.remove(sync_dir)
history.insert(0, sync_dir)
self.sync_dir = sync_dir
try:
with open(history_file_name, "w", encoding="utf-8") as file:
file.write("\n".join(history) + "\n")
except Exception as e:
self.print_io_error("Unable to write to", history_file_name, e)
raise ApplicationExit()
self.dot_dir = os.path.join(self.sync_dir, ".studip")
self.create_path(self.dot_dir)
self.config_file_name = os.path.join(self.dot_dir, "studip.conf")
self.db_file_name = os.path.join(self.dot_dir, "cache.sqlite")
评论列表
文章目录