Skip to content

Commit

Permalink
Merge pull request #20 from kewlfft/feature/localdir
Browse files Browse the repository at this point in the history
use of data dir for log files
  • Loading branch information
KenKundert committed Sep 22, 2019
2 parents 9685b82 + 7dd2257 commit 25ee122
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 3 additions & 1 deletion emborg/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with this program. If not, see http://www.gnu.org/licenses/.

# Imports {{{1
from appdirs import user_config_dir
from appdirs import user_config_dir, user_data_dir
from textwrap import dedent

# Preferences {{{1
Expand All @@ -29,9 +29,11 @@
BORG = 'borg'

CONFIG_DIR = user_config_dir(PROGRAM_NAME)
DATA_DIR = user_data_dir(PROGRAM_NAME)

SETTINGS_FILE = 'settings'
OVERDUE_FILE = 'overdue.conf'

LOG_FILE = '{config_name}.log'
PREV_LOG_FILE = '{config_name}.log.prev'
LOCK_FILE = '{config_name}.lock'
Expand Down
17 changes: 11 additions & 6 deletions emborg/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
BORG,
BORG_SETTINGS,
CONFIG_DIR,
DATA_DIR,
CONFIGS_SETTING,
convert_name_to_option,
DATE_FILE,
Expand Down Expand Up @@ -418,24 +419,28 @@ def __enter__(self):
self.archive = self.resolve(self.archive)

# resolve other files and directories
config_dir = self.resolve(CONFIG_DIR)
self.config_dir = to_path(config_dir, config_dir)
data_dir = self.resolve(DATA_DIR)
self.data_dir = to_path(data_dir, data_dir)

if not self.data_dir.exists():
# config dir does not exist, create and populate it
self.data_dir.mkdir(mode=0o700, parents=True, exist_ok=True)

logfile = self.resolve(LOG_FILE)
self.logfile = to_path(config_dir, logfile)
self.logfile = to_path(data_dir, logfile)

if 'no-log' not in self.options:
prev_logfile = self.resolve(PREV_LOG_FILE)
self.prev_logfile = to_path(config_dir, prev_logfile)
self.prev_logfile = to_path(data_dir, prev_logfile)
rm(self.prev_logfile)
if self.logfile.exists():
mv(self.logfile, self.prev_logfile)

date_file = self.resolve(DATE_FILE)
self.date_file = to_path(config_dir, date_file)
self.date_file = to_path(data_dir, date_file)

# perform locking
lockfile = self.lockfile = to_path(config_dir, self.resolve(LOCK_FILE))
lockfile = self.lockfile = to_path(data_dir, self.resolve(LOCK_FILE))
if self.requires_exclusivity:
# check for existance of lockfile
if lockfile.exists():
Expand Down

0 comments on commit 25ee122

Please sign in to comment.