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_package(self, codepath): debug.log("package found!") # read manifest try: f = file(os.path.join(self._path, codepath, 'MANIFEST')) except IOError, e: raise InvalidPackage("Package is missing manifest.")
def get_connection(self): if self._conn_id is not None \ and DBLocator.connections.has_key(self._conn_id): connection = DBLocator.connections[self._conn_id] if io.ping_db_connection(connection): return connection else: if self._conn_id is None: if DBLocator.cache_connections.has_key(self._hash): connection = DBLocator.cache_connections[self._hash] if io.ping_db_connection(connection): debug.log("Reusing cached connection") return connection if len(DBLocator.connections.keys()) == 0: self._conn_id = 1 else: self._conn_id = max(DBLocator.connections.keys()) + 1 config = { 'host': self._host, 'port': self._port, 'db': self._db, 'user': self._user, 'passwd': self._passwd } #print "config:", config connection = io.open_db_connection(config) DBLocator.connections[self._conn_id] = connection DBLocator.cache_connections[self._hash] = connection return connection
def get_connection(self): if self._conn_id is not None \ and DBLocator.connections.has_key(self._conn_id): connection = DBLocator.connections[self._conn_id] if io.ping_db_connection(connection): return connection else: if self._conn_id is None: if DBLocator.cache_connections.has_key(self._hash): connection = DBLocator.cache_connections[self._hash] if io.ping_db_connection(connection): debug.log("Reusing cached connection") return connection if len(DBLocator.connections.keys()) == 0: self._conn_id = 1 else: self._conn_id = max(DBLocator.connections.keys()) + 1 config = {'host': self._host, 'port': self._port, 'db': self._db, 'user': self._user, 'passwd': self._passwd} #print "config:", config connection = io.open_db_connection(config) DBLocator.connections[self._conn_id] = connection DBLocator.cache_connections[self._hash] = connection return connection
def unserialize(self, str, obj_type): try: root = ElementTree.fromstring(str) return self.read_xml_object(obj_type, root) except SyntaxError, e: debug.log("Invalid VisTrails serialized object %s"% str) return None
def compute(self): o = self.create_output_file() r = self.getInputFromPort("r") g = self.getInputFromPort("g") b = self.getInputFromPort("b") a = self.getInputFromPort("a") path = None if configuration.check('path'): path = configuration.path if path: cmd = os.path.join(path, 'convert') else: cmd = 'convert' cmd = [ cmd, '-channel', 'RGBA', '-combine', r.name, g.name, b.name, a.name, o.name ] if not configuration.quiet: debug.log(cmd) cmdline = list2cmdline(cmd) result = os.system(cmdline) if result != 0: raise ModuleError(self, "system call failed: '%s'" % cmdline) self.setResult("output", o)
def install_default_startupxml_if_needed(): fname = os.path.join(self.temp_configuration.dotVistrails, 'startup.xml') root_dir = core.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) r = core.utils.version_string_to_list(v) return r >= [0, 1] except: return False else: return False if skip(): return try: shutil.copyfile(origin, fname) debug.log('Succeeded!') 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.temp_configuration.dotVistrails))
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_package(self, codepath): debug.log("package found!") # read manifest try: f = urllib2.urlopen(self._path + '/' + codepath + '/MANIFEST') except urllib2.HTTPError, e: raise InvalidPackage("Package is missing manifest.")
def initialize(*args, **keywords): if "CLTools" == name: # this is the original package location = os.path.join(core.system.default_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 = 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), str(exc)), traceback.format_exc())
def reload_scripts(): global cl_tools from core.interpreter.cached import CachedInterpreter CachedInterpreter.flush() reg = core.modules.module_registry.get_module_registry() for tool_name in cl_tools.keys(): reg.delete_module(identifier, tool_name) del cl_tools[tool_name] if "CLTools" == name: # this is the original package location = os.path.join(core.system.default_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), str(exc)), traceback.format_exc())
def initialize(*args, **keywords): reg = core.modules.module_registry.get_module_registry() basic = core.modules.basic_modules reg.add_module(HTTP, abstract=True) reg.add_module(HTTPFile) reg.add_input_port(HTTPFile, "url", (basic.String, "URL")) reg.add_output_port(HTTPFile, "file", (basic.File, "local File object")) reg.add_output_port(HTTPFile, "local_filename", (basic.String, "local filename"), optional=True) reg.add_module(RepoSync) reg.add_input_port(RepoSync, "file", (basic.File, "File")) reg.add_input_port(RepoSync, "checksum", (basic.String, "Checksum"), optional=True) reg.add_output_port(RepoSync, "file", (basic.File, "Repository Synced File object")) reg.add_output_port(RepoSync, "checksum", (basic.String, "Checksum"), optional=True) global package_directory package_directory = core.system.default_dot_vistrails() + "/HTTP" if not os.path.isdir(package_directory): try: debug.log("Creating HTTP package directory: %s" % package_directory) os.mkdir(package_directory) except: debug.critical( ("Create directory failed. Make sure '%s' does not" " exist and parent directory is writable") % package_directory ) sys.exit(1)
def install_default_startupxml_if_needed(): fname = os.path.join(self.temp_configuration.dotVistrails, 'startup.xml') root_dir = core.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) r = core.utils.version_string_to_list(v) return r >= [0, 1] except: return False else: return False if skip(): return try: shutil.copyfile(origin, fname) debug.log('Succeeded!') 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.temp_configuration.dotVistrails))
def initialize(*args, **keywords): if "CLTools" == name: # this is the original package location = os.path.join(core.system.default_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 = core.modules.module_registry.get_module_registry() reg.add_module(CLTools, hide_descriptor=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), str(exc)), traceback.format_exc(), )
def temp_autosave_changed(self, on): """ temp_autosave_changed(on: int) -> None """ debug.log("thumbs_temp_auto_save_changed") value = bool(on) if self._autosave_cb.text() == "No (for this session only)": value = not bool(on) self._temp_configuration.thumbs.autoSave = value
def temp_mouse_hover_changed(self, on): """ temp_mouse_hover_changed(on: int) -> None """ debug.log("thumbs_temp_mouse_hover_changed") value = bool(on) if self._mouse_hover_cb.text() == "No (for this session only)": value = not bool(on) self._temp_configuration.thumbs.mouseHover = value
def temp_use_cache_changed(self, on): """ temp_use_cache_changed(on: int) -> None """ debug.log("temp_use_cache_changed") value = bool(on) if self._use_cache_cb.text() == "No (for this session only)": value = not bool(on) self._temp_configuration.useCache = value
def temp_db_connect_changed(self, on): """ temp_db_connect_changed(on: int) -> None """ debug.log("temp_db_connect_changed") value = bool(on) if self._db_connect_cb.text() == "No (for this session only)": value = not bool(on) self._temp_configuration.dbDefault = value
def create_default_directory(self): if os.path.lexists(self.temp_configuration.dotVistrails): return debug.log('Will try to create default directory') try: os.mkdir(self.temp_configuration.dotVistrails) 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.temp_configuration.dotVistrails) sys.exit(1)
def get_repository(): global _repository if _repository: return _repository import core.configuration conf = core.configuration.get_vistrails_configuration() if conf.check('repositoryHTTPURL'): _repository = HTTPPackageRepository(conf.repositoryHTTPURL) debug.log("Using HTTP Package Repository @ %s" % conf.repositoryHTTPURL) elif conf.check('repositoryLocalPath'): _repository = LocalPackageRepository(conf.repositoryLocalPath) debug.log("Using Local Repository @ %s" % conf.repositoryLocalPath) else: _repository = None return _repository
def install_default_startup(): debug.log('Will try to create default startup script') try: root_dir = core.system.vistrails_root_directory() default_file = os.path.join(root_dir,'core','resources', 'default_vistrails_startup') user_file = os.path.join(self.temp_configuration.dotVistrails, 'startup.py') shutil.copyfile(default_file,user_file) debug.log('Succeeded!') except: debug.critical("""Failed to copy default file %s. This could be an indication of a permissions problem. Make sure directory '%s' is writable""" % (user_file,self.temp_configuration.dotVistrails)) sys.exit(1)
def finalize(self): if not self._initialized: return debug.log("Finalizing %s" % self.name) try: callable_ = self._module.finalize except AttributeError: pass else: callable_() # Save configuration if self.configuration: self.set_persistent_configuration() self.unload() self._module = None self._init_module = None self._initialized = False
def autosave_changed(self, on): """ autosave_changed(on: bool) -> None """ debug.log("thumbs_auto_save_changed") if self._autosave_always.isChecked() == True: value = True self._autosave_cb.setText("No (for this session only)") self._autosave_cb.setChecked(False) else: value = False self._autosave_cb.setText("Yes (for this session only)") self._autosave_cb.setChecked(False) self._configuration.thumbs.autoSave = value self._temp_configuration.thumbs.autoSave = value self.emit(QtCore.SIGNAL("configuration_changed"), None, bool(on))
def install_default_startup(): debug.log('Will try to create default startup script') try: root_dir = core.system.vistrails_root_directory() default_file = os.path.join(root_dir, 'core', 'resources', 'default_vistrails_startup') user_file = os.path.join(self.temp_configuration.dotVistrails, 'startup.py') shutil.copyfile(default_file, user_file) debug.log('Succeeded!') except: debug.critical( """Failed to copy default file %s. This could be an indication of a permissions problem. Make sure directory '%s' is writable""" % (user_file, self.temp_configuration.dotVistrails)) sys.exit(1)
def run(self, *args): """run(*args), runs ImageMagick's 'convert' on a shell, passing all arguments to the program.""" path = None if configuration.check('path'): path = configuration.path if path: cmd = os.path.join(path, 'convert') else: cmd = 'convert' cmd = [cmd] + list(args) cmdline = list2cmdline(cmd) if not configuration.quiet: debug.log(cmdline) r = os.system(cmdline) if r != 0: raise ModuleError(self, "system call failed: '%s'" % cmdline)
def autosave_changed(self, on): """ autosave_changed(on: bool) -> None """ debug.log("thumbs_auto_save_changed") if self._autosave_always.isChecked() == True: value = True self._autosave_cb.setText("No (for this session only)") self._autosave_cb.setChecked(False) else: value = False self._autosave_cb.setText("Yes (for this session only)") self._autosave_cb.setChecked(False) self._configuration.thumbs.autoSave = value self._temp_configuration.thumbs.autoSave = value self.emit(QtCore.SIGNAL('configuration_changed'), None, bool(on))
def run(self, *args): """run(*args), runs ImageMagick's 'convert' on a shell, passing all arguments to the program.""" path = None if configuration.check('path'): path = configuration.path if path: cmd = os.path.join(path,'convert') else: cmd = 'convert' cmd = [cmd] + list(args) cmdline = list2cmdline(cmd) if not configuration.quiet: debug.log(cmdline) r = os.system(cmdline) if r != 0: raise ModuleError(self, "system call failed: '%s'" % cmdline)
def mouse_hover_changed(self, on): """ mouse_hover_changed(on: bool) -> None """ debug.log("thumbs_mouse_hover_changed") if self._mouse_hover_always.isChecked() == True: value = True self._mouse_hover_cb.setText("No (for this session only)") self._mouse_hover_cb.setChecked(False) else: value = False self._mouse_hover_cb.setText("Yes (for this session only)") self._mouse_hover_cb.setChecked(False) self._configuration.thumbs.mouseHover = value self._temp_configuration.thumbs.mouseHover = value self.emit(QtCore.SIGNAL("configuration_changed"), None, bool(on))
def initialize(*args, **keywords): """ initialize() -> None Package-entry to initialize the package """ debug.log('Loading Spreadsheet widgets...') global basicWidgets if basicWidgets==None: basicWidgets = addWidget('packages.spreadsheet.basic_widgets') importWidgetModules(basicWidgets) # Create application if there is no one available global app app = QtCore.QCoreApplication.instance() if app==None: app = QtGui.QApplication(sys.argv) if hasattr(app, 'builderWindow'): global spreadsheetWindow spreadsheetWindow = spreadsheetController.findSpreadsheetWindow(show=False)
def create_abstractions_dir(abstractions_dir=None): debug.log('Will try to create subworkflows directory') abstractions_dir = os.path.join( self.temp_configuration.dotVistrails, 'subworkflows') if not os.path.isdir(abstractions_dir): try: os.mkdir(abstractions_dir) self.configuration.abstractionsDirectory = abstractions_dir self.temp_configuration.abstractionsDirectory = \ abstractions_dir except: msg = ("Failed to create subworkflows directory: '%s'. " "This could be an indication of a permissions " "problem. Make sure directory '%s' is writable." % \ (abstractions_dir, self.configuration.dotVistrails)) debug.critical(msg) sys.exit(1)
def create_abstractions_dir(abstractions_dir=None): debug.log('Will try to create subworkflows directory') abstractions_dir = os.path.join(self.temp_configuration.dotVistrails, 'subworkflows') if not os.path.isdir(abstractions_dir): try: os.mkdir(abstractions_dir) self.configuration.abstractionsDirectory = abstractions_dir self.temp_configuration.abstractionsDirectory = \ abstractions_dir except: msg = ("Failed to create subworkflows directory: '%s'. " "This could be an indication of a permissions " "problem. Make sure directory '%s' is writable." % \ (abstractions_dir, self.configuration.dotVistrails)) debug.critical(msg) sys.exit(1)
def create_thumbnails_dir(thumbnails_dir=None): debug.log('Will try to create thumbnails directory') if thumbnails_dir is None: thumbnails_dir = os.path.join( self.temp_configuration.dotVistrails, 'thumbs') if not os.path.isdir(thumbnails_dir): try: os.mkdir(thumbnails_dir) self.configuration.thumbs.cacheDirectory = thumbnails_dir self.temp_configuration.thumbs.cacheDirectory = \ thumbnails_dir except: msg = ("Failed to create thumbnails cache directory: '%s'. " "This could be an indication of a permissions " "problem. Make sure directory '%s' is writable." % \ (thumbnails_dir, self.configuration.dotVistrails)) debug.critical(msg) sys.exit(1)
def addWidget(packagePath): """ addWidget(packagePath: str) -> package Add a new widget type to the spreadsheet registry supplying a basic set of spreadsheet widgets """ try: registry = get_module_registry() widget = importReturnLast(packagePath) if hasattr(widget, 'widgetName'): widgetName = widget.widgetName() else: widgetName = packagePath widget.registerWidget(registry, basic_modules, basicWidgets) spreadsheetRegistry.registerPackage(widget, packagePath) debug.log(' ==> Successfully import <%s>' % widgetName) except: debug.log(' ==> Ignored package <%s>' % packagePath) widget = None return widget
def dispatch_request(controller, module_id, current_pipeline): reg = get_module_registry() pm = get_package_manager() if module_id not in current_pipeline.modules: # It is possible that some other upgrade request has # already removed the invalid module of this request. In # that case, disregard the request. debug.log("module %s already handled. skipping" % module_id) return [] invalid_module = current_pipeline.modules[module_id] pkg = pm.get_package_by_identifier(invalid_module.package) if hasattr(pkg.module, 'handle_module_upgrade_request'): f = pkg.module.handle_module_upgrade_request return f(controller, module_id, current_pipeline) else: debug.log('Package "%s" cannot handle upgrade request. ' 'VisTrails will attempt automatic upgrade.' % \ pkg.identifier) auto_upgrade = UpgradeWorkflowHandler.attempt_automatic_upgrade return auto_upgrade(controller, current_pipeline, module_id)
def create_thumbnails_dir(thumbnails_dir=None): debug.log('Will try to create thumbnails directory') if thumbnails_dir is None: thumbnails_dir = os.path.join(self.temp_configuration.dotVistrails, 'thumbs') if not os.path.isdir(thumbnails_dir): try: os.mkdir(thumbnails_dir) self.configuration.thumbs.cacheDirectory = thumbnails_dir self.temp_configuration.thumbs.cacheDirectory = \ thumbnails_dir except: msg = ("Failed to create thumbnails cache directory: '%s'. " "This could be an indication of a permissions " "problem. Make sure directory '%s' is writable." % \ (thumbnails_dir, self.configuration.dotVistrails)) debug.critical(msg) sys.exit(1)
def reload_scripts(): global cl_tools from core.interpreter.cached import CachedInterpreter CachedInterpreter.flush() reg = core.modules.module_registry.get_module_registry() for tool_name in cl_tools.keys(): reg.delete_module(identifier, tool_name) del cl_tools[tool_name] if "CLTools" == name: # this is the original package location = os.path.join(core.system.default_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), str(exc)), traceback.format_exc(), )
def initialize(*args, **keywords): # import core.packagemanager global webServicesDict global package_cache #Create a directory for the SUDSWebServices package location = os.path.join(core.system.default_dot_vistrails(), "SUDSWebServices") if not os.path.isdir(location): try: debug.log("Creating SUDS cache directory...") os.mkdir(location) except: debug.critical( """Could not create SUDS cache directory. Make sure '%s' does not exist and parent directory is writable""" % location) sys.exit(1) # the number of days to cache wsdl files days = 1 if configuration.check("cache_days"): days = configuration.cache_days suds.client.ObjectCache.protocol = 0 # windows needs this package_cache = suds.client.ObjectCache(location, days=days) #reg = core.modules.module_registry.get_module_registry() #reg.add_module(SUDSWebService, abstract=True) wsdlList = [] if configuration.check('wsdlList'): wsdlList = configuration.wsdlList.split(";") else: configuration.wsdlList = '' for wsdl in wsdlList: if not wsdl.startswith('http://'): wsdl = 'http://' + wsdl if wsdl in webServicesDict: debug.warning('Duplicate WSDL entry: '+wsdl) continue s = Service(wsdl) if s.service: webServicesDict[wsdl] = s
def initialize(*args, **keywords): # import core.packagemanager global webServicesDict global package_cache #Create a directory for the SUDSWebServices package location = os.path.join(core.system.default_dot_vistrails(), "SUDSWebServices") if not os.path.isdir(location): try: debug.log("Creating SUDS cache directory...") os.mkdir(location) except: debug.critical("""Could not create SUDS cache directory. Make sure '%s' does not exist and parent directory is writable""" % location) sys.exit(1) # the number of days to cache wsdl files days = 1 if configuration.check("cache_days"): days = configuration.cache_days suds.client.ObjectCache.protocol = 0 # windows needs this package_cache = suds.client.ObjectCache(location, days=days) #reg = core.modules.module_registry.get_module_registry() #reg.add_module(SUDSWebService, abstract=True) wsdlList = [] if configuration.check('wsdlList'): wsdlList = configuration.wsdlList.split(";") else: configuration.wsdlList = '' for wsdl in wsdlList: if not wsdl.startswith('http://'): wsdl = 'http://' + wsdl if wsdl in webServicesDict: debug.warning('Duplicate WSDL entry: ' + wsdl) continue s = Service(wsdl) if s.service: webServicesDict[wsdl] = s
def compute(self): o = self.create_output_file() r = self.getInputFromPort("r") g = self.getInputFromPort("g") b = self.getInputFromPort("b") a = self.getInputFromPort("a") path = None if configuration.check('path'): path = configuration.path if path: cmd = os.path.join(path,'convert') else: cmd = 'convert' cmd = [cmd, '-channel', 'RGBA', '-combine', r.name, g.name, b.name, a.name, o.name] if not configuration.quiet: debug.log(cmd) cmdline = list2cmdline(cmd) result = os.system(cmdline) if result != 0: raise ModuleError(self, "system call failed: '%s'" % cmdline) self.setResult("output", o)
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.""" packages = self.import_packages_module() userpackages = self.import_user_packages_module() failed = [] # import the modules existing_paths = set(sys.modules.iterkeys()) for package in self._package_list.itervalues(): if package.initialized(): continue debug.log("Initializing %s" % package.codepath) try: package.load(prefix_dictionary.get(package.codepath, None), existing_paths) except Package.LoadFailed, e: debug.critical( "Package %s failed to load and will be " "disabled" % package.name, str(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 package.remove_own_dom_element() failed.append(package) except MissingRequirement, e: debug.critical( "Package <codepath %s> is missing a " "requirement: %s" % (package.codepath, e.requirement), str(e))
def __init__(self, database=None): if database is None: self.database = ':memory:' else: self.database = database self.entities = {} self.deleted_entities = {} self.temp_entities = {} self.workspaces = {} self.currentWorkspace = 'Default' self.listeners = [] # listens for entity creation removal self.max_id = 0 if not os.path.exists(self.database): debug.log("'%s' does not exist. Trying to create" % self.database) self.conn = sqlite3.connect(self.database) try: cur = self.conn.cursor() [cur.execute(s) for s in schema] self.conn.commit() except Exception, e: debug.critical("Could not create vistrail index schema", str(e))
def initialize(*args, **keywords): """ initialize() -> None Package-entry to initialize the package """ import core.application if not core.application.is_running_gui(): raise Exception, "GUI is not running. The Spreadsheet package requires the GUI" # initialize widgets debug.log('Loading Spreadsheet widgets...') global basicWidgets if basicWidgets==None: basicWidgets = addWidget('packages.spreadsheet.basic_widgets') importWidgetModules(basicWidgets) # Create application if there is no one available global app app = QtCore.QCoreApplication.instance() if app==None: app = QtGui.QApplication(sys.argv) if hasattr(app, 'builderWindow'): global spreadsheetWindow spreadsheetWindow = spreadsheetController.findSpreadsheetWindow(show=False)
def initialize(*args, **keywords): reg = core.modules.module_registry.get_module_registry() basic = core.modules.basic_modules reg.add_module(HTTP, abstract=True) reg.add_module(HTTPFile) reg.add_input_port(HTTPFile, "url", (basic.String, 'URL')) reg.add_output_port(HTTPFile, "file", (basic.File, 'local File object')) reg.add_output_port(HTTPFile, "local_filename", (basic.String, 'local filename'), optional=True) reg.add_module(RepoSync) reg.add_input_port(RepoSync, "file", (basic.File, 'File')) reg.add_input_port(RepoSync, "checksum", (basic.String, 'Checksum'), optional=True) reg.add_output_port(RepoSync, "file", (basic.File, 'Repository Synced File object')) reg.add_output_port(RepoSync, "checksum", (basic.String, 'Checksum'), optional=True) global package_directory package_directory = core.system.default_dot_vistrails() + "/HTTP" if not os.path.isdir(package_directory): try: debug.log("Creating HTTP package directory: %s" % package_directory) os.mkdir(package_directory) except: debug.critical(("Create directory failed. Make sure '%s' does not" " exist and parent directory is writable") % package_directory) sys.exit(1)
def setupDefaultFolders(self): """ setupDefaultFolders() -> None Give default values to folders when there are no values specified """ if self.temp_configuration.has('rootDirectory'): system.set_vistrails_root_directory( self.temp_configuration.rootDirectory) if self.temp_configuration.has('dataDirectory'): system.set_vistrails_data_directory( \ self.temp_configuration.dataDirectory) if self.temp_configuration.has('fileDirectory'): system.set_vistrails_file_directory( \ self.temp_configuration.fileDirectory) if (self.temp_configuration.has('verbosenessLevel') and self.temp_configuration.verbosenessLevel != -1): verbose = self.temp_configuration.verbosenessLevel 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 = 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 = 2 dbg = debug.DebugPrint.getInstance() levels = [dbg.Critical, dbg.Warning, dbg.Log] dbg.set_message_level(levels[verbose]) debug.log("Set verboseness level to %s" % verbose) #these checks may need to update the persistent configuration, so # we have to change both objects #userpackages directory if not self.temp_configuration.check('userPackageDirectory'): s = os.path.join(self.temp_configuration.dotVistrails, 'userpackages') self.temp_configuration.userPackageDirectory = s if not self.configuration.check('userPackageDirectory'): s = os.path.join(self.configuration.dotVistrails, 'userpackages') self.configuration.userPackageDirectory = s #abstractions directory if not self.temp_configuration.check('abstractionsDirectory') or \ self.temp_configuration.abstractionsDirectory == \ os.path.join(self.temp_configuration.userPackageDirectory, 'abstractions'): s = os.path.join(self.temp_configuration.dotVistrails, 'subworkflows') self.temp_configuration.abstractionsDirectory = s if not self.configuration.check('abstractionsDirectory') or \ self.configuration.abstractionsDirectory == \ os.path.join(self.configuration.userPackageDirectory, 'abstractions'): s = os.path.join(self.configuration.dotVistrails, 'subworkflows') self.configuration.abstractionsDirectory = s #thumbnails directory if self.temp_configuration.has('thumbs'): if not self.temp_configuration.thumbs.check('cacheDirectory'): s = os.path.join(self.temp_configuration.dotVistrails, 'thumbs') self.temp_configuration.thumbs.cacheDirectory = s if self.configuration.has('thumbs'): if not self.configuration.thumbs.check('cacheDirectory'): s = os.path.join(self.configuration.dotVistrails, 'thumbs') self.configuration.thumbs.cacheDirectory = s
def initialize(): def parse_error_if_not_equal(s, expected): if s != expected: err = "Parse error on version line. Was expecting '%s', got '%s'" raise Exception(err % (s, expected)) debug.log("ImageMagick VisTrails package") # print "Will test ImageMagick presence..." # # if not configuration.check('path'): # cmd = 'convert' # if (not core.requirements.executable_file_exists('convert') and # not core.bundles.install({'linux-ubuntu': 'imagemagick'})): # raise core.requirements.MissingRequirement("ImageMagick suite") # else: # cmd = os.path.join(configuration.path,'convert') # cmdline = list2cmdline([cmd, '-version']) # # if core.system.systemType not in ['Windows', 'Microsoft']: # process = popen2.Popen4(cmdline) # # result = -1 # while result == -1: # result = process.poll() # conv_output = process.fromchild # else: # conv_output, input = popen2.popen4(cmdline) # result = 0 # # version_line = conv_output.readlines()[0][:-1].split(' ') # if result != 0: # raise Exception("ImageMagick does not seem to be present.") # print "Ok, found ImageMagick" # parse_error_if_not_equal(version_line[0], 'Version:') # parse_error_if_not_equal(version_line[1], 'ImageMagick') # print "Detected version %s" % version_line[2] # global __version__ # __version__ = version_line[2] reg = core.modules.module_registry.get_module_registry() basic = core.modules.basic_modules reg.add_module(ImageMagick, abstract=True) reg.add_input_port(ImageMagick, "input", (basic.File, 'the input file')) reg.add_input_port(ImageMagick, "inputFormat", (basic.String, 'coerce interpretation of file to this format')) reg.add_input_port(ImageMagick, "outputFormat", (basic.String, 'Force output to be of this format')) reg.add_module(Convert) reg.add_input_port(Convert, "geometry", (basic.String, 'ImageMagick geometry')) reg.add_input_port(Convert, "width", (basic.String, 'width of the geometry for operation')) reg.add_input_port(Convert, "height", (basic.String, 'height of the geometry for operation')) reg.add_output_port(Convert, "output", (basic.File, 'the output file')) for (name, opt, doc_string) in no_param_options: m = new_module(Convert, name, no_param_options_method_dict(opt), docstring=doc_string) reg.add_module(m) for (name, opt, paramName, paramComment) in float_param_options: m = new_module(Convert, name, float_param_options_method_dict(opt, paramName)) reg.add_module(m) reg.add_input_port(m, paramName, (basic.Float, paramComment)) reg.add_module(GaussianBlur) reg.add_input_port(GaussianBlur, "radiusSigma", [(basic.Float, 'radius'), (basic.Float, 'sigma')]) reg.add_module(Scale) reg.add_module(CombineRGBA) reg.add_input_port(CombineRGBA, "r", basic.File) reg.add_input_port(CombineRGBA, "g", basic.File) reg.add_input_port(CombineRGBA, "b", basic.File) reg.add_input_port(CombineRGBA, "a", basic.File) reg.add_input_port(CombineRGBA, "outputFormat", basic.String) reg.add_output_port(CombineRGBA, "output", basic.File)
def setupDefaultFolders(self): """ setupDefaultFolders() -> None Give default values to folders when there are no values specified """ if self.temp_configuration.has('rootDirectory'): system.set_vistrails_root_directory(self.temp_configuration.rootDirectory) if self.temp_configuration.has('dataDirectory'): system.set_vistrails_data_directory( \ self.temp_configuration.dataDirectory) if self.temp_configuration.has('fileDirectory'): system.set_vistrails_file_directory( \ self.temp_configuration.fileDirectory) if (self.temp_configuration.has('verbosenessLevel') and self.temp_configuration.verbosenessLevel != -1): verbose = self.temp_configuration.verbosenessLevel 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 = 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 = 2 dbg = debug.DebugPrint.getInstance() levels = [dbg.Critical, dbg.Warning, dbg.Log] dbg.set_message_level(levels[verbose]) debug.log("Set verboseness level to %s" % verbose) #these checks may need to update the persistent configuration, so # we have to change both objects #userpackages directory if not self.temp_configuration.check('userPackageDirectory'): s = os.path.join(self.temp_configuration.dotVistrails, 'userpackages') self.temp_configuration.userPackageDirectory = s if not self.configuration.check('userPackageDirectory'): s = os.path.join(self.configuration.dotVistrails, 'userpackages') self.configuration.userPackageDirectory = s #abstractions directory if not self.temp_configuration.check('abstractionsDirectory') or \ self.temp_configuration.abstractionsDirectory == \ os.path.join(self.temp_configuration.userPackageDirectory, 'abstractions'): s = os.path.join(self.temp_configuration.dotVistrails, 'subworkflows') self.temp_configuration.abstractionsDirectory = s if not self.configuration.check('abstractionsDirectory') or \ self.configuration.abstractionsDirectory == \ os.path.join(self.configuration.userPackageDirectory, 'abstractions'): s = os.path.join(self.configuration.dotVistrails, 'subworkflows') self.configuration.abstractionsDirectory = s #thumbnails directory if self.temp_configuration.has('thumbs'): if not self.temp_configuration.thumbs.check('cacheDirectory'): s = os.path.join(self.temp_configuration.dotVistrails,'thumbs') self.temp_configuration.thumbs.cacheDirectory = s if self.configuration.has('thumbs'): if not self.configuration.thumbs.check('cacheDirectory'): s = os.path.join(self.configuration.dotVistrails, 'thumbs') self.configuration.thumbs.cacheDirectory = s
def execDotVistrails(tried_once=False): """ execDotVistrails() -> None Actually execute the Vistrail initialization """ # if it is file, then must move old-style .vistrails to # directory. if os.path.isfile(self.temp_configuration.dotVistrails): debug.warning( "Old-style initialization hooks. Will try to set things correctly." ) (fd, name) = tempfile.mkstemp() os.close(fd) shutil.copyfile(self.temp_configuration.dotVistrails, name) try: os.unlink(self.temp_configuration.dotVistrails) except: debug.critical("""Failed to remove old initialization file. This could be an indication of a permissions problem. Make sure file '%s' is writable.""" % self.temp_configuration.dotVistrails) sys.exit(1) self.create_default_directory() try: destiny = os.path.join( self.temp_configuration.dotVistrails, 'startup.py') shutil.copyfile(name, destiny) except: debug.critical("""Failed to copy old initialization file to newly-created initialization directory. This must have been a race condition. Please remove '%s' and restart VisTrails.""" % self.temp_configuration.dotVistrails) sys.exit(1) debug.critical("Successful move!") try: os.unlink(name) except: debug.warning("Failed to erase temporary file.") if os.path.isdir(self.temp_configuration.dotVistrails): if self.temp_configuration.check('userPackageDirectory'): userpackages = self.temp_configuration.userPackageDirectory else: userpackages = os.path.join( self.temp_configuration.dotVistrails, 'userpackages') startup = os.path.join(self.temp_configuration.dotVistrails, 'startup.py') if self.temp_configuration.check('abstractionsDirectory'): abstractions = self.temp_configuration.abstractionsDirectory else: abstractions = os.path.join( self.temp_configuration.dotVistrails, 'subworkflows') if (self.temp_configuration.has('thumbs') and self.temp_configuration.thumbs.check( 'cacheDirectory')): thumbnails = self.temp_configuration.thumbs.cacheDirectory else: thumbnails = os.path.join( self.temp_configuration.dotVistrails, 'thumbs') if not os.path.isdir(userpackages): create_user_packages_dir(userpackages) if not os.path.isfile(os.path.join(userpackages, '__init__.py')): create_user_packages_init(userpackages) if not os.path.isdir(abstractions): create_abstractions_dir(abstractions) if not os.path.isdir(thumbnails): create_thumbnails_dir(thumbnails) try: dotVistrails = file(startup) g = {} localsDir = { 'configuration': self.temp_configuration, 'addStartupHook': addStartupHook, 'addPackage': addPackage } old_path = copy.copy(sys.path) sys.path.append(self.temp_configuration.dotVistrails) exec dotVistrails in localsDir sys.path = old_path del localsDir['addPackage'] del localsDir['addStartupHook'] return localsDir except IOError: if tried_once: debug.critical("""Still cannot find default file. Something has gone wrong. Please make sure ~/.vistrails exists, is writable, and ~/.vistrails/startup.py does not exist.""") sys.exit(1) debug.critical('%s not found' % startup) debug.critical('Will try to install default ' 'startup file') install_default_startup() install_default_startupxml_if_needed() return execDotVistrails(True) elif not os.path.lexists(self.temp_configuration.dotVistrails): debug.log('%s not found' % self.temp_configuration.dotVistrails) self.create_default_directory() create_user_packages_dir() create_abstractions_dir() create_thumbnails_dir() install_default_startup() install_default_startupxml_if_needed() return execDotVistrails(True)
def log(m): """ print a log message either to the console or through the VisTrails logger """ if in_vistrails: debug.log(str(m)) else: print(m)