From 68954e034e4edd24b060b84d938839cdf8a44d37 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 30 Mar 2021 19:37:07 +0200 Subject: [PATCH] implemented new Application class which use more data from group and keeps only it's environments --- pype/lib/applications.py | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/pype/lib/applications.py b/pype/lib/applications.py index e2596cbacb..3f573ba6c6 100644 --- a/pype/lib/applications.py +++ b/pype/lib/applications.py @@ -121,6 +121,81 @@ class ApplicationGroup: return copy.deepcopy(self._environment) +class Application: + """Hold information about application. + + Object by itself does nothing special. + + Args: + name (str): Specific version (or variant) of application. + e.g. "maya2020", "nuke11.3", etc. + data (dict): Data for the version containing information about + executables, variant label or if is enabled. + Only required key is `executables`. + group (ApplicationGroup): App group object that created the applicaiton + and under which application belongs. + """ + + def __init__(self, name, data, group): + self.name = name + self.group = group + self._data = data + + enabled = False + if group.enabled: + enabled = data.get("enabled", True) + self.enabled = enabled + + self.label = data.get("variant_label") or name + self.full_name = "/".join((group.name, name)) + self.full_label = " ".join((group.label, self.label)) + self._environment = data.get("environment") or {} + + _executables = data["executables"] + if not _executables: + _executables = [] + + elif isinstance(_executables, dict): + _executables = _executables.get(platform.system().lower()) or [] + + _arguments = data["arguments"] + if not _arguments: + _arguments = [] + + elif isinstance(_arguments, dict): + _arguments = _arguments.get(platform.system().lower()) or [] + + executables = [] + for executable in _executables: + executables.append(ApplicationExecutable(executable)) + + self.executables = executables + self.arguments = _arguments + + def __repr__(self): + return "<{}> - {}".format(self.__class__.__name__, self.full_name) + + @property + def environment(self): + return copy.deepcopy(self._environment) + + @property + def manager(self): + return self.group.manager + + @property + def host_name(self): + return self.group.host_name + + @property + def icon(self): + return self.group.icon + + @property + def is_host(self): + return self.group.is_host + + class ApplicationManager: def __init__(self): self.log = PypeLogger().get_logger(self.__class__.__name__)