OP-3405 - refactor - updated methods signature

Renamed collection to project_name as when we are leaving MongoDB, collection doesnt make much sense.
This commit is contained in:
Petr Kalis 2022-08-02 12:25:51 +02:00
parent 0f5ec0f0c4
commit 89bd23856c
8 changed files with 164 additions and 162 deletions

View file

@ -62,7 +62,7 @@ class AbstractProvider:
@abc.abstractmethod
def upload_file(self, source_path, path,
server, collection, file, representation, site,
server, project_name, file, representation, site,
overwrite=False):
"""
Copy file from 'source_path' to 'target_path' on provider.
@ -75,7 +75,7 @@ class AbstractProvider:
arguments for saving progress:
server (SyncServer): server instance to call update_db on
collection (str): name of collection
project_name (str): name of project_name
file (dict): info about uploaded file (matches structure from db)
representation (dict): complete repre containing 'file'
site (str): site name
@ -87,7 +87,7 @@ class AbstractProvider:
@abc.abstractmethod
def download_file(self, source_path, local_path,
server, collection, file, representation, site,
server, project_name, file, representation, site,
overwrite=False):
"""
Download file from provider into local system
@ -99,7 +99,7 @@ class AbstractProvider:
arguments for saving progress:
server (SyncServer): server instance to call update_db on
collection (str): name of collection
project_name (str):
file (dict): info about uploaded file (matches structure from db)
representation (dict): complete repre containing 'file'
site (str): site name

View file

