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

URI repository paths #1956

Closed
Closed
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
05f6dee
Update environment
tokejepsen Aug 18, 2021
3a94f46
Replace Path with AnyPath
tokejepsen Aug 18, 2021
3b27530
Move FilePath and DropboxPath to tools.
tokejepsen Aug 19, 2021
d1bf208
Move user_data_dir to tools.
tokejepsen Aug 19, 2021
0ffebe5
Get dropbox token from settings
tokejepsen Aug 19, 2021
8e37cf3
Update version
tokejepsen Aug 19, 2021
e460c4b
Update version
tokejepsen Aug 19, 2021
da1937d
Add resolve
tokejepsen Aug 20, 2021
82634f1
Increment version.
tokejepsen Aug 20, 2021
d9c9620
Increment version
tokejepsen Aug 20, 2021
895cfd8
Keep zip file after extraction
tokejepsen Aug 20, 2021
1e808a0
Increment version
tokejepsen Aug 20, 2021
86daf9e
Revert "Keep zip file after extraction"
tokejepsen Aug 20, 2021
459b533
Dropbox cache as subdirectory.
tokejepsen Aug 20, 2021
96d7df6
Increment version
tokejepsen Aug 20, 2021
75f0d6b
Expose clean_cache method.
tokejepsen Aug 21, 2021
1fdda70
Clean cloud caches when cleaning after zip extraction.
tokejepsen Aug 21, 2021
428bea3
Increment version
tokejepsen Aug 21, 2021
501667e
Increment version
tokejepsen Aug 21, 2021
69d6cde
Clean cache with root path.
tokejepsen Aug 21, 2021
38954d2
Clean repository when extracting a new version.
tokejepsen Aug 21, 2021
504c43a
Remove clean cache
tokejepsen Aug 21, 2021
54fe31a
Reset dropbox cache to user data dir
tokejepsen Aug 21, 2021
29babd5
Validate versions
tokejepsen Aug 21, 2021
ef26ea5
Merge branch 'develop' into feature/uri_repository_path
tokejepsen Aug 23, 2021
b3f6f40
Hound fix
tokejepsen Aug 23, 2021
6c158a4
Fix empty Path argument
tokejepsen Aug 26, 2021
db87a76
Catch all expection for when checking existence.
tokejepsen Sep 27, 2021
29dd42e
Merge branch 'develop' into feature/uri_repository_path
tokejepsen Sep 27, 2021
a1e2a07
Issue warning to user when not paths exist.
tokejepsen Sep 27, 2021
842838c
Update for Mongo certifi issue.
tokejepsen Oct 7, 2021
5b8ed4b
Merge branch 'develop' into feature/uri_repository_path
tokejepsen Oct 7, 2021
52d3f81
Merge branch 'develop' into feature/uri_repository_path
antirotor Feb 10, 2022
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
75 changes: 43 additions & 32 deletions igniter/bootstrap_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@

from zipfile import ZipFile, BadZipFile

from appdirs import user_data_dir
from speedcopy import copyfile
import semver
from cloudpathlib import AnyPath

from .user_settings import (
OpenPypeSecureRegistry,
OpenPypeSettingsRegistry
)
from .tools import get_openpype_path_from_db

from .tools import get_openpype_path_from_db, get_user_data_dir

LOG_INFO = 0
LOG_WARNING = 1
Expand Down Expand Up @@ -76,7 +75,7 @@ def __init__(self, *args, **kwargs):

if kwargs.get("path"):
if isinstance(kwargs.get("path"), str):
self.path = Path(kwargs.get("path"))
self.path = AnyPath(kwargs.get("path"))
elif isinstance(kwargs.get("path"), Path):
self.path = kwargs.get("path")
else:
Expand Down Expand Up @@ -233,11 +232,9 @@ def __init__(self, progress_callback: Callable = None, message=None):
message (QtCore.Signal, optional): Signal to report messages back.

"""
# vendor and app used to construct user data dir
self._vendor = "pypeclub"
self._app = "openpype"

self._log = log.getLogger(str(__class__))
self.data_dir = Path(user_data_dir(self._app, self._vendor))
self.data_dir = get_user_data_dir()
self.secure_registry = OpenPypeSecureRegistry("mongodb")
self.registry = OpenPypeSettingsRegistry()
self.zip_filter = [".pyc", "__pycache__"]
Expand All @@ -256,9 +253,11 @@ def empty_progress(x: int):
self._progress_callback = progress_callback

if getattr(sys, "frozen", False):
self.live_repo_dir = Path(sys.executable).parent / "repos"
self.live_repo_dir = AnyPath(sys.executable).parent / "repos"
else:
self.live_repo_dir = Path(Path(__file__).parent / ".." / "repos")
self.live_repo_dir = AnyPath(
AnyPath(__file__).parent / ".." / "repos"
)

@staticmethod
def get_version_path_from_list(version: str, version_list: list) -> Path:
Expand All @@ -281,7 +280,7 @@ def get_local_live_version() -> str:
"""Get version of local OpenPype."""

version = {}
path = Path(os.environ["OPENPYPE_ROOT"]) / "openpype" / "version.py"
path = AnyPath(os.environ["OPENPYPE_ROOT"]) / "openpype" / "version.py"
with open(path, "r") as fp:
exec(fp.read(), version)
return version["__version__"]
Expand All @@ -303,7 +302,7 @@ def get_version(repo_dir: Path) -> Union[str, None]:

"""
# try to find version
version_file = Path(repo_dir) / "openpype" / "version.py"
version_file = AnyPath(repo_dir) / "openpype" / "version.py"
if not version_file.exists():
return None

