Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Sync server fix local drive #1115

Merged
merged 34 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
348cb05
SyncServer - added required methods
kalisp Mar 8, 2021
3e9c867
SyncServer - fix exceptions when no project configured
kalisp Mar 8, 2021
720ab0f
SyncServer - fixes, refactor
kalisp Mar 8, 2021
825e715
Merge remote-tracking branch 'origin/develop' into sync_server_fix_lo…
kalisp Mar 9, 2021
5faf154
SyncServer - use properly get_local_site_id for user's local site in app
kalisp Mar 9, 2021
02bd357
SyncServer - cleaned up unneeded configuration
kalisp Mar 9, 2021
1a57419
SyncServer - use get_local_site_id for local site
kalisp Mar 9, 2021
ba9b56f
SyncServer - added get_active_sites, get_remote_sites methods
kalisp Mar 9, 2021
9c6544a
SyncServer - add 2 new methods get_active_sites_from_settings
kalisp Mar 10, 2021
d16434d
SyncServer - added missed file
kalisp Mar 10, 2021
838d0e0
modules manager is also passed to local settings widgets
iLLiCiTiT Mar 10, 2021
5a2aea6
added applications of project settings
iLLiCiTiT Mar 10, 2021
459a39f
modified how active sites and remote sites are filled
iLLiCiTiT Mar 10, 2021
40e8023
fixed typo in method names
iLLiCiTiT Mar 10, 2021
a469f2d
modified order of local settings processing
iLLiCiTiT Mar 10, 2021
e56cb5f
Merge branch 'develop' of github.com:pypeclub/pype into sync_server_f…
kalisp Mar 11, 2021
a57604f
Merge remote-tracking branch 'origin/sync_server_fix_local_drive' int…
kalisp Mar 11, 2021
c370d5f
it is possible to pass site_name to get_anatomy_settings
iLLiCiTiT Mar 11, 2021
ed32184
anatomy can have defined site_name on creation
iLLiCiTiT Mar 11, 2021
1877ff2
Merge branch 'develop' of github.com:pypeclub/pype into sync_server_f…
kalisp Mar 11, 2021
a0ad216
Merge remote-tracking branch 'origin/sync_server_fix_local_drive' int…
kalisp Mar 11, 2021
431d5a7
fix method name
iLLiCiTiT Mar 11, 2021
f107482
Merge remote-tracking branch 'origin/sync_server_fix_local_drive' int…
kalisp Mar 11, 2021
fcfd537
Fix - get_remote_sites_from_settings does not validate sites
kalisp Mar 11, 2021
83570d4
SyncServer - modified resolving of paths for local and remote
kalisp Mar 11, 2021
25fcec7
`get_anatomy_settings` and `get_project_settings` can not apply local…
iLLiCiTiT Mar 11, 2021
bf127b0
SyncServer - refresh project settings every loop or project change
kalisp Mar 11, 2021
541dd06
SyncServer - fix lagging of gui
kalisp Mar 11, 2021
fe3de0c
Hound
kalisp Mar 11, 2021
8bd7f03
Merge remote-tracking branch 'origin/sync_server_fix_local_drive' int…
kalisp Mar 11, 2021
ad27a41
Merge remote-tracking branch 'origin/develop' into sync_server_fix_lo…
kalisp Mar 11, 2021
0662568
delete look manager
mkolar Mar 11, 2021
495b86d
Merge branch 'develop' of github.com:pypeclub/pype into sync_server_f…
kalisp Mar 11, 2021
1daa755
SyncServer - use local_site_id properly
kalisp Mar 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pype/lib/anatomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Anatomy:
root_key_regex = re.compile(r"{(root?[^}]+)}")
root_name_regex = re.compile(r"root\[([^]]+)\]")

def __init__(self, project_name=None):
def __init__(self, project_name=None, site_name=None):
if not project_name:
project_name = os.environ.get("AVALON_PROJECT")

Expand All @@ -89,7 +89,7 @@ def __init__(self, project_name=None):

self.project_name = project_name

self._data = get_anatomy_settings(project_name)
self._data = get_anatomy_settings(project_name, site_name)

self._templates_obj = Templates(self)
self._roots_obj = Roots(self)
Expand Down
36 changes: 36 additions & 0 deletions pype/modules/sync_server/providers/abstract_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,39 @@ def list_folder(self, folder_path):
(list)
"""
pass

@abstractmethod
def create_folder(self, folder_path):
"""
Create all nonexistent folders and subfolders in 'path'.

Args:
path (string): absolute path

