Make /storage/filesystem more flexible

by adding the optional fileignoreext parameter.
This commit is contained in:
Bernhard Reiter 2021-05-19 18:00:09 +02:00
parent 439e63f8ea
commit 81895c291e
No known key found for this signature in database
GPG key ID: 2B7BA3BF9BC3A554
2 changed files with 7 additions and 2 deletions

View file

@ -408,6 +408,7 @@ Local
fileext = "..." fileext = "..."
#encoding = "utf-8" #encoding = "utf-8"
#post_hook = null #post_hook = null
#fileextignore = ".tmp"
Can be used with `khal <http://lostpackets.de/khal/>`_. See :doc:`vdir` for Can be used with `khal <http://lostpackets.de/khal/>`_. See :doc:`vdir` for
a more formal description of the format. a more formal description of the format.
@ -426,6 +427,8 @@ Local
:param post_hook: A command to call for each item creation and :param post_hook: A command to call for each item creation and
modification. The command will be called with the path of the modification. The command will be called with the path of the
new/updated file. new/updated file.
:param fileextignore: The file extention to ignore,
the default is ``.tmp``.
.. storage:: singlefile .. storage:: singlefile

View file

@ -22,13 +22,15 @@ class FilesystemStorage(Storage):
storage_name = "filesystem" storage_name = "filesystem"
_repr_attributes = ("path",) _repr_attributes = ("path",)
def __init__(self, path, fileext, encoding="utf-8", post_hook=None, **kwargs): def __init__(self, path, fileext,
encoding="utf-8", post_hook=None, fileignoreext=".tmp", **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
path = expand_path(path) path = expand_path(path)
checkdir(path, create=False) checkdir(path, create=False)
self.path = path self.path = path
self.encoding = encoding self.encoding = encoding
self.fileext = fileext self.fileext = fileext
self.fileignoreext = fileignoreext
self.post_hook = post_hook self.post_hook = post_hook
@classmethod @classmethod
@ -81,7 +83,7 @@ class FilesystemStorage(Storage):
for fname in os.listdir(self.path): for fname in os.listdir(self.path):
fpath = os.path.join(self.path, fname) fpath = os.path.join(self.path, fname)
if os.path.isfile(fpath) and fname.endswith(self.fileext) and ( if os.path.isfile(fpath) and fname.endswith(self.fileext) and (
not fname.endswith('.tmp')): not fname.endswith(self.fileignoreext)):
yield fname, get_etag_from_file(fpath) yield fname, get_etag_from_file(fpath)
def get(self, href): def get(self, href):