Skip to content

Commit

Permalink
automatically save project name to .olproject_name
Browse files Browse the repository at this point in the history
  • Loading branch information
zzjjzzgggg committed Dec 4, 2023
1 parent b4d62fb commit 3d72480
Show file tree
Hide file tree
Showing 2 changed files with 239 additions and 98 deletions.
24 changes: 23 additions & 1 deletion olcesync/olsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def main(ctx, local, remote, project_name, cookie_path, sync_path, olignore_path
# Change the current directory to the specified sync path
os.chdir(sync_path)

project_name = project_name or os.path.basename(os.getcwd())
project_name = get_project_name(project_name)
print("Using project name:", project_name)
project = execute_action(
lambda: overleaf_client.get_project(project_name), "Querying project",
"Project queried successfully.", "Project could not be queried.",
Expand Down Expand Up @@ -482,5 +483,26 @@ def olignore_keep_list(olignore_path):
return keep_list


def save_project_name(project_name):
with open(".olproject_name", "w") as fw:
fw.write(project_name)


def get_project_name(project_name):
"""If the project_name is provided, save it to file ".olproject_name".
Otherwise, try to read it from ".olproject_name". If the project_name is still
empty, then use currrent folder name.
"""
if project_name:
with open(".olproject_name", "w") as fw:
fw.write(project_name)
elif os.path.isfile(".olproject_name"):
with open(".olproject_name", 'r') as f:
project_name = f.read().rstrip()
project_name = project_name or os.path.basename(os.getcwd())
return project_name


if __name__ == "__main__":
main()
Loading

0 comments on commit 3d72480

Please sign in to comment.