Expand Down Expand Up @@ -349,7 +348,7 @@ def create_version_from_live_code(
# create zip inside temporary directory.
with tempfile.TemporaryDirectory() as temp_dir:
temp_zip = \
Path(temp_dir) / f"openpype-v{version}.zip"
AnyPath(temp_dir) / f"openpype-v{version}.zip"
self._print(f"creating zip: {temp_zip}")

self._create_openpype_zip(temp_zip, repo_dir.parent)
Expand Down Expand Up @@ -417,7 +416,7 @@ def create_version_from_frozen_code(self) -> Union[None, OpenPypeVersion]:
:class:`OpenPypeVersion` zip file to be installed.

"""
frozen_root = Path(sys.executable).parent
frozen_root = AnyPath(sys.executable).parent

openpype_list = []
for f in self.openpype_filter:
Expand All @@ -432,7 +431,7 @@ def create_version_from_frozen_code(self) -> Union[None, OpenPypeVersion]:
# create zip inside temporary directory.
with tempfile.TemporaryDirectory() as temp_dir:
temp_zip = \
Path(temp_dir) / f"openpype-v{version}.zip"
AnyPath(temp_dir) / f"openpype-v{version}.zip"
self._print(f"creating zip: {temp_zip}")

with ZipFile(temp_zip, "w") as zip_file:
Expand All @@ -447,7 +446,7 @@ def create_version_from_frozen_code(self) -> Union[None, OpenPypeVersion]:
# we need to replace first part of path which starts with
# something like `exe.win/linux....` with `openpype` as
# this is expected by OpenPype in zip archive.
arc_name = Path().joinpath(*arc_name.parts[1:])
arc_name = AnyPath("").joinpath(*arc_name.parts[1:])
zip_file.write(file, arc_name)

destination = self._move_zip_to_data_dir(temp_zip)
Expand Down Expand Up @@ -634,11 +633,11 @@ def find_openpype(
dir_to_search = openpype_path
else:
if os.getenv("OPENPYPE_PATH"):
if Path(os.getenv("OPENPYPE_PATH")).exists():
dir_to_search = Path(os.getenv("OPENPYPE_PATH"))
if AnyPath(os.getenv("OPENPYPE_PATH")).exists():
dir_to_search = AnyPath(os.getenv("OPENPYPE_PATH"))
else:
try:
registry_dir = Path(
registry_dir = AnyPath(
str(self.registry.get_item("openPypePath")))
if registry_dir.exists():
dir_to_search = registry_dir
Expand All @@ -661,6 +660,24 @@ def find_openpype(

return openpype_versions

def _validate_version(self, version):
# if file, strip extension, in case of dir not.
name = version.name if version.is_dir() else version.stem
result = OpenPypeVersion.version_in_str(name)
detected_version = result[1]

if version.is_dir() and not self._is_openpype_in_dir(
version, detected_version
):
return False

if version.is_file() and not self._is_openpype_in_zip(
version, detected_version
):
return False

return True

def process_entered_location(self, location: str) -> Union[Path, None]:
"""Process user entered location string.

Expand Down Expand Up @@ -688,7 +705,7 @@ def process_entered_location(self, location: str) -> Union[Path, None]:

# if not successful, consider location to be fs path.
if not openpype_path:
openpype_path = Path(location)
openpype_path = AnyPath(location)

# test if this path does exist.
if not openpype_path.exists():
Expand All @@ -709,7 +726,11 @@ def process_entered_location(self, location: str) -> Union[Path, None]:
self._print(f"found OpenPype in [ {openpype_path} ]")
self._print(f"latest version found is [ {versions[-1]} ]")

return self.install_version(versions[-1])
# Validate versions and return latest. This is to prevent any
# unnecessary downloading from cloud repositories.
for version in reversed(versions):
if self._validate_version(version):
return self.install_version(version)

# if we got here, it means that location is "live"
# OpenPype repository. We'll create zip from it and move it to user
Expand Down Expand Up @@ -857,7 +878,7 @@ def install_version(self,
self._print("Creating zip from directory ...")
with tempfile.TemporaryDirectory() as temp_dir:
temp_zip = \
Path(temp_dir) / f"openpype-v{openpype_version}.zip"
AnyPath(temp_dir) / f"openpype-v{openpype_version}.zip"
self._print(f"creating zip: {temp_zip}")

self._create_openpype_zip(temp_zip, openpype_version.path)
Expand Down Expand Up @@ -1029,16 +1050,6 @@ def get_openpype_versions(self,
detected_version: OpenPypeVersion
detected_version = result[1]

if item.is_dir() and not self._is_openpype_in_dir(
item, detected_version
):
continue

if item.is_file() and not self._is_openpype_in_zip(
item, detected_version
):
continue

detected_version.path = item
if staging and detected_version.is_staging():
_openpype_versions.append(detected_version)
Expand Down
Loading