def _launch_viewer(self, path): """ Launches an image viewer based on config settings. We assume that the path to the image is just passed as a param to the viewer. This seems to be standard for most apps. """ try: app_path = None if util.is_linux(): app_path = self.get_setting("viewer_path_linux") cmd = '%s "%s" &' % (app_path, path) elif util.is_macos(): app_path = self.get_setting("viewer_path_mac") cmd = 'open -n "%s" --args "%s"' % (app_path, path) elif util.is_windows(): app_path = self.get_setting("viewer_path_windows") cmd = 'start /B "Maya" "%s" "%s"' % (app_path, path) if not app_path: raise KeyError() except KeyError: raise Exception("Platform '%s' is not supported." % sys.platform) self.log_debug("Executing launch command '%s'" % cmd) exit_code = os.system(cmd) if exit_code != 0: self.log_error( "Failed to launch Viewer! This is most likely because the path " "to the viewer executable is not set to a correct value. The " "current value is '%s' - please double check that this path " "is valid and update as needed in this app's configuration. " "If you have any questions, don't hesitate to contact support " "on [email protected]." % app_path )
def launch(self, path): self.log_debug("Launching default system viewer for file %s" % path) # run the app if util.is_linux(): cmd = 'xdg-open "%s"' % path elif util.is_macos(): cmd = 'open "%s"' % path elif util.is_windows(): cmd = 'cmd.exe /C start "file" "%s"' % path else: raise Exception("Platform '%s' is not supported." % sys.platform) self.log_debug("Executing command '%s'" % cmd) exit_code = os.system(cmd) if exit_code != 0: self.log_error("Failed to launch '%s'!" % cmd)
def _jump_to_fs(self): """ Jump from a context to the filesystem. """ # launch one window for each location on disk paths = self._engine.context.filesystem_locations for disk_location in paths: if is_linux(): cmd = 'xdg-open "%s"' % disk_location elif is_macos(): cmd = 'open "%s"' % disk_location elif is_windows(): cmd = 'cmd.exe /C start "Folder" "%s"' % disk_location else: raise Exception("Platform is not supported.") self._engine.logger.debug("Jump to filesystem command: {}".format(cmd)) exit_code = os.system(cmd) if exit_code != 0: self._engine.logger.error("Failed to launch '%s'!", cmd)