diff --git a/opv_directorymanagerclient/directorymanagerclient.py b/opv_directorymanagerclient/directorymanagerclient.py index 7957d8d..64f3eff 100644 --- a/opv_directorymanagerclient/directorymanagerclient.py +++ b/opv_directorymanagerclient/directorymanagerclient.py @@ -66,15 +66,16 @@ def __fetch_protocols(self): return list(filter(None.__ne__, map(self.__str2Protocol, r.json()))) - def Open(self, uuid=None): + def Open(self, uuid=None, autosave=True): """ Get a directory form it's uuid or create one. :param uuid: Optional directory's uuid. + :param autosave: Save back to the server at ext/close (default: True). """ if self.__default_protocol == Protocol.FTP: - return DirectoryUuidFtp(uuid=uuid, api_base=self.__api_base, workspace_directory=self.__workspace_directory) + return DirectoryUuidFtp(uuid=uuid, api_base=self.__api_base, workspace_directory=self.__workspace_directory, autosave=autosave) if self.__default_protocol == Protocol.FILE: - return DirectoryUuidFile(uuid=uuid, api_base=self.__api_base, workspace_directory=self.__workspace_directory) + return DirectoryUuidFile(uuid=uuid, api_base=self.__api_base, workspace_directory=self.__workspace_directory, autosave=autosave) raise NotImplemented @property diff --git a/opv_directorymanagerclient/directoryuuid/directoryuuid.py b/opv_directorymanagerclient/directoryuuid/directoryuuid.py index 8f87902..5c57d9c 100644 --- a/opv_directorymanagerclient/directoryuuid/directoryuuid.py +++ b/opv_directorymanagerclient/directoryuuid/directoryuuid.py @@ -29,12 +29,13 @@ class DirectoryUuid(): implement a ContextManager that return a (uuid, local path). """ - def __init__(self, workspace_directory, api_base: str, uuid=None): + def __init__(self, workspace_directory, api_base: str, uuid=None, autosave=True): """ :param uuid: Directory UUID. :param api_base: Api base URL. :param work_directory: Local directory used to store file. If you use local protocol you may use a folder on the same partition so that cp will be hard link. + :param autosave: Save changed data on the server at exit or context manager close (Default: True). """ self.__api_base = api_base self.__workspace_directory = workspace_directory @@ -42,6 +43,7 @@ def __init__(self, workspace_directory, api_base: str, uuid=None): self._syncable_local = None self._syncable_remote = None # User need to define it in their implementation self.__create_local_directory() + self._autosave = autosave # Fetching files for existing uuids if uuid is not None: @@ -181,10 +183,12 @@ def __exit__(self, type, value, traceback): Context manager. Save files back to server. """ - self.save() + if self._autosave: + self.save() def __del__(self): """ Save files back to server. Might not be called. """ - self.save() + if self._autosave: + self.save()