Skip to content

Commit

Permalink
Merge pull request #173 from dbcli/optional-config
Browse files Browse the repository at this point in the history
Do not crash if ~/.config/litecli is not writeable.
  • Loading branch information
amjith authored Mar 4, 2024
2 parents b183f86 + e2a58c0 commit 1b5cf27
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Next Release - [TBD]

### Bug Fixes

* Do not crash at start up if ~/.config/litecli is not writeable. [#172](https://github.com/dbcli/litecli/issues/172)


## 1.10.0 - 2022-11-19

### Features
Expand Down
6 changes: 5 additions & 1 deletion litecli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def get_config(liteclirc_file=None):
liteclirc_file = liteclirc_file or "%sconfig" % config_location()

default_config = os.path.join(package_root, "liteclirc")
write_default_config(default_config, liteclirc_file)
try:
write_default_config(default_config, liteclirc_file)
except OSError:
# If we can't write to the config file, just use the default config
return load_config(default_config)

return load_config(liteclirc_file, default_config)
6 changes: 5 additions & 1 deletion litecli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ def initialize_logging(self):
log_file = self.config["main"]["log_file"]
if log_file == "default":
log_file = config_location() + "log"
ensure_dir_exists(log_file)
try:
ensure_dir_exists(log_file)
except OSError:
# Unable to create log file, log to temp directory instead.
log_file = "/tmp/litecli.log"

log_level = self.config["main"]["log_level"]

Expand Down

0 comments on commit 1b5cf27

Please sign in to comment.