Skip to content

Create directories before saving credentials #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion td/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,15 @@ def _state_manager(self, action: str) -> None:
self.state.update(json.load(json_file))

# if they want to save it and have allowed for caching then load the file.
elif action == 'save':
elif action == 'save':
# Create parent directory if it doesn't exist
if not credentials_file_exists:
try:
os.makedirs(os.path.dirname(self.credentials_path))
except OSError as exc: # Guard against race condition
if exc.errno != errno.EEXIST:
raise
# Save file
with open(file=self.credentials_path, mode='w+') as json_file:
json.dump(obj=self.state, fp=json_file, indent=4)

Expand Down