@ -224,7 +224,7 @@ class DropboxHandler(AbstractProvider):
return False
def upload_file(self, source_path, path,
server, collection, file, representation, site,
server, project_name, file, representation, site,
overwrite=False):
"""
Copy file from 'source_path' to 'target_path' on provider.
@ -237,7 +237,7 @@ class DropboxHandler(AbstractProvider):
arguments for saving progress:
server (SyncServer): server instance to call update_db on
collection (str): name of collection
project_name (str):
file (dict): info about uploaded file (matches structure from db)
representation (dict): complete repre containing 'file'
site (str): site name
@ -290,7 +290,7 @@ class DropboxHandler(AbstractProvider):
cursor.offset = f.tell()
server.update_db(
collection=collection,
project_name=project_name,
new_file_id=None,
file=file,
representation=representation,
@ -301,7 +301,7 @@ class DropboxHandler(AbstractProvider):
return path
def download_file(self, source_path, local_path,
server, collection, file, representation, site,
server, project_name, file, representation, site,
overwrite=False):
"""
Download file from provider into local system
@ -313,7 +313,7 @@ class DropboxHandler(AbstractProvider):
arguments for saving progress:
server (SyncServer): server instance to call update_db on
collection (str): name of collection
project_name (str):
file (dict): info about uploaded file (matches structure from db)
representation (dict): complete repre containing 'file'
site (str): site name
@ -337,7 +337,7 @@ class DropboxHandler(AbstractProvider):
self.dbx.files_download_to_file(local_path, source_path)
server.update_db(
collection=collection,
project_name=project_name,
new_file_id=None,
file=file,
representation=representation,

View file

@ -251,7 +251,7 @@ class GDriveHandler(AbstractProvider):
return folder_id
def upload_file(self, source_path, path,
server, collection, file, representation, site,
server, project_name, file, representation, site,
overwrite=False):
"""
Uploads single file from 'source_path' to destination 'path'.
@ -264,7 +264,7 @@ class GDriveHandler(AbstractProvider):
arguments for saving progress:
server (SyncServer): server instance to call update_db on
collection (str): name of collection
project_name (str):
file (dict): info about uploaded file (matches structure from db)
representation (dict): complete repre containing 'file'
site (str): site name
@ -324,7 +324,7 @@ class GDriveHandler(AbstractProvider):
while response is None:
if server.is_representation_paused(representation['_id'],
check_parents=True,
project_name=collection):
project_name=project_name):
raise ValueError("Paused during process, please redo.")
if status:
status_val = float(status.progress())
@ -333,7 +333,7 @@ class GDriveHandler(AbstractProvider):
last_tick = time.time()
log.debug("Uploaded %d%%." %
int(status_val * 100))
server.update_db(collection=collection,
server.update_db(project_name=project_name,
new_file_id=None,
file=file,
representation=representation,
@ -358,7 +358,7 @@ class GDriveHandler(AbstractProvider):
return response['id']
def download_file(self, source_path, local_path,
server, collection, file, representation, site,
server, project_name, file, representation, site,
overwrite=False):
"""
Downloads single file from 'source_path' (remote) to 'local_path'.
@ -372,7 +372,7 @@ class GDriveHandler(AbstractProvider):
arguments for saving progress:
server (SyncServer): server instance to call update_db on
collection (str): name of collection
project_name (str):
file (dict): info about uploaded file (matches structure from db)
representation (dict): complete repre containing 'file'
site (str): site name
@ -410,7 +410,7 @@ class GDriveHandler(AbstractProvider):
while response is None:
if server.is_representation_paused(representation['_id'],
check_parents=True,
project_name=collection):
project_name=project_name):
raise ValueError("Paused during process, please redo.")
if status:
status_val = float(status.progress())
@ -419,7 +419,7 @@ class GDriveHandler(AbstractProvider):
last_tick = time.time()
log.debug("Downloaded %d%%." %
int(status_val * 100))
server.update_db(collection=collection,
server.update_db(project_name=project_name,
new_file_id=None,
file=file,
representation=representation,

View file

@ -82,7 +82,7 @@ class LocalDriveHandler(AbstractProvider):
return editable
def upload_file(self, source_path, target_path,
server, collection, file, representation, site,
server, project_name, file, representation, site,
overwrite=False, direction="Upload"):
"""
Copies file from 'source_path' to 'target_path'
@ -95,7 +95,7 @@ class LocalDriveHandler(AbstractProvider):
thread = threading.Thread(target=self._copy,
args=(source_path, target_path))
thread.start()
self._mark_progress(collection, file, representation, server,
self._mark_progress(project_name, file, representation, server,
site, source_path, target_path, direction)
else:
if os.path.exists(target_path):
@ -105,13 +105,13 @@ class LocalDriveHandler(AbstractProvider):
return os.path.basename(target_path)
def download_file(self, source_path, local_path,
server, collection, file, representation, site,
server, project_name, file, representation, site,
overwrite=False):
"""
Download a file form 'source_path' to 'local_path'
"""
return self.upload_file(source_path, local_path,
server, collection, file, representation, site,
server, project_name, file, representation, site,
overwrite, direction="Download")
def delete_file(self, path):
@ -188,7 +188,7 @@ class LocalDriveHandler(AbstractProvider):
except shutil.SameFileError:
print("same files, skipping")
def _mark_progress(self, collection, file, representation, server, site,
def _mark_progress(self, project_name, file, representation, server, site,
source_path, target_path, direction):
"""
Updates progress field in DB by values 0-1.
@ -204,7 +204,7 @@ class LocalDriveHandler(AbstractProvider):
status_val = target_file_size / source_file_size
last_tick = time.time()
log.debug(direction + "ed %d%%." % int(status_val * 100))
server.update_db(collection=collection,
server.update_db(project_name=project_name,
new_file_id=None,
file=file,
representation=representation,

View file

@ -222,7 +222,7 @@ class SFTPHandler(AbstractProvider):
return os.path.basename(path)
def upload_file(self, source_path, target_path,
server, collection, file, representation, site,
server, project_name, file, representation, site,
overwrite=False):
"""
Uploads single file from 'source_path' to destination 'path'.
@ -235,7 +235,7 @@ class SFTPHandler(AbstractProvider):
arguments for saving progress:
server (SyncServer): server instance to call update_db on
collection (str): name of collection
project_name (str):
file (dict): info about uploaded file (matches structure from db)
representation (dict): complete repre containing 'file'
site (str): site name
@ -256,7 +256,7 @@ class SFTPHandler(AbstractProvider):
thread = threading.Thread(target=self._upload,
args=(source_path, target_path))
thread.start()
self._mark_progress(collection, file, representation, server,
self._mark_progress(project_name, file, representation, server,
site, source_path, target_path, "upload")
return os.path.basename(target_path)
@ -267,7 +267,7 @@ class SFTPHandler(AbstractProvider):
conn.put(source_path, target_path)
def download_file(self, source_path, target_path,
server, collection, file, representation, site,
server, project_name, file, representation, site,
overwrite=False):
"""
Downloads single file from 'source_path' (remote) to 'target_path'.
@ -281,7 +281,7 @@ class SFTPHandler(AbstractProvider):
arguments for saving progress:
server (SyncServer): server instance to call update_db on
collection (str): name of collection
project_name (str):
file (dict): info about uploaded file (matches structure from db)
representation (dict): complete repre containing 'file'
site (str): site name
@ -302,7 +302,7 @@ class SFTPHandler(AbstractProvider):
thread = threading.Thread(target=self._download,
args=(source_path, target_path))
thread.start()
self._mark_progress(collection, file, representation, server,
self._mark_progress(project_name, file, representation, server,
site, source_path, target_path, "download")
return os.path.basename(target_path)
@ -425,7 +425,7 @@ class SFTPHandler(AbstractProvider):
pysftp.exceptions.ConnectionException):
log.warning("Couldn't connect", exc_info=True)
def _mark_progress(self, collection, file, representation, server, site,
def _mark_progress(self, project_name, file, representation, server, site,
source_path, target_path, direction):
"""
Updates progress field in DB by values 0-1.
@ -446,7 +446,7 @@ class SFTPHandler(AbstractProvider):
status_val = target_file_size / source_file_size
last_tick = time.time()
log.debug(direction + "ed %d%%." % int(status_val * 100))
server.update_db(collection=collection,
server.update_db(project_name=project_name,
new_file_id=None,
file=file,
representation=representation,