def __init__(self, name, package, config_file=None, vt_file=None, parent=None): self.name = name self.package = package self.parent = parent self.config_file = config_file self.serializedConfigAlias = None self.vt_file = vt_file self.locator = None if self.vt_file: self.locator = FileLocator(os.path.abspath(self.vt_file)) self.cellnum = 1 self.filenum = 1 self.varnum = 0 self.workflow_tag = None self.workflow = None self.workflow_version = -1 self.filetypes = {} self.qt_filter = None self.files = [] self.cells = [] self.vars = [] self.axes = [] self._widget = None self.alias_widgets = {} self.alias_values = {} self.dependencies = [] self.unsatisfied_deps = [] self.loaded = False self.plot_vistrail = None self.current_parent_version = 0L self.current_controller = None self.variables = [] self.template = None
def executeVistrail(*args, **kwargs): import core.requirements, os core.requirements.check_pyqt4() from core.db.locator import FileLocator from PyQt4 import QtGui import gui.application try: optionsDict = kwargs.get('options', None) v = gui.application.start_application(optionsDict) if v != 0: app = gui.application.get_vistrails_application() if app: app.finishSession() sys.exit(v) app = gui.application.get_vistrails_application() resource_path = kwargs.get('dir', None) if not resource_path: resource_path = app.resource_path if hasattr( app, "resource_path") else None for vistrail_name in args: workflow_dir = resource_path if resource_path else os.path.join( packagePath, "workflows") vistrail_filename = os.path.join(workflow_dir, vistrail_name + '.vt') print " Reading vistrail: ", vistrail_filename f = FileLocator(vistrail_filename) app.builderWindow.open_vistrail(f) except SystemExit, e: app = gui.application.get_vistrails_application() if app: app.finishSession() print "Uncaught exception on initialization: %s" % e sys.exit(e)
def get_vistrail_from_file(filename): from core.db.locator import FileLocator from core.vistrail.vistrail import Vistrail v = FileLocator(filename).load() if type(v) != Vistrail: v = v.vistrail return v
def load_vistrail(self, fname): self._old_logs = None locator = FileLocator(fname) (vistrail, abstraction_files, thumbnail_files, mashups) = \ core.db.io.load_vistrail(locator, False) self._controller.set_vistrail(vistrail, locator, abstraction_files, thumbnail_files, mashups) self._controller.select_latest_version()
def simulate_open_project(self, filepath): locator = FileLocator(filepath) locator.clean_temporaries() from gui.vistrails_window import _app _app.open_vistrail_without_prompt(locator) self.disable_autosave()
def open_vistrail_default(self): """ open_vistrail_default() -> None Opens a vistrail from the file/db """ if self.dbDefault: self.open_vistrail_from_locator(DBLocator) else: self.open_vistrail_from_locator(FileLocator())
def process_interactive_input(self): usedb = False if self.temp_db_options.host: usedb = True if self.input: locator = None #check if versions are embedded in the filename for filename in self.input: f_name, version = self._parse_vtinfo(filename, not usedb) if f_name is None: msg = "Could not find file %s" % filename debug.critical(msg) elif not usedb: locator = FileLocator(os.path.abspath(f_name)) #_vnode and _vtag will be set when a .vtl file is open and # it can be either a FileLocator or a DBLocator elif usedb: locator = DBLocator(host=self.temp_db_options.host, port=self.temp_db_options.port, database=self.temp_db_options.db, user='', passwd='', obj_id=f_name, obj_type=None, connection_id=None) if locator: if hasattr(locator, '_vnode') and \ locator._vnode is not None: version = locator._vnode if hasattr(locator, '_vtag'): # if a tag is set, it should be used instead of the # version number if locator._vtag != '': version = locator._vtag execute = self.temp_configuration.executeWorkflows mashuptrail = None mashupversion = None if hasattr(locator, '_mshptrail'): mashuptrail = locator._mshptrail if hasattr(locator, '_mshpversion'): mashupversion = locator._mshpversion if not self.temp_configuration.showSpreadsheetOnly: self.showBuilderWindow() self.builderWindow.open_vistrail_without_prompt( locator, version, execute, mashuptrail=mashuptrail, mashupVersion=mashupversion) if self.temp_configuration.reviewMode: self.builderWindow.interactiveExportCurrentPipeline()
def setFigureInfo(self, opt_dict): self.doCheckLink(True, opt_dict) if 'showworkflow' in opt_dict: self.figure_type.setCurrentIndex(1) elif 'showtree' in opt_dict: self.figure_type.setCurrentIndex(2) else: self.figure_type.setCurrentIndex(0) if 'version' in opt_dict: self.figure_version.setText(str(opt_dict['version'])) else: self.figure_version.setText("") if 'tag' in opt_dict: self.figure_tag.setEditText(str(opt_dict['tag'])[1:-1]) else: self.figure_tag.setEditText("") if '_args' in opt_dict: self.graphicx_edit.setText(opt_dict['_args']) # build locator if 'filename' in opt_dict: # set using basedir of tex file fname = opt_dict['filename'] if not os.path.isabs(fname): source_dir = os.path.dirname(str(self.source_edit.text())) #print 'source_dir:', str(self.source_edit.text()), source_dir fname = os.path.join(source_dir, fname) locator = FileLocator(fname) elif 'host' in opt_dict: if 'port' not in opt_dict: opt_dict['port'] = '3306' port = int(opt_dict['port']) locator = DBLocator(opt_dict['host'], port, opt_dict['db'], '', '', obj_id=opt_dict['vtid']) else: locator = None if locator is not None: self.figure_ref.setText(locator.to_url()) else: self.figure_ref.setText("") self.figure_ref.locator = locator self.readImage(opt_dict)
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(), core.system.vistrails_file_directory(), "VisTrails files (%s)\nOther files (*)" % suffixes) if fileName.isEmpty(): return None filename = os.path.abspath(str(fileName)) dirName = os.path.dirname(filename) setattr(get_vistrails_persistent_configuration(), 'fileDirectory', dirName) setattr(get_vistrails_configuration(), 'fileDirectory', dirName) core.system.set_vistrails_file_directory(dirName) return FileLocator(filename)
def closeVistrail(self, vistrailView=None, quiet=False): """ closeVistrail(vistrailView: QVistrailView, quiet: bool) -> bool Close the current active vistrail """ if not vistrailView: vistrailView = self.currentWidget() vistrailView.flush_changes() if vistrailView: if not quiet and vistrailView.controller.changed: text = vistrailView.controller.name if text=='': text = 'Untitled%s'%core.system.vistrails_default_file_type() text = ('Vistrail ' + QtCore.Qt.escape(text) + ' contains unsaved changes.\n Do you want to ' 'save changes before closing it?') res = QtGui.QMessageBox.information(getBuilderWindow(), 'Vistrails', text, '&Save', '&Discard', 'Cancel', 0, 2) else: res = 1 locator = vistrailView.controller.locator if res == 0: if locator is None: class_ = FileLocator() else: class_ = type(locator) locator = self.save_vistrail(class_) if not locator: return False elif res == 2: return False vistrailView.controller.close_vistrail(locator) self.removeVistrailView(vistrailView) if self.count()==0: self.emit(QtCore.SIGNAL('currentVistrailChanged'), None) self.emit(QtCore.SIGNAL('versionSelectionChange'), -1) if vistrailView == self._first_view: self._first_view = None return True
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...", core.system.vistrails_file_directory(), "VisTrails files (%s)" % suffixes, # filetypes.strip() None, QtGui.QFileDialog.DontConfirmOverwrite) if fileName.isEmpty(): return None f = str(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(str(f)) setattr(get_vistrails_persistent_configuration(), 'fileDirectory', dirName) setattr(get_vistrails_configuration(), 'fileDirectory', dirName) core.system.set_vistrails_file_directory(dirName) return FileLocator(f)
def load_workflow_as_function(vt_filename, workflow): """load_workflow_as_function(vt_filename: str, workflow: str or int) -> function vt_filename is the path to a vistrail and workflow can be a workflow version or a workflow tag """ from core.vistrail.controller import VistrailController from core.db.locator import FileLocator from core.db.io import load_vistrail def getfunction(controller, doc, **kwargs): def makefunction(*args, **kwargs): return controller.execute_current_workflow( custom_aliases=kwargs, reason='API load_workflow_as_function call') makefunction.__doc__ = doc return makefunction locator = FileLocator(vt_filename) (v, abstractions, thumbnails, mashups) = load_vistrail(locator) controller = VistrailController() controller.set_vistrail(v, locator, abstractions, thumbnails, mashups) if type(workflow) == type("str"): version = v.get_version_number(workflow) elif type(workflow) in [type(1), long]: version = workflow controller.change_selected_version(version) notes = v.get_notes(version) pipeline = controller.current_pipeline docstring = "parameters of the function: \n (" kw_aliases = {} for (a, info) in pipeline.aliases.iteritems(): parameter = pipeline.db_get_object(info[0], info[1]) kw_aliases[a] = parameter.strValue docstring += "%s=%s,\n " % (a, parameter.strValue) docstring = docstring[:-5] + ")\n" if notes != None: docstring += str(notes) return getfunction(controller, docstring, **kw_aliases)
def simulate_save_project(self, filepath, projectController=None): if projectController is None: projectController = self.get_project_controller() projectController.vt_controller.locator = FileLocator(filepath) #projectController.vt_controller.locator.clean_temporaries() self.uvcdat_window.workspace.saveProject(False)
def exportMashup(filename, vtcontroller, mashuptrail, mashupversion, etype): """exportMashup(filename: str, vtcontroller: VistrailController, mashuptrail: Mashuptrail, type: int) -> bool where etype is 0: include full tree 1: include only workflow and mashup identified by version 2: as a link, it will point to a local file. """ result = False if vtcontroller is not None and mashuptrail is not None: locator = vtcontroller.locator version = mashuptrail.vtVersion node = ElementTree.Element('vtlink') if isinstance(locator, DBLocator): node.set('host', str(locator.host)) node.set('port', str(locator.port)) node.set('database', str(locator.db)) node.set('vtid', str(locator.obj_id)) else: node.set('filename', str(locator.name)) node.set('version', str(version)) node.set('execute', "True") node.set('forceDB', "False") node.set('showSpreadsheetOnly', "True") node.set('mashuptrail', str(mashuptrail.id)) node.set('mashupVersion', str(mashupversion)) if etype in [0, 1]: if etype == 1: #minimal pip = vtcontroller.vistrail.getPipeline(version) vistrail = Vistrail() id_remap = {} action = core.db.action.create_paste_action( pip, vistrail.idScope, id_remap) vistrail.add_action(action, 0L, 0) tag = vtcontroller.vistrail.get_tag(version) if tag is None: tag = "Imported workflow" vistrail.addTag(tag, action.id) node.set('version', str(action.id)) id_scope = IdScope(1L) newmashuptrail = Mashuptrail( MashupsManager.getNewMashuptrailId(), action.id, id_scope) maction = mashuptrail.actionMap[mashupversion] mtag = mashuptrail.getTagForActionId(mashupversion) newmashup = copy.copy(maction.mashup) newmashup.remapPipelineObjects(id_remap) currVersion = newmashuptrail.addVersion( newmashuptrail.getLatestVersion(), newmashup, maction.user, maction.date) newmashuptrail.currentVersion = currVersion newmashuptrail.changeTag(currVersion, mtag, maction.user, maction.date) newvtcontroller = BaseVistrailController() newvtcontroller.set_vistrail(vistrail, None) MashupsManager.addMashuptrailtoVistrailController( newvtcontroller, newmashuptrail) node.set('mashuptrail', str(newmashuptrail.id)) node.set('mashupVersion', str(newmashuptrail.currentVersion)) else: vistrail = vtcontroller.vistrail newvtcontroller = MashupsManager.copyBaseVistrailController( vtcontroller) #create temporary file (fd, name) = tempfile.mkstemp(prefix='vt_tmp', suffix='.vt') os.close(fd) fileLocator = FileLocator(name) newvtcontroller.write_vistrail(fileLocator) contents = open(name).read() vtcontent = base64.b64encode(contents) os.unlink(name) #if not vistrail.db_version: # vistrail.db_version = currentVersion node.set('vtcontent', vtcontent) xmlstring = ElementTree.tostring(node) file_ = open(filename, 'w') file_.write(xmlstring) file_.close() result = True return result
print >> original_stderr, "Uncaught exception on initialization: %s" % e import traceback traceback.print_exc(None, original_stderr) sys.exit(255) resource_path = kwargs.get('dir', None) version = kwargs.get('version', None) if not resource_path: resource_path = app.resource_path if hasattr(app, "resource_path") else None for vistrail_name in args: workflow_dir = resource_path if resource_path else os.path.join( packagePath, "workflows") vistrail_filename = os.path.join(workflow_dir, vistrail_name + '.vt') print " Reading vistrail: ", vistrail_filename f = FileLocator(vistrail_filename) app.builderWindow.open_vistrail_without_prompt(f, version, True) if (app.temp_configuration.interactiveMode and not app.temp_configuration.check('spreadsheetDumpCells')): v = app.exec_() gui.application.stop_application() sys.exit(v) if __name__ == '__main__': disable_lion_restore() import cdat_info cdat_info.SOURCE = "UV-CDAT" import gui.requirements
def open_vistrail_from_file(filename): from core.db.locator import FileLocator f = FileLocator(filename) view = get_builder_window().open_vistrail(f) return view
def save_vistrail(self, fname, version=None): locator = FileLocator(fname) self._controller.write_vistrail(locator, version)
def loadVistrailFile(self, vistrail_filename, version=None): from core.db.locator import FileLocator print " Reading vistrail: ", vistrail_filename f = FileLocator(vistrail_filename) self.app.builderWindow.open_vistrail_without_prompt(f, version, True)
def push_vistrail_to_repository(self, branching=False): """ uploads current VisTrail to web repository """ self._repository_status['details'] = "Pushing to repository..." self._push_button.setEnabled(False) self._branch_button.setEnabled(False) self.update_push_information() try: # create temp file self.directory = tempfile.mkdtemp(prefix='vt_tmp') (fd, filename) = tempfile.mkstemp(suffix='.vt', prefix='vt_tmp', dir=self.directory) os.close(fd) # writing tmp vt and switching back to orginal vt locator = ZIPFileLocator(filename) controller = api.get_current_controller() tmp_controller = VistrailController() tmp_controller.set_vistrail(controller.vistrail.do_copy(), locator) tmp_controller.changed = True tmp_controller.write_vistrail(locator) # check if this vt is from the repository if controller.vistrail.get_annotation('repository_vt_id'): repository_vt_id = controller.vistrail.get_annotation( 'repository_vt_id').value else: repository_vt_id = -1 # upload vistrail temp file to repository register_openers(cookiejar=self.dialog.cookiejar) project = self.serverCombo.itemData( self.serverCombo.currentIndex()).toList()[0].toString() if project == "Default": project = "" params = {'vistrail_file': open(filename, 'rb'), 'action': 'upload', 'name': controller.locator.short_name, 'repository_vt_id': repository_vt_id if not branching else -1, 'is_runnable': not bool(len(self.unsupported_packages)+ \ len(self.local_data_modules)), 'vt_id': 0, 'branched_from': "" if not branching else repository_vt_id, 'project': project, 'everyone_can_view': self.perm_view.checkState(), 'everyone_can_edit': self.perm_edit.checkState(), 'everyone_can_download': self.perm_download.checkState() } upload_url = "%s/vistrails/remote_upload/" % \ self.config.webRepositoryURL datagen, headers = multipart_encode(params) request = urllib2.Request(upload_url, datagen, headers) result = urllib2.urlopen(request) updated_response = result.read() os.unlink(filename) if updated_response[:6] == "upload": # No update, just upload if result.code != 200: self._repository_status['details'] = \ "Push to repository failed" else: repository_vt_id = int(updated_response[8:]) controller.vistrail.set_annotation('repository_vt_id', repository_vt_id) controller.vistrail.set_annotation( 'repository_creator', self.dialog.loginUser.text()) # ensure that the annotations get saved controller.set_changed(True) self._repository_status['details'] = \ "Push to repository was successful" else: # update, load updated vistrail if result.code != 200: self._repository_status['details'] = "Update Failed" else: debug.log("getting version from web") # request file to download download_url = "%s/vistrails/download/%s/" % \ (self.config.webRepositoryURL, updated_response) request = urllib2.Request(download_url) result = urllib2.urlopen(request) updated_file = result.read() # create temp file of updated vistrail self.directory = tempfile.mkdtemp(prefix='vt_tmp') (fd, updated_filename) = tempfile.mkstemp(suffix='.vtl', prefix='vtl_tmp', dir=self.directory) os.close(fd) updated_vt = open(updated_filename, 'w') updated_vt.write(updated_file) updated_vt.close() # switch vistrails to updated one controller = api.get_current_controller() updated_locator = FileLocator(updated_filename) (up_vistrail, abstractions, thumbnails, mashups) = \ load_vistrail(updated_locator) controller.set_vistrail(up_vistrail, controller.vistrail.locator, abstractions, thumbnails, mashups) # update version tree drawing controller.recompute_terse_graph() controller.invalidate_version_tree() os.remove(updated_filename) os.remove(updated_filename[:-1]) os.rmdir(self.directory) self._repository_status['details'] = \ "Update to repository was successful" except Exception, e: debug.critical(str(e)) self._repository_status['details'] = "An error occurred"
def loadVistrailFromFile(self, filename): locator = FileLocator(filename) (v, abstractions, thumbnails) = load_vistrail(locator) controller = VistrailController() controller.set_vistrail(v, locator, abstractions, thumbnails) return (v, controller)
def update_from_directory(self, directory): filenames = glob.glob(os.path.join(directory, '*.vt')) for filename in filenames: locator = FileLocator(filename) url = locator.to_url() self.updateVistrail(url)