def get_tool_config(self, tool_id, package_name=None): """ Returns config applied to given tool :param tool_id: str :param package_name: str :return: Theme """ if not package_name: package_name = tool_id.replace('.', '-').split('-')[0] if package_name not in self._plugins: logger.warning( 'Impossible to retrieve tool config for "{}" in package "{}"! Package not registered.' .format(tool_id, package_name)) return None tool_ids = [ tool_class.ID for tool_class in self._plugins[package_name] ] if tool_id not in tool_ids: logger.warning( 'Impossible to retrieve tool config for "{}" in package "{}"! Tool not found' .format(tool_id, package_name)) return None return configs.get_tool_config(tool_id=tool_id, package_name=package_name)
def settings_path(): """ Returns library settings file path :return: str """ datalib_config = configs.get_tool_config('tpDcc-tools-datalibrary') settings_file_path = datalib_config.get('settings_path') settings_file_path = format_path(settings_file_path) return settings_file_path
def update_client(self, **kwargs): tool_id = kwargs.get('tool_id', None) config_dict = configs.get_tool_config( tool_id) or dict() if tool_id else dict() supported_dccs = config_dict.get( 'supported_dccs', dict()) if config_dict else kwargs.get( 'supported_dccs', dict()) if not self.connected: self.set_status('Not connected to any DCC', self.Status.WARNING) return False if dcc.is_standalone(): success, dcc_exe = self.update_paths() if not success: return False success = self.update_dcc_paths(dcc_exe) if not success: return False success = self.init_dcc() if not success: return False dcc_name, dcc_version, dcc_pid = self.get_dcc_info() if not dcc_name or not dcc_version: return False if dcc_name not in supported_dccs: self.set_status( 'Connected DCC {} ({}) is not supported!'.format( dcc_name, dcc_version), self.Status.WARNING) return False supported_versions = supported_dccs[dcc_name] if dcc_version not in supported_versions: self.set_status( 'Connected DCC {} is support but version {} is not!'.format( dcc_name, dcc_version), self.Status.WARNING) return False msg = 'Connected to: {} {} ({})'.format(dcc_name, dcc_version, dcc_pid) self.set_status(msg, self.Status.SUCCESS) LOGGER.info(msg) if tool_id: DccClient._register_client(tool_id, self)
def _add_tool_action(item_info, parent): tool_id = item_info.get('id', None) tool_type = item_info.get('type', 'tool') # NOTE: Here we don't pass the package for now. If we pass a package, for example, tpRigTooklit, tpDcc # packages will not be added to the menu tool_config = configs.get_tool_config(tool_id) if not tool_config: return tool_menu_ui_data = tool_config.data.get('menu_ui', {}) tool_icon_name = tool_menu_ui_data.get('icon', '') if not tool_icon_name: tool_icon_name = tool_config.data.get('icon', None) if not tool_icon_name: tool_icon_name = 'tpDcc' tool_icon = resources.icon(tool_icon_name) if not tool_icon or tool_icon.isNull(): tool_icon = resources.icon('tpDcc') label = tool_menu_ui_data.get('label', 'No_label') tagged_action = menu.SearchableTaggedAction(label=label, icon=tool_icon, parent=parent) is_checkable = tool_menu_ui_data.get('is_checkable', False) is_checked = tool_menu_ui_data.get('is_checked', False) if is_checkable: tagged_action.setCheckable(is_checkable) tagged_action.setChecked(is_checked) # tagged_action.connect(partial(self._launch_tool, tool_data)) tagged_action.toggled.connect( partial(_launch_tool_by_id, tool_id)) else: tagged_action.triggered.connect( partial(_launch_tool_by_id, tool_id)) icon = tool_menu_ui_data.get('icon', 'tpDcc') if icon: pass tagged_action.tags = set(tool_config.data.get('tags', [])) parent.addAction(tagged_action)
def register_package_toolsets(self, package_name, toolsets_file_path, toolsets_paths): self._load_registered_paths_toolsets(package_name, toolsets_file_path) if not toolsets_paths: return toolsets_paths = python.remove_dupes(python.force_list(toolsets_paths)) self.register_paths(toolsets_paths, package_name=package_name) if package_name not in self._toolsets: self._toolsets[package_name] = list() toolset_data = self.plugins(package_name) if not toolset_data: return True for toolset in self.plugins(package_name=package_name): if not toolset: continue if not toolset.PACKAGE: toolset.PACKAGE = package_name for tool_set in toolset_data: if tool_set.ID not in self._toolsets[package_name]: toolset_config = configs.get_tool_config( tool_set.ID, package_name=package_name) if not toolset_config: logger.warning( 'No valid configuration file found for toolset: "{}" in package: "{}"' .format(tool_set.ID, package_name)) continue tool_set.CONFIG = toolset_config self._toolsets[package_name].append({tool_set.ID: tool_set}) return True
def connect(self, port=-1): def _connect(_port): try: self._client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._client_socket.connect(('localhost', _port)) # self._client_socket.setblocking(False) except ConnectionRefusedError as exc: # LOGGER.warning(exc) self._status = { 'msg': 'Client connection was refused.', 'level': self.Status.ERROR } self._connected = False return False except Exception: LOGGER.exception(traceback.format_exc()) self._status = { 'msg': 'Error while connecting client', 'level': self.Status.ERROR } self._connected = False return False return True if self._server: self._status = { 'msg': 'Client connected successfully!', 'level': self.Status.SUCCESS } self._connected = True return True # If we pass a port, we just connect to it if port > 0: self._port = port self._connected = _connect(port) return self._connected self._port = self.PORT _connect(self._port) supported_dccs = None tool_id = self._tool_id if tool_id: config_dict = configs.get_tool_config( tool_id) or dict() if tool_id else dict() supported_dccs = config_dict.get( 'supported_dccs', dict()) if config_dict else kwargs.get( 'supported_dccs', dict()) # If no port if given, we check which DCCs are running the user machine and we try to connect # to those ports self._running_dccs = list() for dcc_name in core_dcc.Dccs.ALL: if supported_dccs and dcc_name not in supported_dccs: continue process_name = core_dcc.Dccs.executables.get(dcc_name, dict()).get( osplatform.get_platform(), None) if not process_name: continue process_running = process.check_if_process_is_running(process_name) if not process_running: continue self._running_dccs.append(dcc_name) if not self._running_dccs: self._port = self.PORT self._connected = _connect(self._port) else: for dcc_name in self._running_dccs: self._port = core_dcc.dcc_port(self.PORT, dcc_name=dcc_name) valid_connect = _connect(self._port) if valid_connect: self._connected = True return True return self._connected