def test_format_var(self, tmp_path, monkeypatch): self.setup_storage(self._valid_storage, tmp_path, monkeypatch) s = Storage() vars = s._format_var(json.loads(self._valid_storage)) pprint(vars) assert vars.get('PYPE_STUDIO_PROJECTS_PATH') == '//store/vfx/projects' assert vars.get('PYPE_STUDIO_PROJECTS_MOUNT') == 'P:/vfx'
def test_validate_schema(self, invalid_storage_file, storage_file, tmp_path, monkeypatch): self.setup_storage(self._valid_storage, tmp_path, monkeypatch) s = Storage() r = s._validate_schema(s._read_storage_file(invalid_storage_file)) assert r is False r = s._validate_schema(s._read_storage_file(storage_file)) assert r is True
def _initialize(self): from pypeapp.storage import Storage from pypeapp.deployment import Deployment from pypeapp.lib.Terminal import Terminal # if not called, console coloring will get mangled in python. Terminal() pype_setup = os.getenv('PYPE_ROOT') d = Deployment(pype_setup) tools, config_path = d.get_environment_data() os.environ['PYPE_CONFIG'] = config_path os.environ['TOOL_ENV'] = os.path.normpath( os.path.join( config_path, 'environments')) self._add_modules() Storage().update_environment() self._load_default_environments(tools=tools) self.print_info()
def path_remapper(self, data=None, source=None, to=None): """ This will search existing environment for strings defined by variables in storage setting for all platforms. If found, it will be replaced with string from current platform. For example, we have `PYPE_STORAGE_PATH` pointing on windows to `V:\\Projects`. In environment setting, there is variable `FOO="V:\\Projects\\Foo\\Bar\\baz"`. But we are on linux where `PYPE_STORAGE_PATH` is defined as `/mnt/projects`. This method will change `FOO` to point to `/mnt/projects/Foo/Bar/baz`. This is useful on scenarios, where these variables are set on different platform then one currently running. Source data can be dictionary or list and it can contain other dictionaries and lists. Paths will be replaced recursively. :param data: Source data. By default it is `os.environ` :type data: dict :param source: string defining plaform from which we want to remap. If not set, then all platforms other then current one will be searched. :type source: dict or list :param to: string defining platform to which we want to remap. If not set, we will remap to current platform. :returns: modified data :rtype: dict or list """ from pypeapp.storage import Storage _platform_name = [ ("win32", "windows"), ("linux", "linux"), ("darwin", "darwin") ] _current_platform = [p[1] for p in _platform_name if p[0] == sys.platform][0] # noqa: E501 if not data: data = os.environ.copy() if source: from_paths_platform = [source] else: from_paths_platform = ['windows', 'linux', 'darwin'] from_paths_platform.remove(_current_platform) if to: to_paths_platform = to else: to_paths_platform = _current_platform # noqa: E501 result_strings = Storage().get_storage_vars(platform=to_paths_platform) if isinstance(data, dict): remapped = {} else: remapped = [] done_keys = [] for p in from_paths_platform: search_strings = Storage().get_storage_vars(platform=p) for key in data: if isinstance(data, dict): var = data[key] else: var = key # TODO: handle all cases. Normalized path, backslashes, ... for skey, string in search_strings.items(): # skip empty strings if not string: continue # work only on strings if not isinstance(var, str): # if another dict is found, recurse if isinstance(var, dict) or isinstance(var, list): # don't get into empty oness if var: revar = self.path_remapper(data=var, source=source, to=to) if isinstance(data, dict): remapped[key] = revar else: remapped.append(revar) else: if isinstance(data, dict): remapped[key] = var else: remapped.append(var) continue if string in var and key not in done_keys: out = var.replace(string, result_strings[skey]) if to_paths_platform in ["win32", "windows"]: out = os.path.normpath(out) else: out = out.replace("\\", "/") if isinstance(data, dict): remapped[key] = out else: remapped.append(out) done_keys.append(key) elif key not in done_keys: if isinstance(data, dict): remapped[key] = var else: remapped.append(var) return remapped
def test_get_storage_platform_vars(self, tmp_path, monkeypatch): self.setup_storage(self._valid_storage, tmp_path, monkeypatch) s = Storage() env = s.get_storage_vars(platform="linux") assert env.get("PYPE_STUDIO_PROJECTS_PATH") == '/mnt/vfx/projects' assert env.get("PYPE_STUDIO_PROJECTS_MOUNT") == '/studio/pojects/vfx'
def test_get_storage_vars(self, tmp_path, monkeypatch): self.setup_storage(self._valid_storage, tmp_path, monkeypatch) s = Storage() env = s.get_storage_vars() assert env.get('PYPE_STUDIO_PROJECTS_PATH') == '//store/vfx/projects' assert env.get('PYPE_STUDIO_PROJECTS_MOUNT') == 'P:/vfx'
def test_recurse_dict(self): data_dict = json.loads(self._valid_storage) paths = list(Storage.paths(data_dict)) assert paths[0] == ('studio', 'projects', 'path', 'windows')
def test_read_schema_file(self, tmp_path, monkeypatch): paths = self.setup_storage(self._valid_storage, tmp_path, monkeypatch) s = Storage() loaded = s._read_schema(paths[1]) data = json.load(paths[1]) assert loaded == data
from pprint import pprint from pypeapp.pypeLauncher import PypeLauncher from pypeapp.storage import Storage from pypeapp.deployment import Deployment pype_setup = os.getenv('PYPE_ROOT') d = Deployment(pype_setup) launcher = PypeLauncher() tools, config_path = d.get_environment_data() os.environ['PYPE_CONFIG'] = config_path os.environ['TOOL_ENV'] = os.path.normpath( os.path.join(config_path, 'environments')) launcher._add_modules() Storage().update_environment() launcher._load_default_environments(tools=tools) # -- Project information ----------------------------------------------------- project = 'pype' copyright = '2019, Orbi Tools' author = 'Orbi Tools' # The short X.Y version version = '' # The full version, including alpha/beta/rc tags release = '' # -- General configuration ---------------------------------------------------