Returns:
(string) folder id of lowest subfolder from 'path'
"""
pass

@abstractmethod
def get_tree(self):
"""
Creates folder structure for providers which do not provide
tree folder structure (GDrive has no accessible tree structure,
only parents and their parents)
"""
pass

@abstractmethod
def resolve_path(self, path, root_config, anatomy=None):
"""
Replaces root placeholders with appropriate real value from
'root_configs' (from Settings or Local Settings) or Anatomy
(mainly for 'studio' site)

Args:
path(string): path with '{root[work]}/...'
root_config(dict): from Settings or Local Settings
anatomy (Anatomy): prepared anatomy object for project
"""
pass
10 changes: 10 additions & 0 deletions pype/modules/sync_server/providers/gdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,16 @@ def get_presets(cls):
return
return provider_presets

def resolve_path(self, path, root_config, anatomy=None):
if not root_config.get("root"):
root_config = {"root": root_config}

try:
return path.format(**root_config)
except KeyError:
msg = "Error in resolving remote root, unknown key"
log.error(msg)

def _handle_q(self, q, trashed=False):
""" API list call contain trashed and hidden files/folder by default.
Usually we dont want those, must be included in query explicitly.
Expand Down
108 changes: 92 additions & 16 deletions pype/modules/sync_server/providers/local_drive.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import print_function
import os.path
import shutil
import threading
import time

from pype.api import Logger
from .abstract_provider import AbstractProvider
Expand All @@ -13,29 +15,37 @@ class LocalDriveHandler(AbstractProvider):
def is_active(self):
return True

def upload_file(self, source_path, target_path, overwrite=True):
def upload_file(self, source_path, target_path,
server, collection, file, representation, site,
overwrite=False, direction="Upload"):
"""
Copies file from 'source_path' to 'target_path'
"""
if os.path.exists(source_path):
if overwrite:
shutil.copy(source_path, target_path)
else:
if os.path.exists(target_path):
raise ValueError("File {} exists, set overwrite".
format(target_path))
if not os.path.isfile(source_path):
raise FileNotFoundError("Source file {} doesn't exist."
.format(source_path))
if overwrite:
thread = threading.Thread(target=self._copy,
args=(source_path, target_path))
thread.start()
self._mark_progress(collection, file, representation, server,
site, source_path, target_path, direction)
else:
if os.path.exists(target_path):
raise ValueError("File {} exists, set overwrite".
format(target_path))

def download_file(self, source_path, local_path, overwrite=True):
return os.path.basename(target_path)

def download_file(self, source_path, local_path,
server, collection, file, representation, site,
overwrite=False):
"""
Download a file form 'source_path' to 'local_path'
"""
if os.path.exists(source_path):
if overwrite:
shutil.copy(source_path, local_path)
else:
if os.path.exists(local_path):
raise ValueError("File {} exists, set overwrite".
format(local_path))
return self.upload_file(source_path, local_path,
server, collection, file, representation, site,
overwrite, direction="Download")

def delete_file(self, path):
"""
Expand All @@ -57,3 +67,69 @@ def list_folder(self, folder_path):
lst.append(os.path.join(dir_path, name))

return lst

def create_folder(self, folder_path):
"""
Creates 'folder_path' on local system

Args:
folder_path (string): absolute path on local (and mounted) disk

Returns:
(string) - sends back folder_path to denote folder(s) was
created
"""
os.makedirs(folder_path, exist_ok=True)
return folder_path

def get_tree(self):
return

def resolve_path(self, path, root_config, anatomy=None):
if root_config and not root_config.get("root"):
root_config = {"root": root_config}

try:
if not root_config:
raise KeyError

path = path.format(**root_config)
except KeyError:
try:
path = anatomy.fill_root(path)
except KeyError:
msg = "Error in resolving local root from anatomy"
log.error(msg)
raise ValueError(msg)

return path

def _copy(self, source_path, target_path):
print("copying {}->{}".format(source_path, target_path))
shutil.copy(source_path, target_path)

def _mark_progress(self, collection, file, representation, server, site,
source_path, target_path, direction):
"""
Updates progress field in DB by values 0-1.

Compares file sizes of source and target.
"""
source_file_size = os.path.getsize(source_path)
target_file_size = 0
last_tick = status_val = None
while source_file_size != target_file_size:
if not last_tick or \
time.time() - last_tick >= server.LOG_PROGRESS_SEC:
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,
new_file_id=None,
file=file,
representation=representation,
site=site,
progress=status_val
)
target_file_size = os.path.getsize(target_path)
time.sleep(0.5)
Loading