def init(self, options_dict=None, args=[]): """ VistrailsApplicationSingleton(options_dict: dict, args: list) -> VistrailsApplicationSingleton Create the application with a dict of settings """ warnings.simplefilter('once', VistrailsWarning, append=True) # options_dict overrides startup configuration if options_dict is not None: options_config = ConfigurationObject(**options_dict) else: options_config = None # command line options override both command_line_config = self.read_options(args) # startup takes care of all configurations self.startup = VistrailsStartup(options_config, command_line_config) self.keyChain = keychain.KeyChain() vistrails.core.interpreter.default.connect_to_configuration( self.temp_configuration) # now we want to open vistrails and point to a specific version self.check_all_requirements() if self.temp_configuration.check('staticRegistry'): self.registry = \ self.create_registry(self.temp_configuration.staticRegistry) else: self.registry = self.create_registry(None) self.package_manager = PackageManager(self.registry, self.startup)
def init(self, options_dict=None, args=[]): """ VistrailsApplicationSingleton(options_dict: dict, args: list) -> VistrailsApplicationSingleton Create the application with a dict of settings """ warnings.simplefilter('once', VistrailsWarning, append=True) # options_dict overrides startup configuration if options_dict is not None: options_config = ConfigurationObject(**options_dict) else: options_config = None # command line options override both command_line_config = self.read_options(args) # startup takes care of all configurations self.startup = VistrailsStartup(options_config, command_line_config) self.keyChain = keychain.KeyChain() vistrails.core.interpreter.default.connect_to_configuration( self.temp_configuration) # now we want to open vistrails and point to a specific version self.check_all_requirements() if self.temp_configuration.check('staticRegistry'): self.registry = \ self.create_registry(self.temp_configuration.staticRegistry) else: self.registry = self.create_registry(None) self.package_manager = PackageManager(self.registry, self.startup) if reportusage.update_config(self.temp_configuration): self.temp_configuration.batch = True
class VistrailsApplicationInterface(object): def __init__(self): self._initialized = False self.notifications = {} def read_options(self, args=None): """ read_options() -> None Read arguments from the command line """ if args is None: args = sys.argv[1:] parser = vistrails.core.configuration.build_default_parser() command_line_config = vistrails.core.configuration.ConfigurationObject( ) try: parser.parse_args(args, namespace=command_line_config) except SystemError: print "GOT SYSTEM ERROR!" debug.print_exc() self.input = command_line_config.vistrails if len(self.input) == 0: self.input = None return command_line_config # startup is going to manage configurations def _get_configuration(self): return self.startup.configuration configuration = property(_get_configuration) def _get_temp_configuration(self): return self.startup.temp_configuration temp_configuration = property(_get_temp_configuration) def create_registry(self, registry_filename=None): if registry_filename is not None: registry = vistrails.core.db.io.open_registry(registry_filename) registry.set_global() else: registry = ModuleRegistry() registry.set_global() return registry def init(self, options_dict=None, args=[]): """ VistrailsApplicationSingleton(options_dict: dict, args: list) -> VistrailsApplicationSingleton Create the application with a dict of settings """ warnings.simplefilter('once', VistrailsWarning, append=True) # options_dict overrides startup configuration if options_dict is not None: options_config = ConfigurationObject(**options_dict) else: options_config = None # command line options override both command_line_config = self.read_options(args) # startup takes care of all configurations self.startup = VistrailsStartup(options_config, command_line_config) self.keyChain = keychain.KeyChain() vistrails.core.interpreter.default.connect_to_configuration( self.temp_configuration) # now we want to open vistrails and point to a specific version self.check_all_requirements() if self.temp_configuration.check('staticRegistry'): self.registry = \ self.create_registry(self.temp_configuration.staticRegistry) else: self.registry = self.create_registry(None) self.package_manager = PackageManager(self.registry, self.startup) def check_all_requirements(self): # check scipy vistrails.core.requirements.require_python_module( 'scipy', { 'linux-debian': 'python-scipy', 'linux-ubuntu': 'python-scipy', 'linux-fedora': 'scipy', 'pip': 'scipy' }) def destroy(self): """ destroy() -> None Finalize all packages to, such as, get rid of temp files """ if hasattr(self, 'package_manager'): self.package_manager.finalize_packages() Collection.clearInstance() ThumbnailCache.clearInstance() def __del__(self): """ __del__() -> None Make sure to finalize in the destructor """ self.destroy() def _parse_vtinfo(self, info, use_filename=True): name = None version = None if use_filename and os.path.isfile(info): name = info else: data = info.split(":") if len(data) >= 2: if use_filename: if os.path.isfile(str(data[0])): name = str(data[0]) else: # maybe we are running on Windows and a full path # was passed as the filename so it has a : separating # the driver letter if system.systemType in ["Windows", "Microsoft"]: if os.path.isfile(":".join(data[:2])): name = ":".join(data[:2]) data.pop(0) data[0] = name elif not use_filename: name = str(data[0]) # will try to convert version to int # if it fails, it's a tag name #maybe a tag name contains ':' in its name #so we need to bring it back together rest = ":".join(data[1:]) try: version = int(rest) except ValueError: version = rest elif len(data) == 1: if use_filename and os.path.isfile(str(data[0])): name = str(data[0]) elif not use_filename: name = str(data[0]) return (name, version) def process_interactive_input(self): pe = None usedb = False if self.temp_configuration.check('host'): usedb = True if self.input: #check if versions are embedded in the filename for filename in self.input: f_name, version = self._parse_vtinfo(filename, not usedb) locator = None if f_name is None: debug.critical("Could not find file %s" % filename) return False 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_configuration.check('host'), port=self.temp_configuration.check('port') or 3306, database=self.temp_configuration.check('db'), user='', passwd='', obj_id=f_name, obj_type=None, connection_id=None) if locator: if self.temp_configuration.check('parameterExploration'): pe = version version = None else: 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.check('execute') mashuptrail = None mashupversion = None if hasattr(locator, '_mshptrail'): mashuptrail = locator._mshptrail if hasattr(locator, '_mshpversion'): mashupversion = locator._mshpversion if mashupversion: execute = True if self.temp_configuration.showWindow: self.showBuilderWindow() self.builderWindow.open_vistrail_without_prompt( locator, version, execute, mashuptrail=mashuptrail, mashupVersion=mashupversion) if self.temp_configuration.check('parameterExploration'): self.builderWindow.executeParameterExploration(pe) return True def finishSession(self): vistrails.core.interpreter.cached.CachedInterpreter.cleanup() def save_configuration(self): """ save_configuration() -> None Save the current vistrail configuration to the startup.xml file. This is required to capture changes to the configuration that we make programmatically during the session, ie., browsed directories or window sizes. """ self.startup.save_persisted_startup() def create_notification(self, notification_id, *args, **kwargs): notifications = self.notifications if notification_id not in notifications: notifications[notification_id] = set() else: print "already added notification", notification_id def register_notification(self, notification_id, method, *args, **kwargs): notifications = self.notifications #print '>>> GLOBAL adding notification', notification_id, method #print id(notifications), notifications if notification_id not in notifications: self.create_notification(notification_id) notifications[notification_id].add(method) def unregister_notification(self, notification_id, method, *args, **kwargs): notifications = self.notifications #print '>>> GLOBAL remove notification', notification_id, method #print id(notifications), notifications if notification_id in notifications: notifications[notification_id].remove(method) def send_notification(self, notification_id, *args): # do global notifications if notification_id in self.notifications: # print 'global notification ', notification_id for m in self.notifications[notification_id]: try: #print " m: ", m m(*args) except Exception, e: debug.unexpected_exception(e) debug.print_exc()
def load_startup(startup_fname): from vistrails.core.startup import VistrailsStartup startup = vistrails.db.services.io.open_startup_from_xml(startup_fname) VistrailsStartup.convert(startup) return startup
class VistrailsApplicationInterface(object): def __init__(self): self._initialized = False self.notifications = {} def printVersion(self): """ printVersion() -> None Print version of Vistrail and exit """ print system.about_string() sys.exit(0) def read_options(self, args=None): """ read_options() -> None Read arguments from the command line """ if args is None: args = sys.argv[1:] parser = vistrails.core.configuration.build_default_parser() command_line_config = vistrails.core.configuration.ConfigurationObject() try: parser.parse_args(args, namespace=command_line_config) except SystemError: print "GOT SYSTEM ERROR!" traceback.print_exc() self.input = command_line_config.vistrails if len(self.input) == 0: self.input = None return command_line_config # startup is going to manage configurations def _get_configuration(self): return self.startup.configuration configuration = property(_get_configuration) def _get_temp_configuration(self): return self.startup.temp_configuration temp_configuration = property(_get_temp_configuration) def create_registry(self, registry_filename=None): if registry_filename is not None: registry = vistrails.core.db.io.open_registry(registry_filename) registry.set_global() else: registry = ModuleRegistry() registry.set_global() return registry def init(self, options_dict=None, args=[]): """ VistrailsApplicationSingleton(options_dict: dict, args: list) -> VistrailsApplicationSingleton Create the application with a dict of settings """ warnings.simplefilter('once', VistrailsWarning, append=True) # options_dict overrides startup configuration if options_dict is not None: options_config = ConfigurationObject(**options_dict) else: options_config = None # command line options override both command_line_config = self.read_options(args) # startup takes care of all configurations self.startup = VistrailsStartup(options_config, command_line_config) self.keyChain = keychain.KeyChain() vistrails.core.interpreter.default.connect_to_configuration( self.temp_configuration) # now we want to open vistrails and point to a specific version self.check_all_requirements() if self.temp_configuration.check('staticRegistry'): self.registry = \ self.create_registry(self.temp_configuration.staticRegistry) else: self.registry = self.create_registry(None) self.package_manager = PackageManager(self.registry, self.startup) def check_all_requirements(self): # check scipy vistrails.core.requirements.require_python_module('scipy', { 'linux-debian': 'python-scipy', 'linux-ubuntu': 'python-scipy', 'linux-fedora': 'scipy', 'pip': 'scipy'}) def destroy(self): """ destroy() -> None Finalize all packages to, such as, get rid of temp files """ if hasattr(self, 'package_manager'): self.package_manager.finalize_packages() Collection.clearInstance() ThumbnailCache.clearInstance() def __del__(self): """ __del__() -> None Make sure to finalize in the destructor """ self.destroy() def _parse_vtinfo(self, info, use_filename=True): name = None version = None if use_filename and os.path.isfile(info): name = info else: data = info.split(":") if len(data) >= 2: if use_filename: if os.path.isfile(str(data[0])): name = str(data[0]) else: # maybe we are running on Windows and a full path # was passed as the filename so it has a : separating # the driver letter if system.systemType in ["Windows", "Microsoft"]: if os.path.isfile(":".join(data[:2])): name = ":".join(data[:2]) data.pop(0) data[0] = name elif not use_filename: name = str(data[0]) # will try to convert version to int # if it fails, it's a tag name #maybe a tag name contains ':' in its name #so we need to bring it back together rest = ":".join(data[1:]) try: version = int(rest) except ValueError: version = rest elif len(data) == 1: if use_filename and os.path.isfile(str(data[0])): name = str(data[0]) elif not use_filename: name = str(data[0]) return (name, version) def process_interactive_input(self): pe = None usedb = False if self.temp_configuration.check('host'): usedb = True if self.input: #check if versions are embedded in the filename for filename in self.input: f_name, version = self._parse_vtinfo(filename, not usedb) locator = None if f_name is None: debug.critical("Could not find file %s" % filename) return False 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_configuration.check('host'), port=self.temp_configuration.check('port') or 3306, database=self.temp_configuration.check('db'), user='', passwd='', obj_id=f_name, obj_type=None, connection_id=None) if locator: if self.temp_configuration.check('parameterExploration'): pe = version version = None else: 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.execute mashuptrail = None mashupversion = None if hasattr(locator, '_mshptrail'): mashuptrail = locator._mshptrail if hasattr(locator, '_mshpversion'): mashupversion = locator._mshpversion if mashupversion: execute = True if self.temp_configuration.showWindow: self.showBuilderWindow() self.builderWindow.open_vistrail_without_prompt(locator, version, execute, mashuptrail=mashuptrail, mashupVersion=mashupversion) if self.temp_configuration.check('parameterExploration'): self.builderWindow.executeParameterExploration(pe) return True def finishSession(self): vistrails.core.interpreter.cached.CachedInterpreter.cleanup() def save_configuration(self): """ save_configuration() -> None Save the current vistrail configuration to the startup.xml file. This is required to capture changes to the configuration that we make programmatically during the session, ie., browsed directories or window sizes. """ self.startup.save_persisted_startup() def create_notification(self, notification_id, *args, **kwargs): notifications = self.notifications if notification_id not in notifications: notifications[notification_id] = set() else: print "already added notification", notification_id def register_notification(self, notification_id, method, *args, **kwargs): notifications = self.notifications #print '>>> GLOBAL adding notification', notification_id, method #print id(notifications), notifications if notification_id not in notifications: self.create_notification(notification_id) notifications[notification_id].add(method) def unregister_notification(self, notification_id, method, *args, **kwargs): notifications = self.notifications #print '>>> GLOBAL remove notification', notification_id, method #print id(notifications), notifications if notification_id in notifications: notifications[notification_id].remove(method) def send_notification(self, notification_id, *args): # do global notifications if notification_id in self.notifications: # print 'global notification ', notification_id for m in self.notifications[notification_id]: try: #print " m: ", m m(*args) except Exception, e: debug.unexpected_exception(e) traceback.print_exc()