Skip to content

Commit e49cf33

Browse files
authored
Merge pull request #9 from OpenPathView/master
Add autosave arg, Fixes #7
2 parents 9a6d6fc + a7e6dd7 commit e49cf33

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

opv_directorymanagerclient/directorymanagerclient.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,16 @@ def __fetch_protocols(self):
6666

6767
return list(filter(None.__ne__, map(self.__str2Protocol, r.json())))
6868

69-
def Open(self, uuid=None):
69+
def Open(self, uuid=None, autosave=True):
7070
"""
7171
Get a directory form it's uuid or create one.
7272
:param uuid: Optional directory's uuid.
73+
:param autosave: Save back to the server at ext/close (default: True).
7374
"""
7475
if self.__default_protocol == Protocol.FTP:
75-
return DirectoryUuidFtp(uuid=uuid, api_base=self.__api_base, workspace_directory=self.__workspace_directory)
76+
return DirectoryUuidFtp(uuid=uuid, api_base=self.__api_base, workspace_directory=self.__workspace_directory, autosave=autosave)
7677
if self.__default_protocol == Protocol.FILE:
77-
return DirectoryUuidFile(uuid=uuid, api_base=self.__api_base, workspace_directory=self.__workspace_directory)
78+
return DirectoryUuidFile(uuid=uuid, api_base=self.__api_base, workspace_directory=self.__workspace_directory, autosave=autosave)
7879
raise NotImplemented
7980

8081
@property

opv_directorymanagerclient/directoryuuid/directoryuuid.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,21 @@ class DirectoryUuid():
2929
implement a ContextManager that return a (uuid, local path).
3030
"""
3131

32-
def __init__(self, workspace_directory, api_base: str, uuid=None):
32+
def __init__(self, workspace_directory, api_base: str, uuid=None, autosave=True):
3333
"""
3434
:param uuid: Directory UUID.
3535
:param api_base: Api base URL.
3636
:param work_directory: Local directory used to store file. If you use local protocol you may use
3737
a folder on the same partition so that cp will be hard link.
38+
:param autosave: Save changed data on the server at exit or context manager close (Default: True).
3839
"""
3940
self.__api_base = api_base
4041
self.__workspace_directory = workspace_directory
4142
self._uuid = uuid if uuid is not None else self.__generate_uuid()
4243
self._syncable_local = None
4344
self._syncable_remote = None # User need to define it in their implementation
4445
self.__create_local_directory()
46+
self._autosave = autosave
4547

4648
# Fetching files for existing uuids
4749
if uuid is not None:
@@ -181,10 +183,12 @@ def __exit__(self, type, value, traceback):
181183
Context manager.
182184
Save files back to server.
183185
"""
184-
self.save()
186+
if self._autosave:
187+
self.save()
185188

186189
def __del__(self):
187190
"""
188191
Save files back to server. Might not be called.
189192
"""
190-
self.save()
193+
if self._autosave:
194+
self.save()

0 commit comments

Comments
 (0)