def addButtonsToToolbar(self): # button for toggling executions eye_open_icon = \ QtGui.QIcon(os.path.join(vistrails_root_directory(), 'gui/resources/images/eye.png')) self.portVisibilityAction = QtGui.QAction( eye_open_icon, "Show/hide port visibility toggle buttons", None, triggered=self.showPortVisibility) self.portVisibilityAction.setCheckable(True) self.portVisibilityAction.setChecked(True) self.toolWindow().toolbar.insertAction(self.toolWindow().pinAction, self.portVisibilityAction) self.showTypesAction = QtGui.QAction(letterIcon('T'), "Show/hide type information", None, triggered=self.showTypes) self.showTypesAction.setCheckable(True) self.showTypesAction.setChecked(True) self.toolWindow().toolbar.insertAction(self.toolWindow().pinAction, self.showTypesAction) self.showEditsAction = QtGui.QAction(QtGui.QIcon( os.path.join(vistrails_root_directory(), 'gui/resources/images/pencil.png')), "Show/hide parameter widgets", None, triggered=self.showEdits) self.showEditsAction.setCheckable(True) self.showEditsAction.setChecked( get_vistrails_configuration().check('showInlineParameterWidgets')) self.toolWindow().toolbar.insertAction(self.toolWindow().pinAction, self.showEditsAction)
def addButtonsToToolbar(self): # button for toggling executions eye_open_icon = \ QtGui.QIcon(os.path.join(vistrails_root_directory(), 'gui/resources/images/eye.png')) self.portVisibilityAction = QtGui.QAction(eye_open_icon, "Show/hide port visibility toggle buttons", None, triggered=self.showPortVisibility) self.portVisibilityAction.setCheckable(True) self.portVisibilityAction.setChecked(True) self.toolWindow().toolbar.insertAction(self.toolWindow().pinAction, self.portVisibilityAction) self.showTypesAction = QtGui.QAction(letterIcon('T'), "Show/hide type information", None, triggered=self.showTypes) self.showTypesAction.setCheckable(True) self.showTypesAction.setChecked(True) self.toolWindow().toolbar.insertAction(self.toolWindow().pinAction, self.showTypesAction) self.showEditsAction = QtGui.QAction( QtGui.QIcon(os.path.join(vistrails_root_directory(), 'gui/resources/images/pencil.png')), "Show/hide parameter widgets", None, triggered=self.showEdits) self.showEditsAction.setCheckable(True) self.showEditsAction.setChecked( get_vistrails_configuration().check('showInlineParameterWidgets')) self.toolWindow().toolbar.insertAction(self.toolWindow().pinAction, self.showEditsAction)
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)
class TestUsersGuideVTL(unittest.TestCase): vtl_path = os.path.join(vistrails_root_directory(), '..', 'doc', 'usersguide', 'vtl') @unittest.skipIf(not os.path.isdir(vtl_path), 'Could not find vtl dir') def test_vtl_files(self): from vistrails.tests.utils import run_file for root, dirs, file_names in os.walk(self.vtl_path): for file_name in sorted(file_names): if file_name.endswith('.vtl'): # update available packages from vistrails.core.packagemanager import get_package_manager get_package_manager().build_available_package_names_list() f = os.path.join(root, file_name) locator = FileLocator(f) version = locator._vnode # if there is a version specified try to execute it, # else just load the pipeline if version: errors = run_file(f, lambda x: x == version) self.assertEqual( errors, [], 'Errors processing %s: %s' % (f, str(errors))) else: import vistrails.core.db.io from vistrails.core.vistrail.controller import \ VistrailController loaded_objs = vistrails.core.db.io.load_vistrail( locator) controller = VistrailController( loaded_objs[0], locator, *loaded_objs[1:]) controller.change_selected_version( controller.vistrail.get_latest_version()) self.assertTrue(controller.current_pipeline.is_valid, "Latest pipeline is invalid: %s" % f)
def getVersionSchemaDir(version=None): if version is None: version = currentVersion versionName = get_version_name(version) schemaDir = os.path.join(vistrails_root_directory(), 'db', 'versions', versionName, 'schemas', 'sql') return schemaDir
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 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 testParamexp(self): """test translating parameter explorations from 1.0.3 to 1.0.2""" from vistrails.db.services.io import open_bundle_from_zip_xml from vistrails.core.system import vistrails_root_directory import os (save_bundle, vt_save_dir) = open_bundle_from_zip_xml(DBVistrail.vtType, \ os.path.join(vistrails_root_directory(), 'tests/resources/paramexp-1.0.3.vt')) vistrail = translateVistrail(save_bundle.vistrail)
def test_startup_update(self): from vistrails.db.services.io import open_startup_from_xml from vistrails.core.system import vistrails_root_directory import os startup_tmpl = os.path.join(vistrails_root_directory(), 'tests', 'resources', 'startup-0.1.xml.tmpl') f = open(startup_tmpl, 'r') template = string.Template(f.read()) startup_dir = tempfile.mkdtemp(prefix="vt_startup") startup_fname = os.path.join(startup_dir, "startup.xml") with open(startup_fname, 'w') as f: f.write(template.substitute({'startup_dir': startup_dir})) try: # FIXME need to generate startup from local path startup = open_startup_from_xml(startup_fname) name_idx = startup.db_configuration.db_config_keys_name_index self.assertNotIn('nologger', name_idx) self.assertIn('executionLog', name_idx) self.assertFalse( name_idx['executionLog'].db_value.db_value.lower() == 'true') self.assertNotIn('showMovies', name_idx) self.assertIn('logDir', name_idx) self.assertEqual(name_idx['logDir'].db_value.db_value, 'logs') self.assertIn('userPackageDir', name_idx) self.assertEqual(name_idx['userPackageDir'].db_value.db_value, 'userpackages') self.assertIn('thumbs', name_idx) thumbs_name_idx = \ name_idx['thumbs'].db_value.db_config_keys_name_index self.assertIn('cacheDir', thumbs_name_idx) self.assertEqual(thumbs_name_idx['cacheDir'].db_value.db_value, '/path/to/thumbs') self.assertIn('subworkflowsDir', name_idx) self.assertEqual(name_idx['subworkflowsDir'].db_value.db_value, 'subworkflows') # note: have checked with spreadsheet removed from all # packages list, too # TODO: make this a permanent test (new template?) self.assertNotIn('fixedSpreadsheetCells', name_idx) enabled_names = startup.db_enabled_packages.db_packages_name_index self.assertIn('spreadsheet', enabled_names) spreadsheet_config = enabled_names['spreadsheet'].db_configuration self.assertIsNotNone(spreadsheet_config) spreadsheet_name_idx = spreadsheet_config.db_config_keys_name_index self.assertIn('fixedCellSize', spreadsheet_name_idx) self.assertTrue(spreadsheet_name_idx['fixedCellSize'].db_value. db_value.lower() == "true") self.assertIn('dumpfileType', spreadsheet_name_idx) self.assertEqual( spreadsheet_name_idx['dumpfileType'].db_value.db_value, "PNG") finally: shutil.rmtree(startup_dir)
def linux_fedora_install(package_name): qt = qt_available() hide_splash_if_necessary() if qt: cmd = shell_escape(vistrails_root_directory() + '/gui/bundles/linux_fedora_install.py') else: cmd = 'yum -y install' return run_install_command(qt, cmd, package_name)
def testVistrailvars(self): """test translating vistrail variables from 1.0.3 to 1.0.2""" from vistrails.db.services.io import open_bundle_from_zip_xml from vistrails.core.system import vistrails_root_directory import os (save_bundle, vt_save_dir) = open_bundle_from_zip_xml(DBVistrail.vtType, \ os.path.join(vistrails_root_directory(), 'tests/resources/visvar-1.0.3.vt')) vistrail = translateVistrail(save_bundle.vistrail) visvars = vistrail.db_annotations_key_index['__vistrail_vars__'] self.assertTrue(visvars.db_value)
def test_startup_update(self): from vistrails.db.services.io import open_startup_from_xml from vistrails.core.system import vistrails_root_directory import os startup_tmpl = os.path.join(vistrails_root_directory(), 'tests', 'resources', 'startup-0.1.xml.tmpl') f = open(startup_tmpl, 'r') template = string.Template(f.read()) startup_dir = tempfile.mkdtemp(prefix="vt_startup") startup_fname = os.path.join(startup_dir, "startup.xml") with open(startup_fname, 'w') as f: f.write(template.substitute({'startup_dir': startup_dir})) try: # FIXME need to generate startup from local path startup = open_startup_from_xml(startup_fname) name_idx = startup.db_configuration.db_config_keys_name_index self.assertNotIn('nologger', name_idx) self.assertIn('executionLog', name_idx) self.assertFalse( name_idx['executionLog'].db_value.db_value.lower() == 'true') self.assertNotIn('showMovies', name_idx) self.assertIn('logDir', name_idx) self.assertEqual(name_idx['logDir'].db_value.db_value, 'logs') self.assertIn('userPackageDir', name_idx) self.assertEqual(name_idx['userPackageDir'].db_value.db_value, 'userpackages') self.assertIn('thumbs', name_idx) thumbs_name_idx = \ name_idx['thumbs'].db_value.db_config_keys_name_index self.assertIn('cacheDir', thumbs_name_idx) self.assertEqual(thumbs_name_idx['cacheDir'].db_value.db_value, '/path/to/thumbs') self.assertIn('subworkflowsDir', name_idx) self.assertEqual(name_idx['subworkflowsDir'].db_value.db_value, 'subworkflows') # note: have checked with spreadsheet removed from all # packages list, too # TODO: make this a permanent test (new template?) self.assertNotIn('fixedSpreadsheetCells', name_idx) enabled_names = startup.db_enabled_packages.db_packages_name_index self.assertIn('spreadsheet', enabled_names) spreadsheet_config = enabled_names['spreadsheet'].db_configuration self.assertIsNotNone(spreadsheet_config) spreadsheet_name_idx = spreadsheet_config.db_config_keys_name_index self.assertIn('fixedCellSize', spreadsheet_name_idx) self.assertTrue(spreadsheet_name_idx['fixedCellSize'].db_value.db_value.lower() == "true") self.assertIn('dumpfileType', spreadsheet_name_idx) self.assertEqual(spreadsheet_name_idx['dumpfileType'].db_value.db_value, "PNG") finally: shutil.rmtree(startup_dir)
def testVistrailvars(self): """test translating vistrail variables from 1.0.2 to 1.0.3""" from vistrails.db.services.io import open_bundle_from_zip_xml from vistrails.core.system import vistrails_root_directory import os (save_bundle, vt_save_dir) = open_bundle_from_zip_xml(DBVistrail.vtType, \ os.path.join(vistrails_root_directory(), 'tests/resources/visvar-1.0.2.vt')) vistrail = translateVistrail(save_bundle.vistrail) visvars = vistrail.db_vistrailVariables self.assertEqual(len(visvars), 2) self.assertNotEqual(visvars[0].db_name, visvars[1].db_name)
def uvcdat_vistrails_branch(): git_dir = os.path.join(vistrails_root_directory(), '..') with Chdir(git_dir): release = "update_before_release" if vistrails.core.requirements.executable_file_exists('git'): lines = [] result = execute_cmdline(['git', 'rev-parse', '--abbrev-ref', 'HEAD' ], lines) if len(lines) == 1: if result == 0: release = lines[0].strip() return release
def do_export(self, filename, expected_source): import os from vistrails.core.db.locator import FileLocator from vistrails.core.system import vistrails_root_directory from vistrails.core.vistrail.pipeline import Pipeline locator = FileLocator( os.path.join(vistrails_root_directory(), 'tests', 'resources', filename)) pipeline = locator.load(Pipeline) self.assertEqual('\n'.join(write_workflow_to_python(pipeline)) + '\n', expected_source)
def importWidgetModules(basicWidgets): """ importWidgetModules(basicWidgets: widget) -> None Find all widget package under ./widgets/* to add to the spreadsheet registry """ packageName = __name__.lower().endswith('.init') and \ __name__[:-5] or __name__ widgetDir = os.path.join( os.path.join(os.path.dirname(vistrails_root_directory()), *packageName.split('.')), 'widgets') candidates = os.listdir(widgetDir) for folder in candidates: if os.path.isdir(os.path.join(widgetDir, folder)) and folder != '.svn': addWidget('.'.join([packageName, 'widgets', folder]))
def testParamexp(self): """test translating parameter explorations from 1.0.2 to 1.0.3""" from vistrails.db.services.io import open_bundle_from_zip_xml from vistrails.core.system import vistrails_root_directory import os (save_bundle, vt_save_dir) = open_bundle_from_zip_xml(DBVistrail.vtType, \ os.path.join(vistrails_root_directory(), 'tests/resources/paramexp-1.0.2.vt')) vistrail = translateVistrail(save_bundle.vistrail) pes = vistrail.db_get_parameter_explorations() self.assertEqual(len(pes), 1) funs = pes[0].db_functions self.assertEqual(set(f.db_port_name for f in funs), set(['SetCoefficients', 'SetBackgroundWidget'])) parameters = funs[0].db_parameters self.assertEqual(len(parameters), 10)
def setUpClass(cls): # first make sure CLTools is loaded pm = get_package_manager() if 'CLTools' not in pm._package_list: # pragma: no cover # pragma: no branch pm.late_enable_package('CLTools') remove_all_scripts() cls.testdir = os.path.join(packages_directory(), 'CLTools', 'test_files') cls._tools = {} for name in os.listdir(cls.testdir): if not name.endswith(SUFFIX): continue _add_tool(os.path.join(cls.testdir, name)) toolname = os.path.splitext(name)[0] cls._tools[toolname] = cl_tools[toolname] cls._old_dir = os.getcwd() os.chdir(vistrails_root_directory())
def install_default_startup(): debug.log('Will try to create default startup script') try: root_dir = 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 testParamexp(self): """test translating parameter explorations from 1.0.2 to 1.0.3""" from vistrails.db.services.io import open_bundle_from_zip_xml from vistrails.core.system import vistrails_root_directory import os (save_bundle, vt_save_dir) = open_bundle_from_zip_xml( DBVistrail.vtType, os.path.join(vistrails_root_directory(), "tests/resources/paramexp-1.0.2.vt") ) vistrail = translateVistrail(save_bundle.vistrail) pes = vistrail.db_get_parameter_explorations() self.assertEqual(len(pes), 1) funs = pes[0].db_functions self.assertEqual(set([f.db_port_name for f in funs]), set(["SetCoefficients", "SetBackgroundWidget"])) parameters = funs[0].db_parameters self.assertEqual(len(parameters), 10)
def linux_debian_install(package_name): qt = qt_available() try: import apt import apt_pkg except ImportError: qt = False hide_splash_if_necessary() if qt: cmd = shell_escape(vistrails_root_directory() + '/gui/bundles/linux_debian_install.py') else: cmd = '%s install -y' % ( 'aptitude' if executable_is_in_path('aptitude') else 'apt-get') return run_install_command(qt, cmd, package_name)
def uvcdat_revision(): """uvcdat_revision() -> str When run on a working copy, shows the current git hash else shows the latest release revision """ git_dir = os.path.join(vistrails_root_directory(), '..') with Chdir(git_dir): release = "update_before_release" if vistrails.core.requirements.executable_file_exists('git'): lines = [] result = execute_cmdline(['git', 'describe', '--tags', ], lines) if len(lines) == 1: if result == 0: release = lines[0].strip() return release
def linux_debian_install(package_name): qt = qt_available() try: import apt import apt_pkg except ImportError: qt = False hide_splash_if_necessary() if qt: cmd = shell_escape(vistrails_root_directory() + '/gui/bundles/linux_debian_install.py') else: cmd = '%s install -y' % ('aptitude' if executable_is_in_path('aptitude') else 'apt-get') return run_install_command(qt, cmd, package_name)
def start_process(condition, *args): """Executes a file and waits for a condition. """ prev_dir = os.getcwd() os.chdir(os.path.join(vistrails_root_directory(), os.path.pardir)) try: p = subprocess.Popen(args) finally: os.chdir(prev_dir) if condition is None: return p, None else: while True: time.sleep(0.5) if condition(): return p, None res = p.poll() if res is not None: return None, res
def read_dotvistrails_option(self, optionsDict=None): """ read_dotvistrails_option() -> None Check if the user sets a new dotvistrails folder and updates self.temp_configuration with the new value. Also handles the 'spawned-mode' option, by using a temporary directory as .vistrails directory, and a specific default configuration. """ if optionsDict is None: optionsDict = {} def get(opt): return (optionsDict.get(opt) or command_line.CommandLineParser().get_option(opt)) if get('spawned'): # Here we are in 'spawned' mode, i.e. we are running # non-interactively as a slave # We are going to create a .vistrails directory as a temporary # directory and copy a specific configuration file # We don't want to load packages that the user might enabled in # this machine's configuration file as it would slow down the # startup time, but we'll load any needed package without # confirmation tmpdir = tempfile.mkdtemp(prefix='vt_spawned_') @atexit.register def clean_dotvistrails(): shutil.rmtree(tmpdir, ignore_errors=True) self.temp_configuration.dotVistrails = tmpdir if get('dotVistrails') is not None: debug.warning("--startup option ignored since --spawned-mode " "is used") shutil.copyfile(os.path.join(system.vistrails_root_directory(), 'core', 'resources', 'spawned_startup_xml'), os.path.join(tmpdir, 'startup.xml')) self.temp_configuration.enablePackagesSilently = True self.temp_configuration.nologfile = True self.temp_configuration.singleInstance = False elif get('dotVistrails') is not None: self.temp_configuration.dotVistrails = get('dotVistrails')
def run_file(filename, tag_filter=lambda x: True): """Loads a .vt file and runs all the tagged versions in it. """ import vistrails.core.db.io from vistrails.core.db.locator import FileLocator from vistrails.core.system import vistrails_root_directory from vistrails.core.vistrail.controller import VistrailController filename = os.path.join(vistrails_root_directory(), '..', filename) locator = FileLocator(filename) loaded_objs = vistrails.core.db.io.load_vistrail(locator) controller = VistrailController(loaded_objs[0], locator, *loaded_objs[1:]) errors = [] for version, name in controller.vistrail.get_tagMap().iteritems(): if tag_filter(name): controller.change_selected_version(version) (result,), _ = controller.execute_current_workflow() if result.errors: errors.append(("%d: %s" % (version, name), result.errors)) return errors
def test_load_old_startup_xml(self): # has old nested shell settings that don't match current naming startup_tmpl = os.path.join(system.vistrails_root_directory(), 'tests', 'resources', 'startup-0.1.xml.tmpl') f = open(startup_tmpl, 'r') template = string.Template(f.read()) startup_dir = tempfile.mkdtemp(prefix="vt_startup") old_startup_fname = os.path.join(startup_dir, "startup.xml") with open(old_startup_fname, 'w') as f: f.write(template.substitute({'startup_dir': startup_dir})) startup1 = vistrails.core.db.io.load_startup(old_startup_fname) (h, fname) = tempfile.mkstemp(suffix=".xml") os.close(h) try: vistrails.core.db.io.save_startup(startup1, fname) startup2 = vistrails.core.db.io.load_startup(fname) self.assertEqual(startup1, startup2) finally: os.remove(fname) shutil.rmtree(startup_dir)
def test_looping_pipeline_fix(self): """Chains upgrades and automatic package initialization.""" # Expected actions are as follow: # - loads workflow.xml # * pipeline is missing looping_fix.a version 0.1 # - enables looping_fix.a (version 0.2) # * pipeline is still missing looping_fix.a version 0.1 # - runs upgrade for looping_fix.a, 0.1 -> 0.2 # - upgrade changes modules to package looping_fix.b version 0.1 # * pipeline is missing looping_fix.b version 0.1 # - enables looping_fix.b (version 0.2) # * pipeline is still missing looping_fix.b version 0.1 # - runs upgrade for looping_fix.b, 0.1 -> 0.2 # - upgrade changes modules to package looping_fix.c version 1.0 # * pipeline is missing looping_fix.c version 1.0 # - enables looping_fix.c (version 1.0) # * pipeline is valid # 5 calls to handle_invalid_pipeline() # Pre-adds packages so that the package manager can find them packages = ["pkg_a", "pkg_b", "pkg_c"] prefix = "vistrails.tests.resources.looping_upgrades." pm = get_package_manager() for pkg in packages: pm.get_available_package(pkg, prefix=prefix) self.assertFalse(set(pkg.codepath for pkg in pm.enabled_package_list()).intersection(packages)) # Hooks handle_invalid_pipeline() from vistrails.core.vistrail.controller import VistrailController orig_hip = VistrailController.handle_invalid_pipeline count = [0] def new_hip(*args, **kwargs): count[0] += 1 return orig_hip(*args, **kwargs) VistrailController.handle_invalid_pipeline = new_hip try: # Loads workflow.xml from vistrails.core.db.io import load_vistrail from vistrails.core.db.locator import FileLocator from vistrails.core.system import vistrails_root_directory locator = FileLocator( os.path.join(vistrails_root_directory(), "tests", "resources", "looping_upgrades", "workflow.xml") ) loaded_objs = load_vistrail(locator) controller = VistrailController(loaded_objs[0], locator, *loaded_objs[1:]) # Select version (triggers all the validation/upgrade/loading) self.assertEqual(controller.get_latest_version_in_graph(), 1) controller.do_version_switch(1) self.assertEqual(count[0], 5) # Restores handle_invalid_pipeline() finally: VistrailController.handle_invalid_pipeline = orig_hip # disable packages for pkg in reversed(packages): try: pm.late_disable_package(pkg) except MissingPackage: pass
def __init__(self, options_config, command_line_config, use_dot_vistrails=True): """VistrailsStartup(dot_vistrails: str) -> None Setup VisTrails configuration and options. dot_vistrals indicates the file we will use to load and save configuration options; if it is None, options will not be loaded or saved for the session. """ DBStartup.__init__(self) self.db_enabled_packages = DBEnabledPackages() self.db_disabled_packages = DBDisabledPackages() self._dot_vistrails = None # self._enabled_packages = {} # self._disabled_packages = {} self.configuration = vistrails.core.configuration.default() if ((command_line_config is not None and command_line_config.check('spawned')) or (options_config is not None and options_config.check('spawned'))): # Here we are in 'spawned' mode, i.e. we are running # non-interactively as a slave # We are going to create a .vistrails directory as a temporary # directory and copy a specific configuration file # We don't want to load packages that the user might enabled in # this machine's configuration file as it would slow down the # startup time, but we'll load any needed package without # confirmation tmpdir = tempfile.mkdtemp(prefix='vt_spawned_') @atexit.register def clean_dotvistrails(): shutil.rmtree(tmpdir, ignore_errors=True) command_line_config.dotVistrails = tmpdir shutil.copyfile( os.path.join(system.vistrails_root_directory(), 'core', 'resources', 'spawned_startup_xml'), os.path.join(tmpdir, 'startup.xml')) command_line_config.enablePackagesSilently = True command_line_config.errorLog = False command_line_config.singleInstance = False if use_dot_vistrails: if command_line_config is not None and \ command_line_config.check('dotVistrails'): self._dot_vistrails = command_line_config.get('dotVistrails') elif options_config is not None and \ options_config.check('dotVistrails'): self._dot_vistrails = options_config.get('dotVistrails') else: self._dot_vistrails = self.configuration.get('dotVistrails') self.setup_base_dot_vistrails() self.load_and_update_configurations(options_config, command_line_config) self.update_packages() self.setup_dot_vistrails()
from vistrails.core import debug import vistrails.gui.application from vistrails.core.system import vistrails_root_directory, \ vistrails_examples_directory from vistrails.core.packagemanager import get_package_manager # VisTrails does funny stuff with unittest/unittest2, be sure to load that # after vistrails import unittest # reinitializing arguments and options so VisTrails does not try parsing them sys.argv = sys.argv[:1] vistrails.gui.application.VistrailsApplicationSingleton.use_event_filter = \ False root_directory = os.path.realpath(vistrails_root_directory()) ############################################################################### # Testing Examples EXAMPLES_PATH = vistrails_examples_directory() #dictionary of examples that will be run with the workflows that will be ignored VT_EXAMPLES = { 'EMBOSS_webservices.vt': ["ProphetOutput"], 'KEGGPathway.vt': [], 'KEGG_SearchEntities_webservice.vt': [], 'KEGG_webservices.vt': [], 'brain_vistrail.vt': [], 'chebi_webservice.vt': [], 'head.vt': [], 'infovis.vt': [],
class ParameterEntry(QtGui.QTreeWidgetItem): plus_icon = QtGui.QIcon( os.path.join(vistrails_root_directory(), 'gui/resources/images/plus.png')) minus_icon = QtGui.QIcon( os.path.join(vistrails_root_directory(), 'gui/resources/images/minus.png')) def __init__(self, port_spec, function=None, types_visible=True, parent=None): QtGui.QTreeWidgetItem.__init__(self, parent) self.setFirstColumnSpanned(True) self.port_spec = port_spec self.function = function self.types_visible = types_visible def build_widget(self, widget_accessor, with_alias=True): reg = get_module_registry() # widget = QtGui.QDockWidget() # widget.setFeatures(QtGui.QDockWidget.DockWidgetClosable | # QtGui.QDockWidget.DockWidgetVerticalTitleBar) widget = QtGui.QWidget() h_layout = QtGui.QHBoxLayout() h_layout.insertSpacing(0, 10) h_layout.setMargin(2) h_layout.setSpacing(2) v_layout = QtGui.QVBoxLayout() v_layout.setAlignment(QtCore.Qt.AlignVCenter) delete_button = QtGui.QToolButton() delete_button.setIconSize(QtCore.QSize(8, 8)) delete_button.setIcon(ParameterEntry.minus_icon) def delete_method(): if self.function is not None: self.group_box.parent().parent().parent().delete_method( self, self.port_spec.name, self.function.real_id) else: self.group_box.parent().parent().parent().delete_method( self, self.port_spec.name, None) QtCore.QObject.connect(delete_button, QtCore.SIGNAL("clicked()"), delete_method) v_layout.addWidget(delete_button) add_button = QtGui.QToolButton() add_button.setIcon(ParameterEntry.plus_icon) add_button.setIconSize(QtCore.QSize(8, 8)) def add_method(): self.group_box.parent().parent().parent().add_method( self.port_spec.name) QtCore.QObject.connect(add_button, QtCore.SIGNAL("clicked()"), add_method) v_layout.addWidget(add_button) h_layout.addLayout(v_layout) self.my_widgets = [] self.my_labels = [] self.group_box = QtGui.QGroupBox() layout = QtGui.QGridLayout() layout.setMargin(5) layout.setSpacing(5) layout.setColumnStretch(1, 1) self.group_box.setFocusPolicy(QtCore.Qt.ClickFocus) self.group_box.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed) self.group_box.palette().setColor(QtGui.QPalette.Window, CurrentTheme.METHOD_SELECT_COLOR) if self.function is not None: params = self.function.parameters else: params = [ None, ] * len(self.port_spec.descriptors()) for i, (psi, param) in enumerate( izip(self.port_spec.port_spec_items, params)): if psi.entry_type is not None: # !!only pull off the prefix!! options follow in camelcase prefix_end = len(psi.entry_type.lstrip(string.lowercase)) if prefix_end == 0: entry_type = psi.entry_type else: entry_type = psi.entry_type[:-prefix_end] else: entry_type = None widget_class = widget_accessor(psi.descriptor, entry_type) if param is not None: obj = param else: obj = Parameter(psi.descriptor) obj.port_spec_item = psi if self.types_visible: if with_alias: label = AliasLabel(obj.alias, obj.type, psi.label) self.my_labels.append(label) else: label = QtGui.QLabel(obj.type) layout.addWidget(label, i, 0) layout.setAlignment(label, QtCore.Qt.AlignLeft) param_widget = widget_class(obj, self.group_box) self.my_widgets.append(param_widget) layout.addWidget(param_widget, i, 1) layout.addItem( QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.MinimumExpanding), i, 2) self.group_box.setLayout(layout) def updateMethod(): if self.function is not None: real_id = self.function.real_id else: real_id = -1 self.group_box.parent().parent().parent().update_method( self, self.port_spec.name, self.my_widgets, self.my_labels, real_id) def check_alias(name): controller = self.group_box.parent().parent().parent().controller if controller: return controller.check_alias(name) return False self.group_box.updateMethod = updateMethod self.group_box.check_alias = check_alias h_layout.addWidget(self.group_box) widget.setLayout(h_layout) return widget def get_widget(self): return self.build_widget(get_widget_class, True)
import vistrails.gui.application from vistrails.core.system import vistrails_root_directory, \ vistrails_examples_directory from vistrails.core.packagemanager import get_package_manager # VisTrails does funny stuff with unittest/unittest2, be sure to load that # after vistrails import unittest # reinitializing arguments and options so VisTrails does not try parsing them sys.argv = sys.argv[:1] vistrails.gui.application.VistrailsApplicationSingleton.use_event_filter = \ False root_directory = os.path.realpath(vistrails_root_directory()) ############################################################################### # Testing Examples EXAMPLES_PATH = vistrails_examples_directory() #dictionary of examples that will be run with the workflows that will be ignored VT_EXAMPLES = { 'EMBOSS_webservices.vt': ["ProphetOutput"], 'KEGGPathway.vt': [], 'KEGG_SearchEntities_webservice.vt': [], 'KEGG_webservices.vt': [], 'brain_vistrail.vt': [], 'chebi_webservice.vt': [], 'head.vt': [], 'infovis.vt': [], 'noaa_webservices.vt': [],
class PortItem(QtGui.QTreeWidgetItem): edit_show = QtGui.QIcon( os.path.join(vistrails_root_directory(), 'gui/resources/images/pencil.png')) edit_hide = QtGui.QIcon( os.path.join(vistrails_root_directory(), 'gui/resources/images/pencil-disabled.png')) eye_open_icon = \ QtGui.QIcon(os.path.join(vistrails_root_directory(), 'gui/resources/images/eye.png')) eye_closed_icon = \ QtGui.QIcon(os.path.join(vistrails_root_directory(), 'gui/resources/images/eye_closed.png')) eye_disabled_icon = \ QtGui.QIcon(os.path.join(vistrails_root_directory(), 'gui/resources/images/eye_gray.png')) conn_icon = \ QtGui.QIcon(os.path.join(vistrails_root_directory(), 'gui/resources/images/connection.png')) def __init__(self, port_spec, is_connected, is_optional, is_visible, is_editable=False, parent=None): QtGui.QTreeWidgetItem.__init__(self, parent) # self.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled) self.setFlags(QtCore.Qt.ItemIsEnabled) # self.setCheckState(0, QtCore.Qt.Unchecked) self.port_spec = port_spec self.is_connected = is_connected self.is_optional = is_optional self.is_visible = is_visible self.is_editable = is_editable self.is_unset = False self.build_item(port_spec, is_connected, is_optional, is_visible, is_editable) def visible(self): return not self.is_optional or self.is_visible def set_visible(self, visible): self.is_visible = visible if visible: self.setIcon(0, PortItem.eye_open_icon) else: self.setIcon(0, PortItem.eye_closed_icon) def set_editable(self, edit): self.is_editable = edit if edit: self.setIcon(0, PortItem.edit_show) else: self.setIcon(0, PortItem.edit_hide) def get_visible(self): return self.visible_checkbox def get_connected(self): return self.connected_checkbox def is_constant(self): return (self.port_spec.is_valid and get_module_registry().is_constant(self.port_spec)) def calcUnset(self): self.is_unset = self.is_constant() and \ self.port_spec.is_mandatory() and \ not self.is_connected and \ not self.isExpanded() if self.is_unset: font = self.font(3) font.setWeight(QtGui.QFont.Bold) self.setFont(3, font) def build_item(self, port_spec, is_connected, is_optional, is_visible, is_editable): if not is_optional: self.setIcon(1, PortItem.eye_disabled_icon) elif is_visible: self.setIcon(1, PortItem.eye_open_icon) else: self.setIcon(1, PortItem.eye_closed_icon) if is_connected: self.setIcon(2, PortItem.conn_icon) self.setText(3, port_spec.name) if self.is_constant(): if len(self.port_spec.port_spec_items) > 0: if is_editable: self.setIcon(0, PortItem.edit_show) else: self.setIcon(0, PortItem.edit_hide) else: # if port_spec is not a method, make it gray self.setForeground( 3, QtGui.QBrush(QtGui.QColor.fromRgb(128, 128, 128))) self.visible_checkbox = QtGui.QCheckBox() self.connected_checkbox = QtGui.QCheckBox() def contextMenuEvent(self, event, widget): if self.port_spec is None: return act = QtGui.QAction("View Documentation", widget) act.setStatusTip("View method documentation") QtCore.QObject.connect(act, QtCore.SIGNAL("triggered()"), self.view_documentation) menu = QtGui.QMenu(widget) menu.addAction(act) menu.exec_(event.globalPos()) def view_documentation(self): # descriptor = self.treeWidget().module.module_descriptor module = self.treeWidget().module port_type = self.treeWidget().port_type widget = QPortDocumentation(module, port_type, self.port_spec.name) widget.setAttribute(QtCore.Qt.WA_DeleteOnClose) widget.exec_() def __lt__(self, other): # put unset mandatory ports first if self.is_unset != other.is_unset: return self.is_unset and not other.is_unset # put set (expanded) functions first if self.isExpanded() != other.isExpanded(): return self.isExpanded() and not other.isExpanded() # otherwise use port name return self.port_spec.name < other.port_spec.name
def test_infinite_looping_upgrade(self): """Test that circular upgrades fail gracefully""" # Expected actions are as follow: # - loads workflow2.xml # * pipeline is missing looping_fix.x version 0.1 # - enables looping_fix.x (version 0.2) # * pipeline is still missing looping_fix.x version 0.1 # - runs upgrade for looping_fix.x, 0.1 -> 0.2 # - upgrade changes modules to package looping_fix.y version 0.1 # * pipeline is missing looping_fix.y version 0.1 # - enables looping_fix.y (version 0.2) # * pipeline is still missing looping_fix.y version 0.1 # Loop 50 times: # - runs upgrade for looping_fix.y, 0.1 -> 0.2 # - upgrade changes modules to package looping_fix.x version 0.1 # * pipeline is missing looping_fix.x version 0.1 # - runs upgrade for looping_fix.x, 0.1 -> 0.2 # - upgrade changes modules to package looping_fix.y version 0.1 # * pipeline is missing looping_fix.y version 0.1 # 50 calls to handle_invalid_pipeline() # Pre-adds packages so that the package manager can find them packages = ["pkg_x", "pkg_y"] prefix = "vistrails.tests.resources.looping_upgrades." pm = get_package_manager() for pkg in packages: pm.get_available_package(pkg, prefix=prefix) # Hooks handle_invalid_pipeline() from vistrails.core.vistrail.controller import VistrailController orig_hip = VistrailController.handle_invalid_pipeline count = [0] def new_hip(*args, **kwargs): count[0] += 1 return orig_hip(*args, **kwargs) VistrailController.handle_invalid_pipeline = new_hip try: # Loads workflow.xml from vistrails.core.db.io import load_vistrail from vistrails.core.db.locator import FileLocator from vistrails.core.system import vistrails_root_directory locator = FileLocator( os.path.join(vistrails_root_directory(), "tests", "resources", "looping_upgrades", "workflow2.xml") ) loaded_objs = load_vistrail(locator) controller = VistrailController(loaded_objs[0], locator, *loaded_objs[1:]) # Select version (triggers all the validation/upgrade/loading) self.assertEqual(controller.get_latest_version_in_graph(), 1) try: controller.do_version_switch(1) except InvalidPipeline: pass else: self.fail("No InvalidPipeline exception raised!") # Restores handle_invalid_pipeline() finally: VistrailController.handle_invalid_pipeline = orig_hip # disable packages for pkg in reversed(packages): try: pm.late_disable_package(pkg) except MissingPackage: pass # make sure it looped 50 times before failing max_loops = getattr(get_vistrails_configuration(), "maxPipelineFixAttempts", 50) self.assertEqual(count[0], max_loops) # Check that original version gets selected self.assertEqual(1, controller.current_version)
def __init__(self, options_config, command_line_config, use_dot_vistrails=True): """VistrailsStartup(dot_vistrails: str) -> None Setup VisTrails configuration and options. dot_vistrals indicates the file we will use to load and save configuration options; if it is None, options will not be loaded or saved for the session. """ DBStartup.__init__(self) self.db_enabled_packages = DBEnabledPackages() self.db_disabled_packages = DBDisabledPackages() self._dot_vistrails = None # self._enabled_packages = {} # self._disabled_packages = {} self.configuration = vistrails.core.configuration.default() if ((command_line_config is not None and command_line_config.check('spawned')) or (options_config is not None and options_config.check('spawned'))): # Here we are in 'spawned' mode, i.e. we are running # non-interactively as a slave # We are going to create a .vistrails directory as a temporary # directory and copy a specific configuration file # We don't want to load packages that the user might enabled in # this machine's configuration file as it would slow down the # startup time, but we'll load any needed package without # confirmation tmpdir = tempfile.mkdtemp(prefix='vt_spawned_') @atexit.register def clean_dotvistrails(): shutil.rmtree(tmpdir, ignore_errors=True) command_line_config.dotVistrails = tmpdir shutil.copyfile(os.path.join(system.vistrails_root_directory(), 'core', 'resources', 'spawned_startup_xml'), os.path.join(tmpdir, 'startup.xml')) command_line_config.enablePackagesSilently = True command_line_config.errorLog = False command_line_config.singleInstance = False if use_dot_vistrails: if command_line_config is not None and \ command_line_config.check('dotVistrails'): self._dot_vistrails = command_line_config.get('dotVistrails') elif options_config is not None and \ options_config.check('dotVistrails'): self._dot_vistrails = options_config.get('dotVistrails') else: self._dot_vistrails = self.configuration.get('dotVistrails') self.setup_base_dot_vistrails() self.load_and_update_configurations(options_config, command_line_config) self.update_packages() self.setup_dot_vistrails()