def load_running_jobs(self): conf = configuration.get_vistrails_configuration() if conf.has('runningJobsList') and conf.runningJobsList: for url in conf.runningJobsList.split(';'): loc, version = url.split('?') locator = BaseLocator.from_url(loc) msgBox = QtGui.QMessageBox(QtGui.QMessageBox.Question, "Running Job Found", "Running Job Found:\n %s\n" "Continue now?" % url) msgBox.addButton("Later", msgBox.ActionRole) delete = msgBox.addButton("Delete", msgBox.ActionRole) yes = msgBox.addButton("Yes", msgBox.ActionRole) msgBox.exec_() if msgBox.clickedButton() == yes: from vistrails.gui.vistrails_window import _app _app.open_vistrail_without_prompt(locator, int(version.split('=')[1])) _app.get_current_view().execute() if msgBox.clickedButton() == delete: conf_jobs = conf.runningJobsList.split(';') conf_jobs.remove(url) conf.runningJobsList = ';'.join(conf_jobs) configuration.get_vistrails_persistent_configuration( ).runningJobsList = conf.runningJobsList else: conf.runningJobsList = '' configuration.get_vistrails_persistent_configuration( ).runningJobsList = conf.runningJobsList
def clicked_on_login(self): """ Attempts to log into web repository stores auth cookie for session """ from vistrails.gui.application import get_vistrails_application self.dialog.loginUser = self.loginUser.text() params = urllib.urlencode({ 'username': self.dialog.loginUser, 'password': self.loginPassword.text() }) self.dialog.cookiejar = cookielib.CookieJar() # set base url used for cookie self.dialog.cookie_url = self.config.webRepositoryURL self.loginOpener = urllib2.build_opener( urllib2.HTTPCookieProcessor(self.dialog.cookiejar)) # FIXME doesn't use https login_url = "%s/account/login/" % self.config.webRepositoryURL request = urllib2.Request(login_url, params) url = self.loginOpener.open(request) # login failed if not 'sessionid' in [ cookie.name for cookie in self.dialog.cookiejar ]: debug.critical("Incorrect username or password") self.dialog.cookiejar = None else: # login successful self._login_status = "login successful" self.loginUser.setEnabled(False) self.loginPassword.setEnabled(False) self._login_button.setEnabled(False) self.saveLogin.setEnabled(False) # add association between VisTrails user and web repository user if self.saveLogin.checkState(): if not (self.config.check('webRepositoryUser') and self.config.webRepositoryUser == self.loginUser.text()): self.config.webRepositoryUser = str(self.loginUser.text()) pers_config = get_vistrails_persistent_configuration() pers_config.webRepositoryUser = self.config.webRepositoryUser get_vistrails_application().save_configuration() # remove association between VisTrails user and web repository user else: if self.config.check( 'webRepositoryUser') and self.config.webRepositoryUser: self.config.webRepositoryUser = "" pers_config = get_vistrails_persistent_configuration() pers_config.webRepositoryUser = "" get_vistrails_application().save_configuration() self.close_dialog(0)
def tab_changed(self, index): """ tab_changed(index: int) -> None Keep general and advanced configurations in sync """ self._configuration_tab.configuration_changed( get_vistrails_persistent_configuration(), get_vistrails_configuration()) self._general_tab.update_state( get_vistrails_persistent_configuration(), get_vistrails_configuration())
def clicked_on_login(self): """ Attempts to log into web repository stores auth cookie for session """ from vistrails.gui.application import get_vistrails_application self.dialog.loginUser = self.loginUser.text() params = urllib.urlencode({'username':self.dialog.loginUser, 'password':self.loginPassword.text()}) self.dialog.cookiejar = cookielib.CookieJar() # set base url used for cookie self.dialog.cookie_url = self.config.webRepositoryURL self.loginOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.dialog.cookiejar)) # FIXME doesn't use https login_url = "%s/account/login/" % self.config.webRepositoryURL request = urllib2.Request(login_url, params) url = self.loginOpener.open(request) # login failed if not 'sessionid' in [cookie.name for cookie in self.dialog.cookiejar]: debug.critical("Incorrect username or password") self.dialog.cookiejar = None else: # login successful self._login_status = "login successful" self.loginUser.setEnabled(False) self.loginPassword.setEnabled(False) self._login_button.setEnabled(False) self.saveLogin.setEnabled(False) # add association between VisTrails user and web repository user if self.saveLogin.checkState(): if not (self.config.check('webRepositoryLogin') and self.config.webRepositoryLogin == self.loginUser.text()): self.config.webRepositoryLogin = str(self.loginUser.text()) pers_config = get_vistrails_persistent_configuration() pers_config.webRepositoryLogin = self.config.webRepositoryLogin get_vistrails_application().save_configuration() # remove association between VisTrails user and web repository user else: if self.config.check('webRepositoryLogin') and self.config.webRepositoryLogin: self.config.webRepositoryLogin = "" pers_config = get_vistrails_persistent_configuration() pers_config.webRepositoryLogin = "" get_vistrails_application().save_configuration() self.close_dialog(0)
def __init__(self, parent): QtGui.QDialog.__init__(self, parent) self.setWindowTitle('VisTrails Preferences') layout = QtGui.QHBoxLayout(self) layout.setMargin(0) layout.setSpacing(0) self.setLayout(layout) f = QtGui.QFrame() layout.addWidget(f) l = QtGui.QVBoxLayout(f) f.setLayout(l) self._tab_widget = QtGui.QTabWidget(f) l.addWidget(self._tab_widget) self._tab_widget.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) tabs = [("General", ["General", "Packages"]), ("Interface", ["Interface", "Startup"]), ("Paths && URLs", ["Paths", "Web Sharing"]), ("Advanced", ["Upgrades", "Thumbnails", "Advanced"]), ] for (tab_name, categories) in tabs: tab = QConfigurationPane(self, get_vistrails_persistent_configuration(), get_vistrails_configuration(), [(c, base_config[c]) for c in categories]) self._tab_widget.addTab(tab, tab_name) output_tab = QOutputConfigurationPane(self, get_vistrails_persistent_configuration(), get_vistrails_configuration()) self._tab_widget.addTab(output_tab, "Output") self._packages_tab = self.create_packages_tab() self._tab_widget.addTab(self._packages_tab, 'Packages') self._configuration_tab = self.create_configuration_tab() self._tab_widget.addTab(self._configuration_tab, 'Expert') self.connect(self._tab_widget, QtCore.SIGNAL('currentChanged(int)'), self.tab_changed) self.connect(self._configuration_tab._tree.treeWidget, QtCore.SIGNAL('configuration_changed'), self.configuration_changed)
def __init__(self, parent): QtGui.QDialog.__init__(self, parent) self.setWindowTitle('VisTrails Preferences') layout = QtGui.QHBoxLayout(self) layout.setMargin(0) layout.setSpacing(0) self.setLayout(layout) f = QtGui.QFrame() layout.addWidget(f) l = QtGui.QVBoxLayout(f) f.setLayout(l) self._tab_widget = QtGui.QTabWidget(f) l.addWidget(self._tab_widget) self._tab_widget.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) tabs = [ ("General", ["General", "Packages"]), ("Interface", ["Interface", "Startup"]), ("Paths && URLs", ["Paths", "Web Sharing"]), ("Advanced", ["Upgrades", "Thumbnails", "Advanced"]), ] for (tab_name, categories) in tabs: tab = QConfigurationPane(self, get_vistrails_persistent_configuration(), get_vistrails_configuration(), [(c, base_config[c]) for c in categories]) self._tab_widget.addTab(tab, tab_name) output_tab = QOutputConfigurationPane( self, get_vistrails_persistent_configuration(), get_vistrails_configuration()) self._tab_widget.addTab(output_tab, "Output") self._packages_tab = self.create_packages_tab() self._tab_widget.addTab(self._packages_tab, 'Packages') self._configuration_tab = self.create_configuration_tab() self._tab_widget.addTab(self._configuration_tab, 'Expert') self.connect(self._tab_widget, QtCore.SIGNAL('currentChanged(int)'), self.tab_changed) self.connect(self._configuration_tab._tree.treeWidget, QtCore.SIGNAL('configuration_changed'), self.configuration_changed)
def py_import(module_name, dependency_dictionary, store_in_config=False): """Tries to import a python module, installing if necessary. If the import doesn't succeed, we guess which system we are running on and install the corresponding package from the dictionary. We then run the import again. If the installation fails, we won't try to install that same module again for the session. """ try: result = _vanilla_import(module_name) return result except ImportError: if not getattr(get_vistrails_configuration(), 'installBundles'): raise if module_name in _previously_failed_pkgs: raise PyImportException("Import of Python module '%s' failed again, " "not triggering installation" % module_name) if store_in_config: ignored_packages_list = getattr(get_vistrails_configuration(), 'bundleDeclinedList', None) if ignored_packages_list: ignored_packages = set(ignored_packages_list.split(';')) else: ignored_packages = set() if module_name in ignored_packages: raise PyImportException("Import of Python module '%s' failed " "again, installation disabled by " "configuration" % module_name) debug.warning("Import of python module '%s' failed. " "Will try to install bundle." % module_name) success = vistrails.core.bundles.installbundle.install( dependency_dictionary) if store_in_config: if bool(success): ignored_packages.discard(module_name) else: ignored_packages.add(module_name) setattr(get_vistrails_configuration(), 'bundleDeclinedList', ';'.join(sorted(ignored_packages))) setattr(get_vistrails_persistent_configuration(), 'bundleDeclinedList', ';'.join(sorted(ignored_packages))) if not success: _previously_failed_pkgs.add(module_name) raise PyImportException("Installation of Python module '%s' failed." % module_name) try: result = _vanilla_import(module_name) return result except ImportError, e: _previously_failed_pkgs.add(module_name) raise PyImportBug("Installation of package '%s' succeeded, but import " "still fails." % module_name)
def create_thumbs_tab(self): """ create_thumbs_tab() -> QThumbnailConfiguration """ return QThumbnailConfiguration(self, get_vistrails_persistent_configuration(), get_vistrails_configuration())
def create_general_tab(self): """ create_general_tab() -> QGeneralConfiguration """ return QGeneralConfiguration(self, get_vistrails_persistent_configuration(), get_vistrails_configuration())
def tab_changed(self, index): """ tab_changed(index: int) -> None Keep general and advanced configurations in sync """ # FIXME Need to fix this self._configuration_tab.configuration_changed( get_vistrails_persistent_configuration(), get_vistrails_configuration())
def setUpClass(cls): get_vistrails_configuration().jobAutorun = True get_vistrails_persistent_configuration().jobAutorun = True QJobView.instance().set_refresh() cls.filename = (vistrails.core.system.vistrails_root_directory() + '/tests/resources/jobs.vt') pm = vistrails.core.packagemanager.get_package_manager() if pm.has_package('org.vistrails.vistrails.myjobs'): return d = {'myjob': 'vistrails.tests.resources.'} pm.late_enable_package('myjob', d)
def get_load_file_locator_from_gui(parent, obj_type): suffixes = "*" + " *".join(suffix_map[obj_type]) fileName = QtGui.QFileDialog.getOpenFileName( parent, "Open %s..." % obj_type.capitalize(), vistrails.core.system.vistrails_file_directory(), "VisTrails files (%s)\nOther files (*)" % suffixes) if not fileName: return None filename = os.path.abspath(str(QtCore.QFile.encodeName(fileName))) dirName = os.path.dirname(filename) setattr(get_vistrails_persistent_configuration(), 'fileDir', dirName) setattr(get_vistrails_configuration(), 'fileDir', dirName) vistrails.core.system.set_vistrails_file_directory(dirName) return FileLocator(filename)
def get_load_file_locator_from_gui(parent, obj_type): suffixes = "*" + " *".join(suffix_map[obj_type]) fileName = QtGui.QFileDialog.getOpenFileName( parent, "Open %s..." % obj_type.capitalize(), vistrails.core.system.vistrails_file_directory(), "VisTrails files (%s)\nOther files (*)" % suffixes) if not fileName: return None filename = os.path.abspath(str(QtCore.QFile.encodeName(fileName))) dirName = os.path.dirname(filename) setattr(get_vistrails_persistent_configuration(), 'fileDirectory', dirName) setattr(get_vistrails_configuration(), 'fileDirectory', dirName) vistrails.core.system.set_vistrails_file_directory(dirName) return FileLocator(filename)
def __init__(self): Module.__init__(self) config = get_vistrails_persistent_configuration() if config.check('webRepositoryURL'): self.base_url = config.webRepositoryURL else: raise ModuleError(self, ("No webRepositoryURL value defined" " in the Expert Configuration")) # check if we are running in server mode # this effects how the compute method functions if config.check('isInServerMode'): self.is_server = bool(config.isInServerMode) else: self.is_server = False # TODO: this '/' check should probably be done in core/configuration.py if self.base_url[-1] == '/': self.base_url = self.base_url[:-1]
def get_save_file_locator_from_gui(parent, obj_type, locator=None): # Ignore current locator for now # In the future, use locator to guide GUI for better starting directory suffixes = "*" + " *".join(suffix_map[obj_type]) fileName = QtGui.QFileDialog.getSaveFileName( parent, "Save Vistrail...", vistrails.core.system.vistrails_file_directory(), filter="VisTrails files (%s)" % suffixes, # filetypes.strip() options=QtGui.QFileDialog.DontConfirmOverwrite) if not fileName: return None f = str(QtCore.QFile.encodeName(fileName)) # check for proper suffix found_suffix = False for suffix in suffix_map[obj_type]: if f.endswith(suffix): found_suffix = True break if not found_suffix: if obj_type == 'vistrail': f += get_vistrails_configuration().defaultFileType else: f += suffix_map[obj_type][0] if os.path.isfile(f): msg = QtGui.QMessageBox(QtGui.QMessageBox.Question, "VisTrails", "File exists. Overwrite?", (QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), parent) if msg.exec_() == QtGui.QMessageBox.No: return None dirName = os.path.dirname(f) setattr(get_vistrails_persistent_configuration(), 'fileDir', dirName) setattr(get_vistrails_configuration(), 'fileDir', dirName) vistrails.core.system.set_vistrails_file_directory(dirName) return FileLocator(f)
def get_save_file_locator_from_gui(parent, obj_type, locator=None): # Ignore current locator for now # In the future, use locator to guide GUI for better starting directory suffixes = "*" + " *".join(suffix_map[obj_type]) fileName = QtGui.QFileDialog.getSaveFileName( parent, "Save Vistrail...", vistrails.core.system.vistrails_file_directory(), filter="VisTrails files (%s)" % suffixes, # filetypes.strip() options=QtGui.QFileDialog.DontConfirmOverwrite) if not fileName: return None f = str(QtCore.QFile.encodeName(fileName)) # check for proper suffix found_suffix = False for suffix in suffix_map[obj_type]: if f.endswith(suffix): found_suffix = True break if not found_suffix: if obj_type == 'vistrail': f += get_vistrails_configuration().defaultFileType else: f += suffix_map[obj_type][0] if os.path.isfile(f): msg = QtGui.QMessageBox(QtGui.QMessageBox.Question, "VisTrails", "File exists. Overwrite?", (QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), parent) if msg.exec_() == QtGui.QMessageBox.No: return None dirName = os.path.dirname(f) setattr(get_vistrails_persistent_configuration(), 'fileDirectory', dirName) setattr(get_vistrails_configuration(), 'fileDirectory', dirName) vistrails.core.system.set_vistrails_file_directory(dirName) return FileLocator(f)
def delete_job(self, controller, version_id=None, all=False): if all: for k in self.workflowItems.keys(): workflow = self.workflowItems[k] if workflow.controller is controller: self.jobView.takeTopLevelItem( self.jobView.indexOfTopLevelItem( self.workflowItems[k])) del self.workflowItems[k] return if not version_id: version_id = controller.current_version if controller.locator: conf = configuration.get_vistrails_configuration() if not conf.has('runningJobsList') or not conf.runningJobsList: conf_jobs = [] else: conf_jobs = conf.runningJobsList.split(';') if not conf_jobs: conf_jobs = [] url = controller.locator.to_url() if '?' in url: url += '&workflow=%s' % version_id else: url += '?workflow=%s' % version_id if url in conf_jobs: conf_jobs.remove(url) conf.runningJobsList = ';'.join(conf_jobs) configuration.get_vistrails_persistent_configuration( ).runningJobsList = conf.runningJobsList name = controller.vistrail.locator.short_name else: name = 'Untitled.vt' if (name, version_id) in self.workflowItems: self.jobView.takeTopLevelItem( self.jobView.indexOfTopLevelItem( self.workflowItems[(name, version_id)])) del self.workflowItems[(name, version_id)]
def set_refresh(self, refresh=0): """Changes the timer time. Called when the QComboBox self.interval changes. Updates the configuration and restarts the timer. """ self.updating_now = True refresh = str(refresh) if refresh else '0' if refresh in dict(refresh_states): refresh = dict(refresh_states)[refresh] self.interval.setEditText(str(refresh)) else: refresh = int(refresh) if refresh: if self.timer_id is not None: self.killTimer(self.timer_id) self.timer_id = self.startTimer(refresh * 1000) else: if self.timer_id: self.killTimer(self.timer_id) self.timer_id = None get_vistrails_configuration().jobCheckInterval = refresh get_vistrails_persistent_configuration().jobCheckInterval = refresh self.updating_now = False
def set_refresh(self, refresh=0): """Changes the timer time. Called when the QComboBox self.interval changes. Updates the configuration and restarts the timer. """ self.updating_now = True refresh = str(refresh) if refresh else '0' if refresh in dict(refresh_states): refresh = dict(refresh_states)[refresh] self.interval.setEditText(str(refresh)) else: refresh = int(refresh) if refresh: if self.timer_id is not None: self.killTimer(self.timer_id) self.timer_id = self.startTimer(refresh*1000) else: if self.timer_id: self.killTimer(self.timer_id) self.timer_id = None get_vistrails_configuration().jobCheckInterval = refresh get_vistrails_persistent_configuration().jobCheckInterval = refresh self.updating_now = False
def get_global_setting(cls, k): config = get_vistrails_persistent_configuration().outputDefaultSettings return cls.get_from_config(config, k)
def showEdits(self, checked): get_vistrails_configuration().showInlineParameterWidgets = checked get_vistrails_persistent_configuration( ).showInlineParameterWidgets = checked scene = self.controller.current_pipeline_scene scene.setupScene(self.controller.current_pipeline)
def add_job(self, controller, error, prev='', workflow=None): """ Adds job recursively """ added = False if not prev: if controller.vistrail.locator: name = controller.vistrail.locator.short_name else: name = 'Untitled.vt' version_id = controller.current_version if (name, version_id) not in self.workflowItems: workflow = QWorkflowItem(controller, error, self.jobView) self.jobView.addTopLevelItem(workflow) self.workflowItems[(name, version_id)] = workflow # save job to configuration if controller.vistrail.locator: conf = configuration.get_vistrails_configuration() if not conf.has('runningJobsList') or not conf.runningJobsList: conf_jobs = [] else: conf_jobs = conf.runningJobsList.split(';') if not conf_jobs: conf_jobs = [] url = controller.vistrail.locator.to_url() if '?' in url: url += '&workflow=%d' % version_id else: url += '?workflow=%d' % version_id if not url in conf_jobs: conf_jobs.append(str(url)) conf.runningJobsList = ';'.join(conf_jobs) configuration.get_vistrails_persistent_configuration( ).runningJobsList = conf.runningJobsList else: workflow = self.workflowItems[(name, version_id)] job_name = ((prev+'.') if prev else '') + error.module.__class__.__name__ if not error.children: if not error.queue: # We allow jobs without queue objects, but they will # have to be checked by re-executing the entire workflow workflow.has_queue = False workflow.setIcon(0, theme.get_current_theme().JOB_SCHEDULED) workflow.setToolTip(0, 'To check this workflow it must be re-executed. Make sure "Run To Check" is checked.') #return False # remove any previous instance of this job, if name is shorter if id(error) in workflow.jobs and \ len(job_name) > len(workflow.jobs[id(error)].text(0)): workflow.takeChild(workflow.indexOfChild( workflow.jobs[id(error)])) del workflow.jobs[id(error)] # if we did not keep an already existing job, add it if id(error) not in workflow.jobs: job = QJobItem(job_name, error) workflow.addChild(job) workflow.jobs[id(error)] = job workflow.countJobs() return True else: for child in error.children: result = self.add_job(controller, child, job_name, workflow) if result: added = True return added
def autorunToggled(self, value): get_vistrails_configuration().jobAutorun = value get_vistrails_persistent_configuration().jobAutorun = value
def show_question(which_files, has_distro_pkg, has_pip): if isinstance(which_files, basestring): which_files = [which_files] if qt_available(): from PyQt4 import QtCore, QtGui dialog = QtGui.QDialog() dialog.setWindowTitle("Required packages missing") layout = QtGui.QVBoxLayout() label = QtGui.QLabel( "One or more required packages are missing: %s. VisTrails can " "automatically install them. If you click OK, VisTrails will " "need administrator privileges, and you might be asked for " "the administrator password." % (" ".join(which_files))) label.setWordWrap(True) layout.addWidget(label) if pip_installed and has_pip: use_pip = QtGui.QCheckBox("Use pip") use_pip.setChecked( not has_distro_pkg or ( has_pip and getattr(get_vistrails_configuration(), 'installBundlesWithPip'))) use_pip.setEnabled(has_distro_pkg and has_pip) layout.addWidget(use_pip) remember_align = QtGui.QHBoxLayout() remember_align.addSpacing(20) remember_pip = QtGui.QCheckBox("Remember my choice") remember_pip.setChecked(False) remember_pip.setEnabled(use_pip.isEnabled()) remember_align.addWidget(remember_pip) layout.addLayout(remember_align) elif has_pip: label = QtGui.QLabel("pip package is available but pip is not installed") layout.addWidget(label) buttons = QtGui.QDialogButtonBox( QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel) QtCore.QObject.connect(buttons, QtCore.SIGNAL('accepted()'), dialog, QtCore.SLOT('accept()')) QtCore.QObject.connect(buttons, QtCore.SIGNAL('rejected()'), dialog, QtCore.SLOT('reject()')) layout.addWidget(buttons) dialog.setLayout(layout) hide_splash_if_necessary() if dialog.exec_() != QtGui.QDialog.Accepted: return False else: if pip_installed and has_pip: if remember_pip.isChecked(): setattr(get_vistrails_persistent_configuration(), 'installBundlesWithPip', use_pip.isChecked()) if use_pip.isChecked(): return 'pip' return 'distro' else: print "\nRequired package(s) missing: %s" % (" ".join(which_files)) print ("A required package is missing, but VisTrails can " "automatically install it. " "If you say Yes, VisTrails will need " "administrator privileges, and you " "might be asked for the administrator password.") if has_distro_pkg: print "(VisTrails will use your distribution's package manager)" else: print "(VisTrails will use the 'pip' installer)" print "Give VisTrails permission to try to install package? (y/N)" v = raw_input().upper() if v == 'Y' or v == 'YES': if has_distro_pkg: return 'distro' else: return 'pip'
def create_configuration_tab(self): return QConfigurationWidget(self, get_vistrails_persistent_configuration(), get_vistrails_configuration())
def showEdits(self, checked): get_vistrails_configuration().showInlineParameterWidgets = checked get_vistrails_persistent_configuration().showInlineParameterWidgets = checked scene = self.controller.current_pipeline_scene scene.setupScene(self.controller.current_pipeline)