def get_module_upgrade(self, module_name, old_version): for module_remap in self.get_module_remaps(module_name): if ( module_remap.start_version is None or not versions_increasing(old_version, module_remap.start_version) ) and (module_remap.end_version is None or versions_increasing(old_version, module_remap.end_version)): return module_remap return None
def update_module(self, module=None): self.module = module for ports_list in self.ports_lists: ports_list.update_module(module) self.annotations.updateModule(module) if module is None: self.name_edit.setText("") if not versions_increasing(QtCore.QT_VERSION_STR, "4.7.0"): self.name_edit.setPlaceholderText("") # self.name_edit.setEnabled(False) self.type_edit.setText("") # self.type_edit.setEnabled(False) self.package_edit.setText("") self.module_id.setText("") else: if module.has_annotation_with_key("__desc__"): label = module.get_annotation_by_key("__desc__").value.strip() else: label = "" self.name_edit.setText(label) if not label and not versions_increasing(QtCore.QT_VERSION_STR, "4.7.0"): self.name_edit.setPlaceholderText(self.module.name) # self.name_edit.setEnabled(True) self.type_edit.setText(self.module.name) # self.type_edit.setEnabled(True) self.package_edit.setText(self.module.package) # self.package_edit.setEnabled(True) self.module_id.setText("%d" % self.module.id)
def check_dependencies(self, package, deps): # want to check that necessary version also exists, if specified missing_deps = [] for dep in deps: min_version = None max_version = None if isinstance(dep, tuple): identifier = dep[0] if len(dep) > 1: min_version = dep[1] if len(dep) > 2: max_version = dep[2] else: identifier = dep # check if it's an old identifier identifier = self._old_identifier_map.get(identifier, identifier) if identifier not in self._package_versions: missing_deps.append((identifier, None, None)) else: if min_version is None and max_version is None: continue found_version = False for version, pkg in self._package_versions[identifier].iteritems(): if (min_version is None or versions_increasing(min_version, version)) and ( max_version is None or versions_increasing(version, max_version) ): found_version = True if not found_version: missing_deps.append((identifier, min_version, max_version)) if len(missing_deps) > 0: raise Package.MissingDependency(package, missing_deps) return True
def get_module_upgrade(self, module_name, old_version): for module_remap in self.get_module_remaps(module_name): if ((module_remap.start_version is None or not versions_increasing( old_version, module_remap.start_version)) and (module_remap.end_version is None or versions_increasing( old_version, module_remap.end_version))): return module_remap return None
def update_module(self, module=None): for plist in self.ports_lists: plist.types_visible = self.types_visible plist.ports_visible = self.ports_visible self.module = module for ports_list in self.ports_lists: ports_list.update_module(module) self.annotations.updateModule(module) if module is None: # We show the version properties tab if both are tabified and # self is visible if not self.toolWindow().isFloating() and \ not QVersionProp.instance().toolWindow().isFloating() and \ not self.toolWindow().visibleRegion().isEmpty(): QVersionProp.instance().set_visible(True) self.name_edit.setText("") if not versions_increasing(QtCore.QT_VERSION_STR, '4.7.0'): self.name_edit.setPlaceholderText("") # self.name_edit.setEnabled(False) self.type_edit.setText("") # self.type_edit.setEnabled(False) self.package_edit.setText("") self.namespace_edit.setText("") self.module_id.setText("") else: # We show self if both are tabified and # the version properties tab is visible if not self.toolWindow().isFloating() and \ not QVersionProp.instance().toolWindow().isFloating() and \ not QVersionProp.instance().toolWindow().visibleRegion().isEmpty(): self.set_visible(True) if module.has_annotation_with_key('__desc__'): label = module.get_annotation_by_key('__desc__').value.strip() else: label = '' self.name_edit.setText(label) if not label and not versions_increasing(QtCore.QT_VERSION_STR, '4.7.0'): self.name_edit.setPlaceholderText(self.module.name) self.type_edit.setText(self.module.name) self.package_edit.setText(self.module.package) if self.module.namespace is not None: self.namespace_edit.setText(self.module.namespace.replace('|', '/')) else: self.namespace_edit.setText('') self.module_id.setText('%d' % self.module.id)
def update_module(self, module=None): for plist in self.ports_lists: plist.types_visible = self.types_visible plist.ports_visible = self.ports_visible self.module = module for ports_list in self.ports_lists: ports_list.update_module(module) self.annotations.updateModule(module) if module is None: # We show the version properties tab if both are tabified and # self is visible if not self.toolWindow().isFloating() and \ not QVersionProp.instance().toolWindow().isFloating() and \ not self.toolWindow().visibleRegion().isEmpty(): QVersionProp.instance().set_visible(True) self.name_edit.setText("") if not versions_increasing(QtCore.QT_VERSION_STR, '4.7.0'): self.name_edit.setPlaceholderText("") # self.name_edit.setEnabled(False) self.type_edit.setText("") # self.type_edit.setEnabled(False) self.package_edit.setText("") self.namespace_edit.setText("") self.module_id.setText("") else: # We show self if both are tabified and # the version properties tab is visible if not self.toolWindow().isFloating() and \ not QVersionProp.instance().toolWindow().isFloating() and \ not QVersionProp.instance().toolWindow().visibleRegion().isEmpty(): self.set_visible(True) if module.has_annotation_with_key('__desc__'): label = module.get_annotation_by_key('__desc__').value.strip() else: label = '' self.name_edit.setText(label) if not label and not versions_increasing(QtCore.QT_VERSION_STR, '4.7.0'): self.name_edit.setPlaceholderText(self.module.name) self.type_edit.setText(self.module.name) self.package_edit.setText(self.module.package) if self.module.namespace is not None: self.namespace_edit.setText( self.module.namespace.replace('|', '/')) else: self.namespace_edit.setText('') self.module_id.setText('%d' % self.module.id)
def setPlaceholderTextCompat(self, value): """ Qt pre 4.7.0 does not have setPlaceholderText """ if versions_increasing(QtCore.QT_VERSION_STR, '4.7.0'): self.setText(value) else: self.setPlaceholderText(value)
def add_descriptor(self, desc): self.db_add_module_descriptor(desc) key = (desc.name, desc.namespace) if key in self.descriptors: old_desc = self.descriptors[key] if versions_increasing(old_desc.version, desc.version): self.descriptors[key] = desc else: self.descriptors[key] = desc
def setup_indices(self): self.descriptor_versions = self.db_module_descriptors_name_index self.descriptors_by_id = self.db_module_descriptors_id_index self.descriptors = {} for key, desc in self.descriptor_versions.iteritems(): key = key[:2] if key in self.descriptors: old_desc = self.descriptors[key] if versions_increasing(old_desc.version, desc.version): self.descriptors[key] = desc else: self.descriptors[key] = desc
def update_module(self, module=None): for plist in self.ports_lists: plist.types_visible = self.types_visible plist.ports_visible = self.ports_visible self.module = module for ports_list in self.ports_lists: ports_list.update_module(module) self.annotations.updateModule(module) if module is None: self.name_edit.setText("") if not versions_increasing(QtCore.QT_VERSION_STR, '4.7.0'): self.name_edit.setPlaceholderText("") # self.name_edit.setEnabled(False) self.type_edit.setText("") # self.type_edit.setEnabled(False) self.package_edit.setText("") self.namespace_edit.setText("") self.module_id.setText("") else: if module.has_annotation_with_key('__desc__'): label = module.get_annotation_by_key('__desc__').value.strip() else: label = '' self.name_edit.setText(label) if not label and not versions_increasing(QtCore.QT_VERSION_STR, '4.7.0'): self.name_edit.setPlaceholderText(self.module.name) self.type_edit.setText(self.module.name) self.package_edit.setText(self.module.package) if self.module.namespace is not None: self.namespace_edit.setText(self.module.namespace.replace('|', '/')) else: self.namespace_edit.setText('') self.module_id.setText('%d' % self.module.id)
def update_module(self, module=None): for plist in self.ports_lists: plist.types_visible = self.types_visible plist.ports_visible = self.ports_visible self.module = module for ports_list in self.ports_lists: ports_list.update_module(module) self.annotations.updateModule(module) if module is None: self.name_edit.setText("") if not versions_increasing(QtCore.QT_VERSION_STR, '4.7.0'): self.name_edit.setPlaceholderText("") # self.name_edit.setEnabled(False) self.type_edit.setText("") # self.type_edit.setEnabled(False) self.package_edit.setText("") self.namespace_edit.setText("") self.module_id.setText("") else: if module.has_annotation_with_key('__desc__'): label = module.get_annotation_by_key('__desc__').value.strip() else: label = '' self.name_edit.setText(label) if not label and not versions_increasing(QtCore.QT_VERSION_STR, '4.7.0'): self.name_edit.setPlaceholderText(self.module.name) self.type_edit.setText(self.module.name) self.package_edit.setText(self.module.package) if self.module.namespace is not None: self.namespace_edit.setText( self.module.namespace.replace('|', '/')) else: self.namespace_edit.setText('') self.module_id.setText('%d' % self.module.id)
def check_dependencies(self, package, deps): # want to check that necessary version also exists, if specified missing_deps = [] for dep in deps: min_version = None max_version = None if isinstance(dep, tuple): identifier = dep[0] if len(dep) > 1: min_version = dep[1] if len(dep) > 2: max_version = dep[2] else: identifier = dep # check if it's an old identifier identifier = self._old_identifier_map.get(identifier, identifier) if identifier not in self._package_versions: missing_deps.append((identifier, None, None)) else: if min_version is None and max_version is None: continue found_version = False for version, pkg in \ self._package_versions[identifier].iteritems(): if ((min_version is None or versions_increasing(min_version, version)) and (max_version is None or versions_increasing(version, max_version))): found_version = True if not found_version: missing_deps.append((identifier, min_version, max_version)) if len(missing_deps) > 0: raise Package.MissingDependency(package, missing_deps) return True
def handle_module_upgrade_request(controller, module_id, pipeline): # Before 0.0.3, SQLSource's resultSet output was type ListOfElements (which # doesn't exist anymore) # In 0.0.3, SQLSource's resultSet output was type List # In 0.1.0, SQLSource's output was renamed to result and is now a Table; # this is totally incompatible and no upgrade code is possible # the resultSet is kept for now for compatibility # Up to 0.0.4, DBConnection would ask for a password if one was necessary; # this behavior has not been kept. There is now a password input port, to # which you can connect a PasswordDialog from package dialogs if needed old_module = pipeline.modules[module_id] # DBConnection module from before 0.1.0: automatically add the password # prompt module if (old_module.name == 'DBConnection' and versions_increasing(old_module.version, '0.1.0')): reg = get_module_registry() # Creates the new module new_module = controller.create_module_from_descriptor( reg.get_descriptor(DBConnection)) # Create the password module mod_desc = reg.get_descriptor_by_name( 'org.vistrails.vistrails.dialogs', 'PasswordDialog') mod = controller.create_module_from_descriptor(mod_desc) # Adds a 'label' function to the password module ops = [('add', mod)] ops.extend( controller.update_function_ops(mod, 'label', ['Server password'])) # Connects the password module to the new module conn = controller.create_connection(mod, 'result', new_module, 'password') ops.append(('add', conn)) # Replaces the old module with the new one upgrade_actions = UpgradeWorkflowHandler.replace_generic( controller, pipeline, old_module, new_module, src_port_remap={'self': 'connection'}) password_fix_action = create_action(ops) return upgrade_actions + [password_fix_action] return UpgradeWorkflowHandler.attempt_automatic_upgrade( controller, pipeline, module_id)
def handle_module_upgrade_request(controller, module_id, pipeline): # Before 0.0.3, SQLSource's resultSet output was type ListOfElements (which # doesn't exist anymore) # In 0.0.3, SQLSource's resultSet output was type List # In 0.1.0, SQLSource's output was renamed to result and is now a Table; # this is totally incompatible and no upgrade code is possible # the resultSet is kept for now for compatibility # Up to 0.0.4, DBConnection would ask for a password if one was necessary; # this behavior has not been kept. There is now a password input port, to # which you can connect a PasswordDialog from package dialogs if needed old_module = pipeline.modules[module_id] # DBConnection module from before 0.1.0: automatically add the password # prompt module if (old_module.name == 'DBConnection' and versions_increasing(old_module.version, '0.1.0')): reg = get_module_registry() # Creates the new module new_module = controller.create_module_from_descriptor( reg.get_descriptor(DBConnection)) # Create the password module mod_desc = reg.get_descriptor_by_name( 'org.vistrails.vistrails.dialogs', 'PasswordDialog') mod = controller.create_module_from_descriptor(mod_desc) # Adds a 'label' function to the password module ops = [('add', mod)] ops.extend(controller.update_function_ops(mod, 'label', ['Server password'])) # Connects the password module to the new module conn = controller.create_connection(mod, 'result', new_module, 'password') ops.append(('add', conn)) # Replaces the old module with the new one upgrade_actions = UpgradeWorkflowHandler.replace_generic( controller, pipeline, old_module, new_module, src_port_remap={'self': 'connection'}) password_fix_action = create_action(ops) return upgrade_actions + [password_fix_action] return UpgradeWorkflowHandler.attempt_automatic_upgrade( controller, pipeline, module_id)
def get_package(self, identifier, version=None): # check if it's an old identifier identifier = self._old_identifier_map.get(identifier, identifier) try: package_versions = self._package_versions[identifier] if version is not None: return package_versions[version] except KeyError: # dynamic packages are only registered in the registry try: return self._registry.get_package_by_name(identifier, version) except MissingPackageVersion: return self._registry.get_package_by_name(identifier) max_version = '0' max_pkg = None for version, pkg in package_versions.iteritems(): if versions_increasing(max_version, version): max_version = version max_pkg = pkg return max_pkg
def remap_module(controller, module_id, pipeline, module_remap): """remap_module offers a method to shortcut the specification of upgrades. It is useful when just changing the names of ports or modules, but can also be used to add intermediate modules or change the format of parameters. It is usually called from handle_module_upgrade_request, and the first three arguments are passed from the arguments to that method. module_remap specifies all of the changes and is of the format {<old_module_name>: [(<start_version>, <end_version>, <new_module_klass> | <new_module_id> | None, <remap_dictionary>)]} where new_module_klass is the class and new_module_id is a string of the format <package_name>:[<namespace> | ]<module_name> passing None keeps the original name, and remap_dictionary is {<remap_type>: <name_changes>} and <name_changes> is a map from <old_name> to <new_name> or <remap_function> The remap functions are passed the old object and the new module and should return a list of operations with elements of the form ('add', <obj>). For example: def outputName_remap(old_conn, new_module): ops = [] ... return ops module_remap = {'FileSink': [(None, '1.5.1', FileSink, {'dst_port_remap': {'overrideFile': 'overwrite', 'outputName': outputName_remap}, 'function_remap': {'overrideFile': 'overwrite', 'outputName': 'outputPath'}}), } """ reg = get_module_registry() old_module = pipeline.modules[module_id] old_desc_str = create_descriptor_string(old_module.package, old_module.name, old_module.namespace, False) # print 'running module_upgrade_request', old_module.name if old_desc_str in module_remap: for upgrade_tuple in module_remap[old_desc_str]: (start_version, end_version, new_module_type, remap) = \ upgrade_tuple old_version = old_module.version if ((start_version is None or not versions_increasing(old_version, start_version)) and (end_version is None or versions_increasing(old_version, end_version))): # do upgrade if new_module_type is None: try: new_module_desc = \ reg.get_descriptor_by_name(old_module.package, old_module.name, old_module.namespace) except MissingModule, e: # if the replacement is an abstraction, # and it has been upgraded, we use that if reg.has_abs_upgrade(old_module.package, old_module.name, old_module.namespace): new_module_desc = \ reg.get_abs_upgrade(old_module.package, old_module.name, old_module.namespace) else: raise e elif isinstance(new_module_type, basestring): d_tuple = parse_descriptor_string(new_module_type, old_module.package) try: new_module_desc = \ reg.get_descriptor_by_name(*d_tuple) except MissingModule, e: # if the replacement is an abstraction, # and it has been upgraded, we use that if reg.has_abs_upgrade(*d_tuple): new_module_desc = reg.get_abs_upgrade(*d_tuple) else: raise e else: # we have a klass for get_descriptor new_module_desc = reg.get_descriptor(new_module_type) src_port_remap = remap.get('src_port_remap', {}) dst_port_remap = remap.get('dst_port_remap', {}) # !!! we're going to let dst_port_remap serve as a # base for function_remap but the developer is # responsible for knowing that anything beyond name # remaps requires different functions function_remap = copy.copy(dst_port_remap) function_remap.update(remap.get('function_remap', {})) annotation_remap = remap.get('annotation_remap', {}) action_list = \ UpgradeWorkflowHandler.replace_module(controller, pipeline, module_id, new_module_desc, function_remap, src_port_remap, dst_port_remap, annotation_remap) return action_list