Skip to content

Commit

Permalink
Allow user to toggle whether files are placed in a timestamped subfol…
Browse files Browse the repository at this point in the history
…der of root_dir or not.
  • Loading branch information
Dave Barnum committed Jan 12, 2018
1 parent 463beac commit 48e8d6c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def __init__(self, keep_dirs):
self._root_dir = configuration.Configuration.get(
'backend_root_dir', not_null=True
)
self._timestamp_subfolder = configuration.Configuration.get(
'backend_timestamp_subfolder', is_bool=True
)
self._keep_dirs = keep_dirs
self._session_name = self._generate_session_name()
Log.verbose(u'Current session: {}'.format(self._session_name))
Expand Down Expand Up @@ -91,13 +94,19 @@ class SimpleBackend(BaseBackend):

def __init__(self, keep_dirs):
super(SimpleBackend, self).__init__(keep_dirs)
self._mkdir(self._session_name)
self._current_dir = os.path.join(self._root_dir, self._session_name)
if (self._timestamp_subfolder):
self._mkdir(self._session_name)
self._current_dir = os.path.join(self._root_dir, self._session_name)
else:
self._current_dir = os.path.join(self._root_dir)
Log.debug('SimpleBackend loaded')

def save(self, user, document):
path = self._get_path(user, document)
self._mkdir(os.path.join(self._session_name, path))
if (self._timestamp_subfolder):
self._mkdir(os.path.join(self._session_name, path))
else:
self._mkdir(os.path.join(path))
prefix = os.path.join(self._current_dir, path)
for document_content in document.contents:
path = os.path.join(prefix, document_content.file_name)
Expand Down
2 changes: 2 additions & 0 deletions settings.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ backend:
# optional: compression format, is 'compression' is set to 'True'
# must be either gz or bz2, defaults to gz
compression_format: 'gz'
# optional: Create timestamped sub-folder in root_dir path for each run.
timestamp_subfolder: 'True'

0 comments on commit 48e8d6c

Please sign in to comment.