class SchemaMainView(WizardPage): def __init__(self, main): super(SchemaMainView, self).__init__(main, 'Schema Selection') def create_ui(self): self.content.set_padding(20) self.content.add(mforms.newLabel('Select the schemas to copy to the destination server and click [Start Copy >] to start the process.'), False, True) match_str = r"\%s\.\%s" % (self.main.plan.migrationSource._db_module.quoteIdentifier('(.+)\\'), self.main.plan.migrationSource._db_module.quoteIdentifier('(.+)\\')) self.catalog_schemata = [ schema_name for catalog_name, schema_name in (re.match(match_str, full_name).groups() for full_name in [x for x in self.main.plan.migrationSource.schemaNames if x not in SYSTEM_SCHEMAS])] self.schema_selector = DatabaseSchemaSelector(self.catalog_schemata, tree_checked_callback=self.update_next_button) self.content.add(self.schema_selector, True, True) self.innodb_switch = mforms.newCheckBox() self.innodb_switch.set_text('Migrate MyISAM tables to InnoDB') self.innodb_switch.set_active(True) self.content.add_end(self.innodb_switch, False) self.content.add_end(mforms.newLabel(''), False) self.next_button.set_text('Start Copy >') self.next_button.set_enabled(False) def update_next_button(self, count): self.next_button.set_enabled( bool(count) ) def go_next(self): self.main.plan.migrationSource.selectedCatalogName = 'def' try: self.main.plan.migrationSource.selectedSchemataNames = self.schema_selector.get_selected() except Exception, e: mforms.Utilities.show_error("Invalid Selection", str(e), "OK", "", "") return self.main.plan.state.applicationData["schemaMappingMethod"] = "drop_catalog" schema_set = set(schema.upper() for schema in self.schema_selector.get_selected()) target_schema_set = set(schema.upper() for schema in grt.modules.DbMySQLFE.getSchemaNames(self.main.plan.migrationTarget.connection)) existing_schemas = list(schema_set.intersection(target_schema_set)) if len(existing_schemas) > 0: if mforms.Utilities.show_message("Existing Schemas", "The %s %s " % ( 'schema' if len(existing_schemas) == 1 else 'schemas', ", ".join(existing_schemas)) + "will be dropped in the target MySQL Server and all the existing data will be" + " lost. Do you want to continue?" , "Yes", "No", "") == mforms.ResultCancel: return super(SchemaMainView, self).go_next()
class SchemaMainView(WizardPage): def __init__(self, main): WizardPage.__init__(self, main, 'Schemas Selection') self._ui_created = False self.main.add_wizard_page(self, 'SourceTarget', 'Schemas Selection') optionspanel = mforms.newPanel(mforms.TitledBoxPanel) optionspanel.set_title('Schema Name Mapping Method') optionsbox = mforms.newBox(False) optionsbox.set_padding(8) optionsbox.set_spacing(8) label = mforms.newLabel( 'Choose how the reverse engineered schemas and objects should be mapped.\n' ) label.set_name('') optionsbox.add(label, False) options = [ 'Keep schemas as they are: Catalog.Schema.Table -> Schema.Table', 'Only one schema: Catalog.Schema.Table -> Catalog.Table', 'Only one schema, keep current schema names as a prefix: Catalog.Schema.Table -> Catalog.Schema_Table', ] rid = mforms.RadioButton.new_id() self.options = [] for opt in options: radio_button = mforms.newRadioButton(rid) radio_button.set_name('Option %i' % options.index(opt)) radio_button.set_text(opt) optionsbox.add(radio_button, False) self.options.append(radio_button) self.options[1].set_active(True) optionspanel.add(optionsbox) self._optionspanel = optionspanel #self._advanced_shown = False #self._optionspanel.show(False) self.content.add_end(optionspanel, False) def page_activated(self, advancing): WizardPage.page_activated(self, advancing) if advancing: self.doesSupportCatalogs = self.main.plan.migrationSource.rdbms.doesSupportCatalogs match_str = r"\%s\.\%s" % (self.main.plan.migrationSource. _db_module.quoteIdentifier('(.+)\\'), self.main.plan.migrationSource. _db_module.quoteIdentifier('(.+)\\')) if self.doesSupportCatalogs > 0: catalog_schemata_list = [ (catalog_name, schema_name) for catalog_name, schema_name in ( re.match(match_str, full_name).groups() for full_name in self.main.plan.migrationSource.schemaNames) ] self.catalog_schemata = {} for catalog_name, schema_name in catalog_schemata_list: self.catalog_schemata.setdefault(catalog_name, []).append(schema_name) self.catalog_schemata = self.catalog_schemata.items() self._optionspanel.show(True) #self.advanced_button.show(True) else: self.catalog_schemata = [ schema_name for catalog_name, schema_name in ( re.match(match_str, full_name).groups() for full_name in self.main.plan.migrationSource.schemaNames) ] self._optionspanel.show(False) #self.advanced_button.show(False) if self.schema_selector: self.content.remove(self.schema_selector) self.schema_selector = DatabaseSchemaSelector( self.catalog_schemata, tree_checked_callback=self.update_next_button) self.content.add(self.schema_selector, True, True) self.next_button.set_enabled(False) def create_ui(self): label = mforms.newLabel('Select the schemata you want to migrate:') label.set_name('Select Schema To Migrate') label.set_style(mforms.BoldStyle) self.content.add(label, False) self.schema_selector = None def should_skip(self): return self.main.plan.migrationSource.rdbms.doesSupportCatalogs < 0 and len( self.main.plan.migrationSource.schemaNames) == 1 def page_skipped(self): # called when the page is not activated, because should_skip returned True match_re = self.main.plan.migrationSource._db_module.quoteIdentifier( '(.+)\\') names = [ re.match(match_re, s).groups()[0] for s in self.main.plan.migrationSource.schemaNames ] self.main.plan.migrationSource.selectedCatalogName, self.main.plan.migrationSource.selectedSchemataNames = ( "def", names) self.main.plan.state.applicationData[ "schemaMappingMethod"] = "drop_catalog" def update_next_button(self, count): self.next_button.set_enabled(bool(count)) def schemata_to_migrate(self): selected = self.schema_selector.get_selected() if self.doesSupportCatalogs > 0: if len(selected) > 1: raise Exception( 'Cannot select multiple schemas from different catalogs') catalog = selected.keys()[0] return catalog, selected[catalog] else: return "def", selected #def go_advanced(self): # self._advanced_shown = not self._advanced_shown # self._optionspanel.show(self._advanced_shown) def go_next(self): try: self.main.plan.migrationSource.selectedCatalogName, self.main.plan.migrationSource.selectedSchemataNames = self.schemata_to_migrate( ) except Exception, e: mforms.Utilities.show_error("Invalid Selection", str(e), "OK", "", "") return def find_selected_option( ): #TODO: When we finally drop py2.5 support substitute this with self.options.index(next(opt for opt in self.options if opt.get_active())) for idx, option_radio in enumerate(self.options): if option_radio.get_active(): return idx return None if self.doesSupportCatalogs: self.main.plan.state.applicationData["schemaMappingMethod"] = [ "drop_catalog", "drop_schema", "merge_schema" ][find_selected_option()] else: self.main.plan.state.applicationData[ "schemaMappingMethod"] = "drop_catalog" WizardPage.go_next(self)
class SchemaMainView(WizardPage): def __init__(self, main): WizardPage.__init__(self, main, 'Schemata Selection') self._ui_created = False self.main.add_wizard_page(self, 'SourceTarget', 'Schemata Selection') optionspanel = mforms.newPanel(mforms.TitledBoxPanel) optionspanel.set_title('Schema Name Mapping Method') optionsbox = mforms.newBox(False) optionsbox.set_padding(8) optionsbox.set_spacing(8) optionsbox.add(mforms.newLabel('Choose how the reverse engineered schemata and objects should be mapped.\n'), False) options = [ 'Keep schemata as they are: Catalog.Schema.Table -> Schema.Table', 'Only one schema: Catalog.Schema.Table -> Catalog.Table', 'Only one schema, keep current schema names as a prefix: Catalog.Schema.Table -> Catalog.Schema_Table', ] rid = mforms.RadioButton.new_id() self.options = [] for opt in options: radio_button = mforms.newRadioButton(rid) radio_button.set_text(opt) optionsbox.add(radio_button, False) self.options.append(radio_button) self.options[1].set_active(True) optionspanel.add(optionsbox) self._optionspanel = optionspanel #self._advanced_shown = False #self._optionspanel.show(False) self.content.add_end(optionspanel, False) def page_activated(self, advancing): WizardPage.page_activated(self, advancing) if advancing: self.doesSupportCatalogs = self.main.plan.migrationSource.rdbms.doesSupportCatalogs if self.doesSupportCatalogs: catalog_schemata_list = [ (catalog_name, schema_name) for catalog_name, dot, schema_name in (full_name.rpartition('.') for full_name in self.main.plan.migrationSource.schemaNames) ] self.catalog_schemata = {} for catalog_name, schema_name in catalog_schemata_list: self.catalog_schemata.setdefault(catalog_name, []).append(schema_name) self.catalog_schemata = self.catalog_schemata.items() self._optionspanel.show(True) #self.advanced_button.show(True) else: self.catalog_schemata = [ schema_name for catalog_name, dot, schema_name in (full_name.rpartition('.') for full_name in self.main.plan.migrationSource.schemaNames) ] self._optionspanel.show(False) #self.advanced_button.show(False) if self.schema_selector: self.content.remove(self.schema_selector) self.schema_selector = DatabaseSchemaSelector(self.catalog_schemata, tree_checked_callback=self.update_next_button) self.content.add(self.schema_selector, True, True) self.next_button.set_enabled(False) def create_ui(self): label = mforms.newLabel('Select the schemata you want to migrate:') label.set_style(mforms.BoldStyle) self.content.add(label, False) self.schema_selector = None def update_next_button(self, count): self.next_button.set_enabled( bool(count) ) def schemata_to_migrate(self): selected = self.schema_selector.get_selected() if self.doesSupportCatalogs: if len(selected) > 1: raise Exception('Cannot select multiple schemata from different catalogs') catalog = selected.keys()[0] return catalog, selected[catalog] else: return 'def', selected #def go_advanced(self): # self._advanced_shown = not self._advanced_shown # self._optionspanel.show(self._advanced_shown) def go_next(self): try: self.main.plan.migrationSource.selectedCatalogName, self.main.plan.migrationSource.selectedSchemataNames = self.schemata_to_migrate() except Exception, e: mforms.Utilities.show_error("Invalid Selection", str(e), "OK", "", "") return def find_selected_option(): #TODO: When we finally drop py2.5 support substitute this with self.options.index(next(opt for opt in self.options if opt.get_active())) for idx, option_radio in enumerate(self.options): if option_radio.get_active(): return idx return None if self.doesSupportCatalogs: self.main.plan.state.applicationData["schemaMappingMethod"] = ["drop_catalog", "drop_schema", "merge_schema"][find_selected_option()] else: self.main.plan.state.applicationData["schemaMappingMethod"] = "drop_catalog" WizardPage.go_next(self)
class SchemaMainView(WizardPage): def __init__(self, main): super(SchemaMainView, self).__init__(main, 'Schema Selection') def create_ui(self): self.content.set_padding(20) self.content.add( mforms.newLabel( 'Select the schemas to copy to the destination server and click [Start Copy >] to start the process.' ), False, True) match_str = r"\%s\.\%s" % (self.main.plan.migrationSource._db_module. quoteIdentifier('(.+)\\'), self.main.plan.migrationSource._db_module. quoteIdentifier('(.+)\\')) self.catalog_schemata = [ schema_name for catalog_name, schema_name in ( re.match(match_str, full_name).groups() for full_name in [ x for x in self.main.plan.migrationSource.schemaNames if x not in SYSTEM_SCHEMAS ]) ] self.schema_selector = DatabaseSchemaSelector( self.catalog_schemata, tree_checked_callback=self.update_next_button) self.content.add(self.schema_selector, True, True) self.innodb_switch = mforms.newCheckBox() self.innodb_switch.set_text('Migrate MyISAM tables to InnoDB') self.innodb_switch.set_active(True) self.content.add_end(self.innodb_switch, False) self.content.add_end(mforms.newLabel(''), False) self.next_button.set_text('Start Copy >') self.next_button.set_enabled(False) def update_next_button(self, count): self.next_button.set_enabled(bool(count)) def go_next(self): self.main.plan.migrationSource.selectedCatalogName = 'def' try: self.main.plan.migrationSource.selectedSchemataNames = self.schema_selector.get_selected( ) except Exception, e: mforms.Utilities.show_error("Invalid Selection", str(e), "OK", "", "") return self.main.plan.state.applicationData[ "schemaMappingMethod"] = "drop_catalog" schema_set = set(schema.upper() for schema in self.schema_selector.get_selected()) target_schema_set = set( schema.upper() for schema in grt.modules.DbMySQLFE.getSchemaNames( self.main.plan.migrationTarget.connection)) existing_schemas = list(schema_set.intersection(target_schema_set)) if len(existing_schemas) > 0: if mforms.Utilities.show_message( "Existing Schemas", "The %s %s " % ('schema' if len(existing_schemas) == 1 else 'schemas', ", ".join(existing_schemas)) + "will be dropped in the target MySQL Server and all the existing data will be" + " lost. Do you want to continue?", "Yes", "No", "") == mforms.ResultCancel: return super(SchemaMainView, self).go_next()