Skip to content
Snippets Groups Projects
Commit d2898f3b authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Be more helpful on Permission error

parent dbbb6f77
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python #!/usr/bin/env python
#-*- coding: utf-8 -*- #-*- coding: utf-8 -*-
import os, sys, ast import os, sys, ast, getpass
import toml import toml
from pathlib import Path from pathlib import Path
...@@ -75,8 +75,13 @@ def initialize_config(application_name: str, default_config: str) -> dict: ...@@ -75,8 +75,13 @@ def initialize_config(application_name: str, default_config: str) -> dict:
# Create the config_dir if it doesn't exist # Create the config_dir if it doesn't exist
if not Path.is_dir(Path(config_dir)): if not Path.is_dir(Path(config_dir)):
try:
Path(config_dir).mkdir(parents=True, exist_ok=True) Path(config_dir).mkdir(parents=True, exist_ok=True)
print("Config directory didn't exist, created directory: {}".format(config_dir)) print("Config directory didn't exist, created directory: {}".format(config_dir))
except PermissionError as e:
print("Error: Not sufficient permissions to create config directory at {} (Running {} as user {})".format(config_dir, application_name, getpass.getuser()), file=sys.stderr)
print("Consider creating {} manually with write permissions for {}. After initial write of default config.toml on the first run {} won't write that file ever again".format(config_dir, getpass.getuser(), application_name), file=sys.stderr)
exit(1)
# Create a default config if it does exist # Create a default config if it does exist
if not Path.is_file(Path(config_path)): if not Path.is_file(Path(config_path)):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment