|
13 | 13 | __all__ = ["get_bookmarks", "add_bookmarks", "delete_bookmarks",
|
14 | 14 | "list_bookmarks"]
|
15 | 15 |
|
16 |
| -CONFIG_FILENAME = os.path.join(os.path.expanduser("~"), ".gitup") |
17 |
| - |
18 | 16 | YELLOW = Fore.YELLOW + Style.BRIGHT
|
19 | 17 | RED = Fore.RED + Style.BRIGHT
|
20 | 18 |
|
21 | 19 | INDENT1 = " " * 3
|
22 | 20 |
|
| 21 | +def _get_config_path(): |
| 22 | + """Return the path to the configuration file.""" |
| 23 | + xdg_cfg = os.environ.get("XDG_CONFIG_HOME") or os.path.join("~", ".config") |
| 24 | + return os.path.join(os.path.expanduser(xdg_cfg), "gitup", "config.ini") |
| 25 | + |
23 | 26 | def _load_config_file():
|
24 | 27 | """Read the config file and return a SafeConfigParser() object."""
|
25 | 28 | config = configparser.SafeConfigParser()
|
26 | 29 | # Don't lowercase option names, because we are storing paths there:
|
27 | 30 | config.optionxform = str
|
28 |
| - config.read(CONFIG_FILENAME) |
| 31 | + config.read(_get_config_path()) |
29 | 32 | return config
|
30 | 33 |
|
31 | 34 | def _save_config_file(config):
|
32 |
| - """Save config changes to the config file specified by CONFIG_FILENAME.""" |
33 |
| - with open(CONFIG_FILENAME, "wb") as config_file: |
| 35 | + """Save config changes to the config file returned by _get_config_path.""" |
| 36 | + cfg_path = _get_config_path() |
| 37 | + if not os.path.exists(os.path.dirname(cfg_path)): # Race condition, meh... |
| 38 | + os.makedirs(os.path.dirname(cfg_path)) |
| 39 | + |
| 40 | + with open(cfg_path, "wb") as config_file: |
34 | 41 | config.write(config_file)
|
35 | 42 |
|
36 | 43 | def get_bookmarks():
|
|
0 commit comments