def initialize(*args, **keywords): if "CLTools" == identifiers.name: # this is the original package location = os.path.join(vistrails.core.system.current_dot_vistrails(), "CLTools") # make sure dir exist if not os.path.isdir(location): try: debug.log("Creating CLTools directory...") os.mkdir(location) except: debug.critical("""Could not create CLTools directory. Make sure '%s' does not exist and parent directory is writable""" % location) sys.exit(1) else: # this is a standalone package so modules are placed in this directory location = os.path.dirname(__file__) reg = vistrails.core.modules.module_registry.get_module_registry() reg.add_module(CLTools, abstract=True) for path in os.listdir(location): if path.endswith(SUFFIX): try: add_tool(os.path.join(location, path)) except Exception as exc: import traceback debug.critical("Package CLTools failed to create module " "from '%s': %s" % (os.path.join(location, path), exc), traceback.format_exc())
def reload_scripts(): remove_all_scripts() if "CLTools" == identifiers.name: # this is the original package location = os.path.join(vistrails.core.system.current_dot_vistrails(), "CLTools") # make sure dir exist if not os.path.isdir(location): try: debug.log("Creating CLTools directory...") os.mkdir(location) except: debug.critical("""Could not create CLTools directory. Make sure '%s' does not exist and parent directory is writable""" % location) sys.exit(1) else: # this is a standalone package so modules are placed in this directory location = os.path.dirname(__file__) for path in os.listdir(location): if path.endswith(SUFFIX): try: add_tool(os.path.join(location, path)) except Exception as exc: import traceback debug.critical("Package CLTools failed to create module " "from '%s': %s" % (os.path.join(location, path), exc), traceback.format_exc()) from vistrails.core.interpreter.cached import CachedInterpreter CachedInterpreter.clear_package(identifiers.identifier) from vistrails.gui.vistrails_window import _app _app.invalidate_pipelines()
def open_workflow(self, locator): if isinstance(locator, basestring): locator = BaseLocator.from_url(locator) vistrail = Vistrail() try: if locator is None: return False if locator is not None: workflow = locator.load(Pipeline) action_list = [] for module in workflow.module_list: action_list.append(('add', module)) for connection in workflow.connection_list: action_list.append(('add', connection)) action = vistrails.core.db.action.create_action(action_list) vistrail.add_action(action, 0L) vistrail.update_id_scope() vistrail.addTag("Imported workflow", action.id) # FIXME might need different locator? controller = self.add_vistrail(vistrail, locator) except VistrailsDBException, e: import traceback debug.critical("Exception from the database", traceback.format_exc()) return None
def execute(self): """ execute() -> None Perform the exploration by collecting a list of actions corresponding to each dimension """ # persist the parameter exploration pe = self.getParameterExploration() pe.action_id = self.controller.current_version # check if pe has changed changed = False if not self.controller.current_parameter_exploration or \ pe != self.controller.current_parameter_exploration: changed = True pe.name = '' self.controller.current_parameter_exploration = pe self.controller.vistrail.add_paramexp(pe) self.controller.set_changed(True) else: pe = self.controller.current_parameter_exploration errors = self.controller.executeParameterExploration(pe, self.get_param_view().pipeline_view.scene()) if errors: errors = '\n'.join(['Position %s: %s' % (error[0], error[1]) for error in errors]) debug.critical("Parameter Exploration Execution had errors", errors) if changed: from vistrails.gui.vistrails_window import _app _app.notify('exploration_changed')
def add_wf_exec_entity(self, wf_exec, add_to_map=False): version_id = wf_exec.parent_version is_new = False if version_id not in self.wf_entity_map: is_new = True # FIXME add new workflow entity for this version if version_id not in self.vistrail.actionMap: raise LookupError("Version %d does not occur in vistrail." % version_id) action = self.vistrail.actionMap[version_id] try: workflow = self.vistrail.getPipeline(version_id) except: import traceback if self.vistrail.has_tag(version_id): tag_str = self.vistrail.get_tag(version_id) else: tag_str = str(version_id) debug.critical("Failed to construct pipeline '%s'" % tag_str, traceback.format_exc()) workflow = self.vistrail.getPipeline(0) wf_entity = self.create_workflow_entity(workflow, action) self.wf_entity_map[version_id] = wf_entity else: wf_entity = self.wf_entity_map[version_id] entity = self.create_wf_exec_entity(wf_exec, wf_entity) if add_to_map: self.wf_exec_entity_map[wf_exec.id] = entity if is_new: return (entity, wf_entity) return (entity, None)
def add_workflow_entity(self, version_id): if version_id not in self.vistrail.actionMap: return action = self.vistrail.actionMap[version_id] tag = None if self.vistrail.has_tag(version_id): tag = self.vistrail.get_tag(version_id) try: workflow = self.vistrail.getPipeline(version_id) except: import traceback debug.critical("Failed to construct pipeline '%s'" % (tag if tag else version_id), traceback.format_exc()) workflow = self.vistrail.getPipeline(0) if tag: workflow.name = tag # if workflow already exists, we want to update it... # spin through self.children and look for matching # workflow entity? # self.children.append(WorkflowEntity(workflow)) self.wf_entity_map[version_id] = \ self.create_workflow_entity(workflow, action) # get thumbnail thumbnail = self.vistrail.get_thumbnail(version_id) if thumbnail is not None: cache = ThumbnailCache.getInstance() path = cache.get_abs_name_entry(thumbnail) if path: entity = ThumbnailEntity(path) self.wf_entity_map[action.id].children.append(entity) entity.parent = self.wf_entity_map[action.id] return self.wf_entity_map[version_id]
def updateController(self, controller): """ updateController(controller: VistrailController) -> None Construct input forms for a controller's variables """ # we shouldn't do this whenver the controller changes... if self.controller != controller: self.controller = controller if self.updateLocked: return self.vWidget.clear() if controller: reg = module_registry.get_module_registry() for var in [v for v in controller.vistrail.vistrail_vars]: try: descriptor = reg.get_descriptor_by_name(var.package, var.module, var.namespace) except module_registry.ModuleRegistryException: debug.critical("Missing Module Descriptor for vistrail" " variable %s\nPackage: %s\nType: %s" "\nNamespace: %s" % \ (var.name, var.package, var.module, var.namespace)) continue self.vWidget.addVariable(var.uuid, var.name, descriptor, var.value) self.vWidget.showPromptByChildren() else: self.vWidget.showPrompt(False)
def import_user_packages_module(self): """Imports the 'userspackages' package. This will need to manipulate the Python path to find it. """ if self._userpackages is not None: return self._userpackages # Imports user packages directory old_sys_path = copy.copy(sys.path) userPackageDir = system.get_vistrails_directory('userPackageDir') if userPackageDir is not None: sys.path.insert(0, os.path.join(userPackageDir, os.path.pardir)) try: import userpackages except ImportError: debug.critical('ImportError: "userpackages" sys.path: %s' % sys.path) raise finally: sys.path = old_sys_path os.environ['VISTRAILS_USERPACKAGES_DIR'] = userPackageDir self._userpackages = userpackages return userpackages # possible that we don't have userPackageDir set! return None
def open_workflow(self, locator, version=None): self.close_first_vistrail_if_necessary() if self.single_document_mode and self.currentView(): self.closeVistrail() vistrail = Vistrail() try: if locator is not None: workflow = locator.load(Pipeline) action_list = [] for module in workflow.module_list: action_list.append(('add', module)) for connection in workflow.connection_list: action_list.append(('add', connection)) action = vistrails.core.db.action.create_action(action_list) vistrail.add_action(action, 0L) vistrail.update_id_scope() vistrail.addTag("Imported workflow", action.id) # FIXME might need different locator? except ModuleRegistryException, e: msg = ('Cannot find module "%s" in package "%s". ' 'Make sure package is ' 'enabled in the Preferences dialog.' % \ (e._name, e._identifier)) debug.critical(msg)
def updateContents(self, conn_id=-1): """updateContents(connection_id: int) -> None Reloads vistrails from the given connection """ self.clear() if conn_id != -1: parent = self.parent() try: objs = parent.connectionList.getDBObjectList(int(conn_id), self.obj_type) for (id,obj,date) in objs: item = QDBObjectListItem(CurrentTheme.FILE_ICON, int(id), str(obj), str(date)) self.addItem(item) except VistrailsDBException, e: #show connection setup error = str(e) if "Couldn't get list of vistrails objects" in error: debug.critical('An error has occurred', error) raise e config = parent.connectionList.getConnectionInfo(int(conn_id)) if config != None: config["create"] = False if not parent.showConnConfig(**config): raise e else: raise e
def __init__(self, address): """ Process WSDL and add all Types and Methods """ self.address = address self.signature = toSignature(self.address) self.wsdlHash = '-1' self.modules = [] self.package = None debug.log("Installing Web Service from WSDL: %s"% address) options = dict(cachingpolicy=1, cache=package_cache) proxy_types = ['http'] for t in proxy_types: key = 'proxy_%s'%t if configuration.check(key): proxy = getattr(configuration, key) debug.log("Using proxy: %s" % proxy) if len(proxy): options['proxy'] = {t:proxy} try: self.service = suds.client.Client(address, **options) self.backUpCache() except Exception, e: self.service = None # We may be offline and the cache may have expired, # try to use backup if self.restoreFromBackup(): try: self.service = suds.client.Client(address, **options) except Exception, e: self.service = None debug.critical("Could not load WSDL: %s" % address, str(e) + '\n' + str(traceback.format_exc()))
def install_default_startupxml_if_needed(): fname = os.path.join(self.temp_configuration.dotVistrails, 'startup.xml') root_dir = system.vistrails_root_directory() origin = os.path.join(root_dir, 'core','resources', 'default_vistrails_startup_xml') def skip(): if os.path.isfile(fname): try: d = self.startup_dom() v = str(d.getElementsByTagName('startup')[0].attributes['version'].value) return LooseVersion('0.1') <= LooseVersion(v) except Exception: return False else: return False if skip(): return try: shutil.copyfile(origin, fname) debug.log('Succeeded!') except Exception, e: debug.critical("""Failed to copy default configuration file to %s. This could be an indication of a permissions problem. Please make sure '%s' is writable.""" % (fname, self.temp_configuration.dotVistrails), e)
def save_as(self, save_bundle, version=None): save_bundle = _DBLocator.save(self, save_bundle, True, version) for obj in save_bundle.get_db_objs(): klass = self.get_convert_klass(obj.vtType) klass.convert(obj) obj.locator = self # Need to copy images into thumbnail cache directory so references # won't become invalid if they are in a temp dir that gets destroyed # when the previous locator is closed import shutil thumb_cache = ThumbnailCache.getInstance() thumb_cache_dir = thumb_cache.get_directory() new_thumbnails = [] for thumbnail in save_bundle.thumbnails: if os.path.dirname(thumbnail) == thumb_cache_dir: new_thumbnails.append(thumbnail) else: cachedir_thumbnail = os.path.join(thumb_cache_dir, os.path.basename(thumbnail)) try: shutil.copyfile(thumbnail, cachedir_thumbnail) new_thumbnails.append(cachedir_thumbnail) except Exception, e: debug.critical("copying %s -> %s failed" % ( thumbnail, cachedir_thumbnail), e)
def updateCells(self, info=None): # check if we should create a sequence if self.cb_loop_sequence.isChecked(): return self.updateCellsLoop(info) self.is_executing = True (cellEvents, errors) = self.runAndGetCellEvents() if errors is True: debug.critical("Mashup job is still running. Run again to check " "if it has completed.") self.is_executing = False if self.numberOfCells is not None and len(cellEvents) != self.numberOfCells: raise RuntimeError( "The number of cells has changed (unexpectedly) " "(%d vs. %d)!\n" "Pipeline results: %s" % (len(cellEvents), self.numberOfCells, errors)) elif self.numberOfCells is None and not errors: self.numberOfCells = len(cellEvents) if cellEvents: self.initCells(cellEvents) #self.SaveCamera() for i in xrange(self.numberOfCells): camera = [] if (hasattr(self.cellWidgets[i],"getRendererList") and self.cb_keep_camera.isChecked()): for ren in self.cellWidgets[i].getRendererList(): camera.append(ren.GetActiveCamera()) self.cellWidgets[i].updateContents(cellEvents[i].inputPorts, camera) #self.cellWidgets[i].updateContents(cellEvents[i].inputPorts) else: self.cellWidgets[i].updateContents(cellEvents[i].inputPorts)
def interpolate(self, ranges, stepCount): """ interpolate(ranges: tuple, stepCount: int) -> list This function takes a number of (min,max) or (s1,...sn) to interpolate exact stepCount number of step. The output will be a list of stepCount elements where each of them is (a1,...,an). a{i} is either int or string and n is the number of arguments. """ params = [] for r in ranges: interpolatedValues = [] argumentType = type(r[0]) if argumentType in [int, float]: for i in xrange(stepCount): if stepCount>1: t = i/float(stepCount-1) else: t = 0 interpolatedValues.append(argumentType(r[0]+t*(r[1]-r[0]))) elif argumentType==str: interpolatedValues = list(r) else: debug.critical('Cannot interpolate non-cardinal types') assert False params.append(interpolatedValues) return zip(*params)
def create_startupxml_if_needed(self): needs_create = True fname = self.get_startup_xml_fname() if os.path.isfile(fname): try: tree = ElementTree.parse(fname) startup_version = \ vistrails.db.services.io.get_version_for_xml(tree.getroot()) version_list = version_string_to_list(startup_version) if version_list >= [0,1]: needs_create = False except: debug.warning("Unable to read startup.xml file, " "creating a new one") if needs_create: root_dir = system.vistrails_root_directory() origin = os.path.join(root_dir, 'core','resources', 'default_vistrails_startup_xml') try: shutil.copyfile(origin, fname) debug.log('Succeeded!') self.first_run = True except: debug.critical("""Failed to copy default configuration file to %s. This could be an indication of a permissions problem. Please make sure '%s' is writable.""" % (fname, self._dot_vistrails)) raise
def open_workflow(self, locator): if isinstance(locator, basestring): locator = BaseLocator.from_url(locator) new_locator = UntitledLocator() controller = self.open_vistrail(new_locator) try: if locator is None: return False workflow = locator.load(Pipeline) action_list = [] for module in workflow.module_list: action_list.append(('add', module)) for connection in workflow.connection_list: action_list.append(('add', connection)) action = vistrails.core.db.action.create_action(action_list) controller.add_new_action(action) controller.perform_action(action) controller.vistrail.set_tag(action.id, "Imported workflow") controller.change_selected_version(action.id) except VistrailsDBException: debug.critical("Exception from the database", traceback.format_exc()) return None controller.select_latest_version() controller.set_changed(True) return controller
def createPackage(self): reg = vistrails.core.modules.module_registry.get_module_registry() if self.signature in reg.packages: reg.remove_package(reg.packages[self.signature]) # create a document hash integer from the cached sax tree # "name" is what suds use as the cache key name = '%s-%s' % (abs(hash(self.address)), "wsdl") wsdl = package_cache.get(name) if not wsdl: debug.critical("File not found in SUDS cache: '%s'" % name) self.wsdlHash = '0' return self.wsdlHash = str(int(hashlib.md5(str(wsdl.root)).hexdigest(), 16)) package_id = reg.idScope.getNewId(Package.vtType) package = Package(id=package_id, load_configuration=False, name="SUDS#" + self.address, identifier=self.signature, version=self.wsdlHash, ) suds_package = reg.get_package_by_name(identifier) package._module = suds_package.module package._init_module = suds_package.init_module self.package = package reg.add_package(package) reg.signals.emit_new_package(self.signature) self.module = new_module(Module, str(self.signature)) reg.add_module(self.module, **{'package':self.signature, 'package_version':self.wsdlHash, 'abstract':True})
def updateVistrail(self): """updateVistrail() -> None Update vistrail to contain changes to the python source """ deleted_ports = [] added_ports = [] if self.has_inputs: (input_deleted_ports, input_added_ports) = \ self.getPortDiff('input', self.inputPortTable) deleted_ports.extend(input_deleted_ports) added_ports.extend(input_added_ports) if self.has_outputs: (output_deleted_ports, output_added_ports) = \ self.getPortDiff('output', self.outputPortTable) deleted_ports.extend(output_deleted_ports) added_ports.extend(output_added_ports) functions = [] modified = False if self.codeEditor.__class__.__name__ not in ['_PythonEditor', '_TextEditor']: modified = self.codeEditor.document().isModified() else: modified = self.codeEditor.isModified() if (self.codeEditor is not None and modified): try: code = str(self.codeEditor.toPlainText()) except UnicodeEncodeError, e: debug.critical('Source Code Editor does not support non-ascii characters', e) return False if self.sourceEncode: code = urllib.quote(code) functions.append((self.sourcePortName, [code]))
def load_entity(self, *args): if args[1] in Collection.entity_types: entity = Collection.entity_types[args[1]].create(*args) return entity else: debug.critical("Cannot find entity type '%s'" % args[1]) return None
def initialize_packages(self, prefix_dictionary={}, report_missing_dependencies=True): """initialize_packages(prefix_dictionary={}): None Initializes all installed packages. If prefix_dictionary is not {}, then it should be a dictionary from package names to the prefix such that prefix + package_name is a valid python import.""" failed = [] # import the modules app = get_vistrails_application() for package in self._package_list.itervalues(): # print '+ initializing', package.codepath, id(package) if package.initialized(): # print '- already initialized' continue try: prefix = prefix_dictionary.get(package.codepath) if prefix is None: prefix = self._default_prefix_dict.get(package.codepath) package.load(prefix) except Package.LoadFailed, e: debug.critical("Package %s failed to load and will be " "disabled" % package.name, e) # We disable the package manually to skip over things # we know will not be necessary - the only thing needed is # the reference in the package list self._startup.set_package_to_disabled(package.codepath) failed.append(package) except MissingRequirement, e: debug.critical("Package <codepath %s> is missing a " "requirement: %s" % ( package.codepath, e.requirement), e)
def import_user_packages_module(self): """Imports the packages module using path trickery to find it in the right place. """ if self._userpackages is not None: return self._userpackages # Imports user packages directory conf = self._startup.temp_configuration old_sys_path = copy.copy(sys.path) userPackageDir = system.get_vistrails_directory('userPackageDir') if userPackageDir is not None: sys.path.insert(0, os.path.join(userPackageDir, os.path.pardir)) try: import userpackages except ImportError: debug.critical('ImportError: "userpackages" sys.path: %s' % sys.path) raise finally: sys.path = old_sys_path os.environ['VISTRAILS_USERPACKAGES_DIR'] = userPackageDir self._userpackages = userpackages return userpackages # possible that we don't have userPackageDir set! return None
def reload_scripts(initial=False, name=None): reg = vistrails.core.modules.module_registry.get_module_registry() if not initial: from vistrails.core.interpreter.cached import CachedInterpreter CachedInterpreter.clear_package(identifiers.identifier) if name is None: remove_all_scripts() else: del cl_tools[name] reg.delete_module(identifiers.identifier, name) if "CLTools" == identifiers.name: # this is the original package location = os.path.join(vistrails.core.system.current_dot_vistrails(), "CLTools") # make sure dir exist if not os.path.isdir(location): # pragma: no cover # pragma: no branch try: debug.log("Creating CLTools directory...") os.mkdir(location) except Exception, e: debug.critical("Could not create CLTools directory. Make " "sure '%s' does not exist and parent directory " "is writable" % location, e) sys.exit(1)
def save_vistrail(self, locator_class, vistrailView=None, force_choose_locator=False): """ force_choose_locator=True triggers 'save as' behavior """ global bobo if not vistrailView: vistrailView = self.currentWidget() vistrailView.flush_changes() if vistrailView: gui_get = locator_class.save_from_gui # get a locator to write to if force_choose_locator: locator = gui_get(self, Vistrail.vtType, vistrailView.controller.locator) else: locator = (vistrailView.controller.locator or gui_get(self, Vistrail.vtType, vistrailView.controller.locator)) if locator == untitled_locator(): locator = gui_get(self, Vistrail.vtType, vistrailView.controller.locator) # if couldn't get one, ignore the request if not locator: return False # update collection vistrailView.controller.flush_delayed_actions() try: vistrailView.controller.write_vistrail(locator) except Exception, e: debug.critical('An error has occurred', str(e)) raise return False try: thumb_cache = ThumbnailCache.getInstance() vistrailView.controller.vistrail.thumbnails = \ vistrailView.controller.find_thumbnails( tags_only=thumb_cache.conf.tagsOnly) vistrailView.controller.vistrail.abstractions = \ vistrailView.controller.find_abstractions( vistrailView.controller.vistrail, True) collection = Collection.getInstance() url = locator.to_url() # create index if not exist entity = collection.fromUrl(url) if entity: # find parent vistrail while entity.parent: entity = entity.parent else: entity = collection.updateVistrail(url, vistrailView.controller.vistrail) # add to relevant workspace categories collection.add_to_workspace(entity) collection.commit() except Exception, e: debug.critical('Failed to index vistrail', str(e))
def updateCellsLoop(self, info=None): """ Run workflow for each step in the loop sequence and collect results. """ interactive = self.cb_loop_int.isChecked() slider = self.sequenceOption.value if info and info[1][0] == slider: # User is moving the slider, so we use the existing result if interactive: if slider.value() < len(self.steps): self.updateRenderedCells(slider.value()) else: for i in xrange(self.numberOfCells): self.cellWidgets[i].setPlayerFrame(slider.value()) return if not interactive: for i in xrange(self.numberOfCells): self.cellWidgets[i].clearHistory() self.is_executing = True self.steps = [] old_value = slider.value() value = slider.minimum() slider.setValue(value) while True: (cellEvents, errors) = self.runAndGetCellEvents() if errors is True: debug.critical("Mashup job is still running. Run again to check " "if it has completed.") if self.numberOfCells is not None and len(cellEvents) != self.numberOfCells: raise RuntimeError( "The number of cells has changed (unexpectedly) " "(%d vs. %d)!\n" "Pipeline results: %s" % (len(cellEvents), self.numberOfCells, errors)) elif self.numberOfCells is None and not errors: self.numberOfCells = len(cellEvents) if cellEvents: self.initCells(cellEvents) if interactive: self.steps.append([]) else: self.steps = [[]] for i in xrange(self.numberOfCells): self.steps[-1].append(cellEvents[i].inputPorts) # show the result self.updateRenderedCells(value if interactive else 0) self.is_executing = True if value >= slider.maximum(): break value += slider.singleStep() slider.setValue(value) self.is_executing = False slider.setValue(old_value) self.loopButton.setEnabled(True)
def run(self, useDefaultValues=False): # Building the list of parameter values params = [] if useDefaultValues: for alias in self.currentMashup.alias_list: params.append((alias.component.vttype, alias.component.vtid, alias.component.val)) else: for (aliasName, edit) in self.cellControls.iteritems(): alias = self.currentMashup.getAliasByName(aliasName) if hasattr(edit, 'contents'): val = str(edit.contents()) else: val =str(edit.text()) params.append((alias.component.vttype, alias.component.vtid, val)) # reset job view from vistrails.gui.job_monitor import QJobView jobView = QJobView.instance() if jobView.updating_now: debug.critical("Execution Aborted: Job Monitor is updating. " "Please wait a few seconds and try again.") return [False, []] jobView.updating_now = True job_id = 'Mashup %s %s' % (self.currentMashup.version, self.currentMashup.id) current_workflow = None for wf in self.view.controller.jobMonitor.workflows.itervalues(): if job_id == wf.version: current_workflow = wf self.view.controller.jobMonitor.startWorkflow(wf) if not current_workflow: current_workflow = JobWorkflow(job_id) self.view.controller.jobMonitor.startWorkflow(current_workflow) self.view.controller.progress = ExecutionProgressDialog(self.view) self.view.controller.progress.show() try: results = self.controller.execute(params)[0] finally: self.view.controller.jobMonitor.finishWorkflow() jobView.updating_now = False self.view.controller.progress.setValue(100) self.view.controller.progress.hide() self.view.controller.progress.deleteLater() self.view.controller.progress = None result = results[0] objs, errors, executed, suspended = \ result.objects, result.errors, result.executed, result.suspended if len(errors) > 0: print '=== ERROR EXECUTING PIPELINE ===' print errors return (False, errors) return (not suspended, [])
def saveToPNG(self, filename): """ saveToPNG(filename: str) -> Bool Abtract function for saving the current widget contents to an image file Returns True when succesful """ debug.critical('saveToPNG() is unimplemented by the inherited cell')
def module_documentation(self, module=None): doc = pydoc.getdoc(self.module) if hasattr(self.module, "get_documentation"): try: doc = self.module.get_documentation(doc, module) except Exception, e: debug.critical("Exception calling get_documentation on %r" % self.module, e) doc = doc or "(Error getting documentation)"
def add_tool(path): try: _add_tool(path) except Exception as exc: # pragma: no cover import traceback debug.critical("Package CLTools failed to create module " "from '%s': %s" % (path, exc), traceback.format_exc())
def saveVistrailFileHook(self, vistrail, tmp_dir): if hasattr(self._init_module, 'saveVistrailFileHook'): try: self._init_module.saveVistrailFileHook(vistrail, tmp_dir) except Exception, e: debug.critical("Got exception in %s's saveVistrailFileHook(): " "%s: %s" % (self.name, type(e).__name__, ', '.join(e.args)))
def setup_init_file(self, dir_name): name = os.path.join(dir_name, '__init__.py') try: f = open(name, 'w') f.write('pass\n') f.close() except: msg = ("""Failed to create file '%s'. This could indicate a rare combination of a race condition and a permissions problem. Please make sure it is writable.""" % name) debug.critical(msg) sys.exit(1)
def getInstance(): if Collection._instance is False: debug.critical("Collection.getInstance() called but the " "Collection has been deleted!") raise RuntimeError("Collection has been deleted!") elif Collection._instance is None: dotVistrails = vistrails.core.system.current_dot_vistrails() path = os.path.join(dotVistrails, "index.db") obj = Collection(path) Collection._instance = obj return Collection._instance
def testConnection(self): """testConnection() -> None """ config = {'host': str(self.hostEdt.text()), 'port': int(self.portEdt.value()), 'user': str(self.userEdt.text()), 'passwd': str(self.passwdEdt.text()), 'db': str(self.databaseEdt.text())} try: vistrails.db.services.io.test_db_connection(config) show_info('Vistrails',"Connection succeeded!") except Exception, e: debug.critical('An error has occurred', e)
def create_directory(self, dir_name): if not os.path.isdir(dir_name): debug.warning('Will try to create directory "%s"' % dir_name) try: os.mkdir(dir_name) return True except Exception, e: msg = ("Failed to create directory: '%s'." "This could be an indication of a permissions problem." "Make sure directory '%s' in writable." % (str(e), dir_name)) debug.critical(msg) sys.exit(1)
def enable_current_package(self): av = self._available_packages_list item = av.currentItem() codepath = str(item.text()) pm = get_package_manager() try: new_deps = self._current_package.dependencies() except Exception, e: debug.critical( "Failed getting dependencies of package %s, " "so it will not be enabled" % self._current_package.name, e) return
def menu_items(self): try: callable_ = self._module.menu_items except AttributeError: return None else: try: return callable_() except Exception, e: debug.unexpected_exception(e) debug.critical("Couldn't load menu items for %s: %s\n%s" % (self.name, debug.format_exception(e), traceback.format_exc()))
def can_handle_identifier(self, identifier): """ Asks package if it can handle this package """ try: return (hasattr(self.init_module, 'can_handle_identifier') and self.init_module.can_handle_identifier(identifier)) except Exception, e: debug.unexpected_exception(e) debug.critical( "Got exception calling %s's can_handle_identifier: " "%s\n%s" % (self.name, debug.format_exception(e), traceback.format_exc())) return False
def can_handle_vt_file(self, name): """ Asks package if it can handle a file inside a zipped vt file """ try: return (hasattr(self.init_module, 'can_handle_vt_file') and self.init_module.can_handle_vt_file(name)) except Exception, e: debug.unexpected_exception(e) debug.critical( "Got exception calling %s's can_handle_vt_file: " "%s\n%s" % (self.name, debug.format_exception(e), traceback.format_exc())) return False
def dependencies(self): deps = [] try: callable_ = self._module.package_dependencies except AttributeError: pass else: try: deps = callable_() except Exception, e: debug.critical( "Couldn't get dependencies of %s: %s: %s" % (self.name, type(e).__name__, ', '.join(e.args)))
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 getChildTypes(type): schema = self.service.wsdl.schema if type in schema.elements: if schema.elements[type].type is not None: return [(schema.elements[type].name, schema.elements[type].type)] else: return [(c[0].name, c[0].type) for c in schema.elements[type].children()] elif type in schema.types: return [(c[0].name, c[0].type) for c in schema.types[type].children()] debug.critical("Could not resolve type in WSDL:" + str(type)) return []
def dependencies(self): deps = [] try: callable_ = self._module.package_dependencies except AttributeError: pass else: try: deps = callable_() except Exception, e: debug.critical("Couldn't get dependencies of %s: %s\n%s" % (self.name, debug.format_exception(e), traceback.format_exc())) deps = []
def update_jobs(self): """Called via a timer. Checks jobs for all workflows both with and without monitors. """ for i in xrange(self.jobView.topLevelItemCount()): vistrail = self.jobView.topLevelItem(i) jm = vistrail.jobMonitor for workflow_item in vistrail.workflowItems.values(): workflow = workflow_item.workflow # jobs without a handle can also be checked if not workflow_item.has_handle: # restart job and execute jm.startWorkflow(workflow) self.updating_now = False workflow_item.execute() self.updating_now = True continue if workflow_item.workflowFinished: continue for job in workflow_item.jobs.itervalues(): if job.jobFinished: continue try: # call monitor job.jobFinished = jm.isDone(job.handle) if job.jobFinished: job.setText(1, "Finished") except Exception, e: debug.critical("Error checking job %s: %s" % (workflow_item.text(0), e)) workflow_item.updateJobs() if workflow_item.workflowFinished: if self.autorun.isChecked(): jm.startWorkflow(workflow) self.updating_now = False workflow_item.execute() self.updating_now = True continue ret = QtGui.QMessageBox.information( self, "Job Ready", 'Pending Jobs in workflow "%s" have finished, ' 'continue execution now?' % workflow_item.text(0), QtGui.QMessageBox.Ok, QtGui.QMessageBox.Cancel) if ret == QtGui.QMessageBox.Ok: jm.startWorkflow(workflow) self.updating_now = False workflow_item.execute() self.updating_now = True
def reload(self, vistrail): if vistrail is not None: self.set_vistrail(vistrail) for version_id in self.vistrail.get_tagMap(): self.add_workflow_entity(version_id) #mashups if hasattr(self.vistrail, 'mashups'): self._mshp_tag_map = {} for mashuptrail in self.vistrail.mashups: self._mshp_tag_map[mashuptrail.id] = \ self.add_mashup_entities_from_mashuptrail(mashuptrail) #parameter explorations if hasattr(self.vistrail, 'parameter_explorations'): self.pe_entity_map = {} # find named pe's #max_pe = {} for pe in self.vistrail.parameter_explorations: if pe.name: self.pe_entity_map[pe.name] = \ self.add_parameter_exploration_entity(pe) # if pe.action_id not in max_pe or max_pe[pe.action_id]<pe.id: # max_pe[pe.action_id] = pe #for pe in max_pe.values(): # if pe.id not in self.pe_entity_map: # self.pe_entity_map[pe.id] = \ # self.add_parameter_exploration_entity(pe) # read persisted log entries log = None try: log = vistrail.get_persisted_log() except Exception, e: debug.unexpected_exception(e) debug.critical("Failed to read log", debug.format_exc()) if log is not None: for wf_exec in log.workflow_execs: self.add_wf_exec_entity(wf_exec, False) # read unpersisted log entries if vistrail.log is not None: for wf_exec in self.vistrail.log.workflow_execs: self.add_wf_exec_entity(wf_exec, True) self._vt_tag_map = copy.copy(self.vistrail.get_tagMap())
def add_workflow_entity(self, version_id): if version_id not in self.vistrail.actionMap: return action = self.vistrail.actionMap[version_id] tag = None if self.vistrail.has_tag(version_id): tag = self.vistrail.get_tag(version_id) try: workflow = self.vistrail.getPipeline(version_id) except Exception, e: debug.unexpected_exception(e) debug.critical( "Failed to construct pipeline '%s'" % (tag if tag else version_id), debug.format_exc()) workflow = self.vistrail.getPipeline(0)
def finalize(self): if not self._initialized: return debug.log("Finalizing %s" % self.name) try: callable_ = self._module.finalize except AttributeError: pass else: try: callable_() except Exception, e: debug.critical( "Couldn't finalize %s: %s: %s" % (self.name, type(e).__name__, ', '.join(e.args)))
def setParameterExplorationOld(self, xmlString): """ setParameterExploration(xmlString: string) -> None Sets the current parameter exploration to the one defined by 'xmlString'. """ if not xmlString: return # Parse/validate the xml try: xmlDoc = parseString(xmlString).documentElement except Exception, e: debug.unexpected_exception(e) debug.critical("Parameter Exploration load failed because of " "invalid XML:\n\n%s" % xmlString) return
def finalize(self): if not self._initialized: return debug.log("Finalizing %s" % self.name) try: callable_ = self._module.finalize except AttributeError: pass else: try: callable_() except Exception, e: debug.unexpected_exception(e) debug.critical("Couldn't finalize %s: %s\n%s" % (self.name, debug.format_exception(e), traceback.format_exc()))
def disable_current_package(self): inst = self._enabled_packages_list item = inst.currentItem() codepath = str(item.text()) pm = get_package_manager() dependency_graph = pm.dependency_graph() identifier = pm.get_package_by_codepath(codepath).identifier if dependency_graph.in_degree(identifier) > 0: rev_deps = dependency_graph.inverse_adjacency_list[identifier] debug.critical("Missing dependency", ("There are other packages that depend on this:\n %s" + "Please disable those first.") % rev_deps) else: pm.late_disable_package(codepath) self.invalidate_current_pipeline()
def initialize(*args, **keywords): # import core.packagemanager global webServicesDict global package_cache #Create a directory for the SUDSWebServices package location = os.path.join(vistrails.core.system.current_dot_vistrails(), "SUDSWebServices") if not os.path.isdir(location): try: debug.log("Creating SUDS cache directory...") os.mkdir(location) except OSError, e: debug.critical( """Could not create SUDS cache directory. Make sure '%s' does not exist and parent directory is writable""" % location, e) sys.exit(1)
def set_key(self, key, value): """ set_key(key: str, value: str) -> None Sets a key value pair in the internal dictionary """ #get the arguments of the frame that called us args = inspect.getargvalues(inspect.currentframe().f_back)[3] try: #this will return the instance of the object that called us caller = id(args['self']) newkey = str(caller) + str(key) hashkey = md5_hash(newkey).hexdigest()[:16] cryptvalue = crypt(hashkey, value) self.__keys[hashkey] = cryptvalue except KeyError: debug.critical("KeyChain: You need to call this method inside " "another a object's method")
def setup_debug(self): if (self.temp_configuration.has('debugLevel') and self.temp_configuration.debugLevel != -1): verbose = self.temp_configuration.debugLevel if verbose < 0: msg = ("""Don't know how to set verboseness level to %s - " "setting to the lowest one I know of: 0""" % verbose) debug.critical(msg) verbose = self.temp_configuration.debugLevel = 0 if verbose > 2: msg = ("""Don't know how to set verboseness level to %s - " "setting to the highest one I know of: 2""" % verbose) debug.critical(msg) verbose = self.temp_configuration.debugLevel = 2 dbg = debug.DebugPrint.getInstance() levels = [dbg.WARNING, dbg.INFO, dbg.DEBUG] dbg.set_message_level(levels[verbose]) debug.log("Set verboseness level to %s" % verbose)
def set_package_information(self): """Looks at current package and sets all labels (name, dependencies, etc.) appropriately. """ assert self._current_package p = self._current_package try: p.load() except Exception, e: msg = 'ERROR: Could not load package.' self._name_label.setText(msg) self._version_label.setText(msg) self._identifier_label.setText(msg) self._dependencies_label.setText(msg) self._description_label.setText(msg) self._reverse_dependencies_label.setText(msg) debug.critical('Cannot load package', e)
def updateVistrail(self): """updateVistrail() -> None Update vistrail to contain changes to the python source """ deleted_ports = [] added_ports = [] if self.has_inputs: (input_deleted_ports, input_added_ports) = \ self.getPortDiff('input', self.inputPortTable) deleted_ports.extend(input_deleted_ports) added_ports.extend(input_added_ports) if self.has_outputs: (output_deleted_ports, output_added_ports) = \ self.getPortDiff('output', self.outputPortTable) deleted_ports.extend(output_deleted_ports) added_ports.extend(output_added_ports) functions = [] modified = False if self.codeEditor.__class__.__name__ not in [ '_PythonEditor', '_TextEditor' ]: modified = self.codeEditor.document().isModified() else: modified = self.codeEditor.isModified() if (self.codeEditor is not None and modified): code = self.codeEditor.toPlainText().encode('utf-8') if self.sourceEncode: code = urllib.quote(code) functions.append((self.sourcePortName, [code])) if len(deleted_ports) + len(added_ports) + len(functions) == 0: # nothing changed return True try: self.controller.update_ports_and_functions(self.module.id, deleted_ports, added_ports, functions) except PortAlreadyExists, e: debug.critical('Port Already Exists %s' % e) return False
def open_vistrail(self, locator=None, version=None, is_abstraction=False): if isinstance(locator, basestring): locator = BaseLocator.from_url(locator) elif locator is None: locator = UntitledLocator() controller = self.ensure_vistrail(locator) if controller is None: # vistrail is not already open try: loaded_objs = vistrails.core.db.io.load_vistrail( locator, is_abstraction) controller = self.add_vistrail(loaded_objs[0], locator, *loaded_objs[1:]) if locator.is_untitled(): return controller controller.is_abstraction = is_abstraction thumb_cache = ThumbnailCache.getInstance() controller.vistrail.thumbnails = controller.find_thumbnails( tags_only=thumb_cache.conf.tagsOnly) controller.vistrail.abstractions = controller.find_abstractions( controller.vistrail, True) controller.vistrail.mashups = controller._mashups collection = Collection.getInstance() url = locator.to_url() entity = collection.updateVistrail(url, controller.vistrail) # add to relevant workspace categories if not controller.is_abstraction: collection.add_to_workspace(entity) collection.commit() except VistrailsDBException as e: debug.unexpected_exception(e) debug.critical("Exception from the database: %s" % e, debug.format_exc()) return None version = self.convert_version(version) if version is None: controller.select_latest_version() version = controller.current_version self.select_version(version) return controller
def create_dot_vistrails_if_necessary(self): if os.path.exists(self._dot_vistrails): if not os.path.isdir(self._dot_vistrails): raise ValueError('The .vistrails directory cannot be used or ' 'created because the specified path "%s" is ' 'a file not a directory.' % self._dot_vistrails) else: return debug.log('Will try to create default directory') try: os.mkdir(self._dot_vistrails) debug.log('Succeeded!') except: debug.critical("""Failed to create initialization directory. This could be an indication of a permissions problem. Make sure parent directory of '%s' is writable.""" % self._dot_vistrails) raise
def show_dialog(parent, id, name, host, port, user, passwd, databaseb, create): dialog = QConnectionDBSetupWindow(parent, id, name, host, port, user, passwd, database, create) config = None if dialog.exec_() == QtGui.QDialog.Accepted: config = {'host': str(dialog.hostEdt.text()), 'port': int(dialog.portEdt.value()), 'user': unicode(dialog.userEdt.text()), 'passwd': unicode(dialog.passwdEdt.text()), 'db': str(dialog.databaseEdt.text()) } try: vistrails.db.services.io.test_db_connection(config) config['succeeded'] = True config['name'] = str(dialog.nameEdt.text()) config['id'] = dialog.id except VistrailsDBException, e: debug.critical('VisTrails DB Exception', e) config['succeeded'] = False
def import_packages_module(self): """Imports the 'vistrails.packages' package. This might need to manipulate the Python path to find it. """ if self._packages is not None: return self._packages # Imports standard packages directory conf = self._startup.temp_configuration old_sys_path = copy.copy(sys.path) if conf.check('packageDirectory'): sys.path.insert(0, conf.packageDirectory) try: import vistrails.packages except ImportError: debug.critical('ImportError: "packages" sys.path: %s' % sys.path) raise finally: sys.path = old_sys_path self._packages = vistrails.packages return vistrails.packages
def import_packages_module(self): """Imports the packages module using path trickery to find it in the right place. """ if self._packages is not None: return self._packages # Imports standard packages directory conf = self._startup.temp_configuration old_sys_path = copy.copy(sys.path) if conf.check('packageDirectory'): sys.path.insert(0, conf.packageDirectory) try: import vistrails.packages except ImportError: debug.critical('ImportError: "packages" sys.path: %s' % sys.path) raise finally: sys.path = old_sys_path self._packages = vistrails.packages return vistrails.packages
def save_vistrail(self, locator=None, controller=None, export=False): if controller is None: controller = self.get_current_controller() if controller is None: return False if locator is None and controller is not None: locator = controller.locator elif isinstance(locator, basestring): locator = BaseLocator.from_url(locator) if not locator: return False old_locator = controller.locator controller.flush_delayed_actions() try: controller.write_vistrail(locator, export=export) except Exception, e: debug.unexpected_exception(e) debug.critical("Failed to save vistrail", debug.format_exc()) raise