def remove_own_dom_element(self): """remove_own_dom_element() -> None Opens the startup DOM, looks for the element that belongs to the package. If it is there and there's a configuration, moves it to disabledpackages node. This is done as part of package disable. """ startup = get_vistrails_application().vistrailsStartup dom = startup.startup_dom() doc = dom.documentElement def find_it(): packages = enter_named_element(doc, 'packages') for package_node in named_elements(packages, 'package'): if str(package_node.attributes['name'].value) == self.codepath: return package_node package_node = find_it() oldpackage_element = self.find_disabledpackage_element(doc) assert oldpackage_element is None packages = enter_named_element(doc, 'packages') disabledpackages = enter_named_element(doc, 'disabledpackages') try: packages.removeChild(package_node) disabledpackages.appendChild(package_node) except xml.dom.NotFoundErr: pass startup.write_startup_dom(dom)
def load_persistent_configuration(self): (dom, element) = self.find_own_dom_element() configuration = enter_named_element(element, 'configuration') if configuration: self.configuration.set_from_dom_node(configuration) dom.unlink()
def load_configuration(self): """load_configuration() -> None Loads the appropriate configuration from .vistrails/startup.xml. """ dom = self.startup_dom() conf = enter_named_element(dom.documentElement, 'configuration') self.configuration.set_from_dom_node(conf)
def set_persistent_configuration(self): (dom, element) = self.find_own_dom_element() child = enter_named_element(element, 'configuration') if child: element.removeChild(child) self.configuration.write_to_dom(dom, element) get_vistrails_application().vistrailsStartup.write_startup_dom(dom) dom.unlink()
def set_persistent_configuration(self): (dom, element) = self.find_own_dom_element() child = enter_named_element(element, 'configuration') if child: element.removeChild(child) if self.configuration: self.configuration.write_to_dom(dom, element) get_vistrails_application().vistrailsStartup.write_startup_dom(dom) dom.unlink()
def load_configuration(self): """load_configuration() -> None Loads the appropriate configuration from .vistrails/startup.xml. This will overwrite both configuration and temp_configuration """ dom = self.startup_dom() conf = enter_named_element(dom.documentElement, 'configuration') self.configuration.set_from_dom_node(conf) self.temp_configuration.set_from_dom_node(conf)
def create_startup_package_node(self): (dom, element) = self.find_own_dom_element() doc = dom.documentElement disabledpackages = enter_named_element(doc, 'disabledpackages') packages = enter_named_element(doc, 'packages') oldpackage = self.find_disabledpackage_element(doc) if oldpackage is not None: # Must remove element from oldpackages, # _and_ the element that was just created in find_own_dom_element() disabledpackages.removeChild(oldpackage) packages.removeChild(element) packages.appendChild(oldpackage) configuration = enter_named_element(oldpackage, 'configuration') if configuration: self.configuration.set_from_dom_node(configuration) get_vistrails_application().vistrailsStartup.write_startup_dom(dom) dom.unlink()
def create_startup_package_node(self): (dom, element) = self.find_own_dom_element() doc = dom.documentElement disabledpackages = enter_named_element(doc, 'disabledpackages') packages = enter_named_element(doc, 'packages') oldpackage = self.find_disabledpackage_element(doc) if oldpackage is not None: # Must remove element from oldpackages, # _and_ the element that was just created in find_own_dom_element() disabledpackages.removeChild(oldpackage) packages.removeChild(element) packages.appendChild(oldpackage) configuration = enter_named_element(oldpackage, 'configuration') if configuration: if self.configuration: self.configuration.set_from_dom_node(configuration) else: debug.warning("Error, missing configuration in package") get_vistrails_application().vistrailsStartup.write_startup_dom(dom) dom.unlink()
def find_disabledpackage_element(self, doc): """find_disabledpackage_element(documentElement) -> Node or None Returns the package's disabledpackage element, if present. Returns None otherwise. """ packages = enter_named_element(doc, 'disabledpackages') assert packages for package_node in named_elements(packages, 'package'): if str(package_node.attributes['name'].value) == self.codepath: return package_node return None
def reset_configuration(self): """Reset_configuration() -> Resets configuration to original package settings.""" (dom, element) = self.find_own_dom_element() doc = dom.documentElement configuration = enter_named_element(element, 'configuration') if configuration: element.removeChild(configuration) self.configuration = copy.copy(self._initial_configuration) startup = get_vistrails_application().vistrailsStartup startup.write_startup_dom(dom)
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. """ dom = self.vistrailsStartup.startup_dom() doc = dom.documentElement configuration_element = enter_named_element(doc, 'configuration') doc.removeChild(configuration_element) self.configuration.write_to_dom(dom, doc) self.vistrailsStartup.write_startup_dom(dom) dom.unlink()
def load_persistent_configuration(self): (dom, element) = ( None, None ) for iAttempt in range(10): try: (dom, element) = self.find_own_dom_element() break except: time.sleep( 0.5 ) if element <> None: configuration = enter_named_element(element, 'configuration') if configuration and self.configuration: if self.configuration: self.configuration.set_from_dom_node(configuration) else: debug.warning("Error, missing configuration in package") if dom <> None: dom.unlink() else: debug.warning("Error reading dom for package")
def load_packages(self): """load_packages() -> None Loads the appropriate packages from .vistrails/startup.xml. """ def parse_package(node): is_value = (lambda node: node.nodeName in set(['bool', 'str', 'int', 'float'])) package_name = str(node.attributes['name'].value) self._package_manager.add_package(package_name) dom = self.startup_dom() doc = dom.documentElement packages_node = enter_named_element(doc, 'packages') for package_node in named_elements(packages_node, 'package'): parse_package(package_node)
def load_persistent_configuration(self): (dom, element) = ( None, None ) for iAttempt in range(10): try: (dom, element) = self.find_own_dom_element() break except: time.sleep( 0.5 ) if element <> None: configuration = enter_named_element(element, 'configuration') if configuration and self.configuration: if self.configuration: self.configuration.set_from_dom_node(configuration) else: print>>sys.stderr, "Error, missing configuration in package" if dom <> None: dom.unlink() else: print>>sys.stderr, "Error reading dom for package"
def load_packages(self): """load_packages() -> None Loads the appropriate packages from .vistrails/startup.xml. """ def parse_package(node): is_value = (lambda node: node.nodeName in set( ['bool', 'str', 'int', 'float'])) package_name = str(node.attributes['name'].value) # FIXME use more robust checks here! if package_name != 'basic_modules' and \ package_name != 'abstraction': self._package_manager.add_package(package_name) dom = self.startup_dom() doc = dom.documentElement packages_node = enter_named_element(doc, 'packages') for package_node in named_elements(packages_node, 'package'): parse_package(package_node)
def find_own_dom_element(self): """find_own_dom_element() -> (DOM, Node) Opens the startup DOM, looks for the element that belongs to the package, and returns DOM and node. Creates a new one if element is not there. """ dom = get_vistrails_application().vistrailsStartup.startup_dom() doc = dom.documentElement packages = enter_named_element(doc, 'packages') for package_node in named_elements(packages, 'package'): if str(package_node.attributes['name'].value) == self.codepath: return (dom, package_node) # didn't find anything, create a new node package_node = dom.createElement("package") package_node.setAttribute('name', self.codepath) packages.appendChild(package_node) get_vistrails_application().vistrailsStartup.write_startup_dom(dom) return (dom, package_node)
def load_packages(self): """load_packages() -> None Loads the appropriate packages from .vistrails/startup.xml. """ for package_name in self._needed_packages: self._package_manager.add_package(package_name) def parse_package(node): is_value = (lambda node: node.nodeName in set(['bool', 'str', 'int', 'float'])) package_name = str(node.attributes['name'].value) # FIXME use more robust checks here! if package_name != 'basic_modules' and \ package_name != 'abstraction': self._package_manager.add_package(package_name) dom = self.startup_dom() doc = dom.documentElement packages_node = enter_named_element(doc, 'packages') for package_node in named_elements(packages_node, 'package'): parse_package(package_node)
def find_it(): packages = enter_named_element(doc, 'packages') for package_node in named_elements(packages, 'package'): if str(package_node.attributes['name'].value) == self.codepath: return package_node