Пример #1
0
    def __init__(self):
        grt.modules.Workbench.initializeOtherRDBMS()
        self.state = grt.root.wb.migration
        if not self.state:
            self.state = grt.classes.db_migration_Migration()
            self.state.owner = grt.root.wb
            grt.root.wb.migration = self.state

            datadir = mforms.App.get().get_user_data_folder()
            path = datadir + "/migration_generic_typemap.xml"
            if os.path.exists(path):
                self.state.genericDatatypeMappings.extend(grt.unserialize(path))
            else:
                global_path = mforms.App.get().get_resource_path("")
                global_path += "/modules/data/migration_generic_typemap.xml"
                if os.path.exists(global_path):
                    self.state.genericDatatypeMappings.extend(grt.unserialize(global_path))

        self.migrationSource = None
        self.migrationTarget = None
        
        if sys.platform == "win32":
            self.wbcopytables_path = mforms.App.get().get_executable_path("wbcopytables.exe")
        elif sys.platform == "darwin":
            self.wbcopytables_path = mforms.App.get().get_executable_path("wbcopytables")
        else:
            self.wbcopytables_path = mforms.App.get().get_executable_path("wbcopytables-bin")
            if not os.path.exists(self.wbcopytables_path):
                self.wbcopytables_path = os.path.join(os.path.dirname(grt.root.wb.registry.appExecutablePath), "wbcopytables-bin")
            if not os.path.exists(self.wbcopytables_path):
                self.wbcopytables_path = "wbcopytables-bin"
        if type(self.wbcopytables_path) == unicode:
            self.wbcopytables_path = self.wbcopytables_path.encode("UTF-8")
def run():
    import grt
    import os
    
    datadir = mforms.App.get().get_user_data_folder()
    path = datadir + "/migration_generic_typemap.xml"
    if grt.root.wb.migration:
        typemap = grt.root.wb.migration.genericDatatypeMappings
    else:        
        if os.path.exists(path):
            typemap = grt.unserialize(path)
        else:
            global_path = mforms.App.get().get_resource_path("")
            global_path += "/modules/data/migration_generic_typemap.xml"
            if os.path.exists(global_path):
                typemap = grt.unserialize(global_path)
            else:
                typemap = grt.List(grt.OBJECT, "db.migration.DatatypeMapping")
    form = DatatypeMappingEditor()
    if form.run(typemap):
        grt.serialize(typemap, path)
        return 1
    return 0
Пример #3
0
 def get_profiles_for(system):
     path = mforms.App.get().get_resource_path("mysql.profiles")
     if not path:
         path = mforms.App.get().get_resource_path("")
         if not path:
             log_error(_this_file, "Could not find mysql.profiles dir\n")
             return []
         path += "/mysql.profiles"
     files = os.listdir(path)
     profiles = []
     for f in files:
         data = grt.unserialize(os.path.join(path, f))
         if data.has_key("sys.system") and data["sys.system"] == system:
             profiles.append(data)
     return profiles
    def test_script_full_mssql_migration(self):
        # Sample migration plan:
        plan = migration.MigrationPlan()

        # Each migration source instance needs a concrete connection to the server with the source database:
        source_server_instance = grt.unserialize('./fixtures/mssql_connection.xml')
        self.assertEqual(source_server_instance.parameterValues['database'], 'AdventureWorks')
        plan.setSourceConnection(source_server_instance)

        # Each plan must set a migration target
        plan.setMigrationTarget('MySQL')        # a string with the name of the instance to be used

        # Now reverse engineer the source catalog:
        plan.migrationSource.reverseEngineer('AdventureWorks')

        # Proceed to the actual migration:
        plan.migrate()  # Now the target should have been populated with the migrated objects

        # Get the resulting MySQL script:
        script = plan.migrationTarget.generateScript()

        self.assertIsInstance(script, str)
Пример #5
0
    def get_profiles_for(system, version):
        path = mforms.App.get().get_resource_path("mysql.profiles")
        if not path:
            path = mforms.App.get().get_resource_path("")
            if not path:
                log_error("Could not find mysql.profiles dir\n")
                return []
            path += "/mysql.profiles"
        version = Version.fromstr(version or "5.6")
        files = [f for f in os.listdir(path) if f.endswith(".xml")]
        profiles = []
        matched_profiles = []
        for f in files:
            data = grt.unserialize(os.path.join(path, f))
            if data and data.has_key("sys.system") and data["sys.system"] == system:
                profiles.append(data)
                profile_version = Version.fromstr(data.get("serverVersion"))
                if version.majorNumber == profile_version.majorNumber or version.minorNumber == profile_version.minorNumber:
                    matched_profiles.append(data)

        if matched_profiles:
            return matched_profiles
        return profiles
Пример #6
0
    def get_profiles_for(system, version):
        path = mforms.App.get().get_resource_path("mysql.profiles")
        if not path:
            path = mforms.App.get().get_resource_path("")
            if not path:
                log_error("Could not find mysql.profiles dir\n")
                return []
            path += "/mysql.profiles"
        version = Version.fromstr(version or "5.6")
        files = [f for f in os.listdir(path) if f.endswith(".xml")]
        profiles = []
        matched_profiles = []
        for f in files:
            data = grt.unserialize(os.path.join(path, f))
            if data and data.has_key(
                    "sys.system") and data["sys.system"] == system:
                profiles.append(data)
                profile_version = Version.fromstr(data.get("serverVersion"))
                if version.majorNumber == profile_version.majorNumber or version.minorNumber == profile_version.minorNumber:
                    matched_profiles.append(data)

        if matched_profiles:
            return matched_profiles
        return profiles
Пример #7
0
def restoreConnections():
    def generate_unique_name(name, name_set):
        new_name = name
        idx = 1
        while True:
            if not new_name in name_set:
                return new_name
            new_name = name + ' (%d)' % idx
            idx += 1

    file_chooser = mforms.newFileChooser(mforms.Form.main_form(), mforms.OpenFile)
    file_chooser.set_title('Select a Connections Backup File')
    file_chooser.set_extensions('ZIP Files (*.zip)|*.zip', 'import')
    if file_chooser.run_modal():
        backup_path = file_chooser.get_path()
        try:
            backup_file = zipfile.ZipFile(backup_path, 'r')
            try:
                instances_file = tempfile.NamedTemporaryFile(delete=False)
                instances_file.write(backup_file.read('server_instances.xml'))
                instances_file.close()

                connections_file = tempfile.NamedTemporaryFile(delete=False)
                connections_file.write(backup_file.read('connections.xml'))
                connections_file.close()
            except KeyError, error:
                mforms.Utilities.show_error('Restore Connections Error', 'The selected file is not a valid backup file '
                                            'or the file is corrupted: %s.' % error.message,
                                            'OK', '', '')
                grt.log_error('restoreConnections', 'The selected file is not a valid backup file '
                              'or the file is corrupted: %s.' % error.message)
                return

            connections = grt.unserialize(connections_file.name)

            if not isinstance(connections, grt.List):
                mforms.Utilities.show_error('Restore Connections Error', 'The selected file is not a valid backup file '
                                            'or the file is corrupted.',
                                            'OK', '', '')
                grt.log_error('restoreConnections', 'The selected archive does not have a valid connection backup file.\n')
                return

            inserted_connections = {}
            existent_connection_names = set(conn.name for conn in grt.root.wb.rdbmsMgmt.storedConns)
            existent_connection_ids = set(conn.__id__ for conn in grt.root.wb.rdbmsMgmt.storedConns)
            duplicate_connection_count = 0
            for candidate_connection in connections:
                if candidate_connection.__id__ in existent_connection_ids:
                    duplicate_connection_count = duplicate_connection_count + 1
                    continue
                    
                candidate_connection.name = generate_unique_name(candidate_connection.name, existent_connection_names)

                existent_connection_names.add(candidate_connection.name)
                candidate_connection.owner = grt.root.wb.rdbmsMgmt
                inserted_connections[candidate_connection.__id__] = candidate_connection
                grt.root.wb.rdbmsMgmt.storedConns.append(candidate_connection)

            instances   = grt.unserialize(instances_file.name)
            
            if not isinstance(instances, grt.List):
                mforms.Utilities.show_error('Restore Connections Error', 'The selected file is not a valid backup file '
                                            'or the file is corrupted.',
                                            'OK', '', '')
                grt.log_error('restoreConnections', 'Workbench restored %i valid connections but server configuration data could not be found or is not valid.\n' % len(connections))
                return
     
            existent_instance_names = set(instance.name for instance in grt.root.wb.rdbmsMgmt.storedInstances)
            previous_instances_conns = set()
            duplicated_instance_count = 0
            for candidate_instance in instances:
                if candidate_instance.connection.__id__ in previous_instances_conns:
                    duplicated_instance_count = duplicated_instance_count + 1
                    continue  # Skip instances whose connections are associated to previously processed instances
                previous_instances_conns.add(candidate_instance.connection.__id__)
                candidate_instance.name = generate_unique_name(candidate_instance.name, existent_instance_names)

                existent_instance_names.add(candidate_instance.name)
                new_conn = inserted_connections.get(candidate_instance.connection.__id__, None)
                candidate_instance = candidate_instance.shallow_copy()
                candidate_instance.connection = new_conn
                grt.root.wb.rdbmsMgmt.storedInstances.append(candidate_instance)

            grt.modules.Workbench.refreshHomeConnections()
            grt.modules.Workbench.saveConnections()
            grt.modules.Workbench.saveInstances()
            
            if duplicate_connection_count > 0 or duplicated_instance_count > 0:
                message = []
                message.append('Workbench detected ')
                if duplicate_connection_count > 0:
                    message.append('%i duplicated connections' % duplicate_connection_count)
                if duplicated_instance_count > 0:
                    if duplicate_connection_count > 0:
                        message.append(' and ')
                    message.append('%i duplicated instances' % duplicated_instance_count)
                message.append(', which were not restored.')
                mforms.Utilities.show_warning('Restore Connections', ''.join(message), 'OK', '', '')
            
        except zipfile.BadZipfile, error:
            mforms.Utilities.show_error('Restore Connections Error', 'The selected file is not a valid backup file '
                                        'or the file is corrupted.',
                                        'OK', '', '')
            grt.log_error('restoreConnections', 'The selected file is not a valid backup file or the file is corrupted: %s\n' % error)
def initializeDBMSInfo():
    rdbms = grt.unserialize(ModuleInfo.moduleDataDirectory + "/sybase_rdbms_info.xml")
    grt.root.wb.rdbmsMgmt.rdbms.append(rdbms)
    return rdbms
Пример #9
0
 def initializeDBMSInfo(cls, xml_data_path):
     cls._rdbms = grt.unserialize(os.path.join(ModuleInfo.moduleDataDirectory, xml_data_path))
     grt.root.wb.rdbmsMgmt.rdbms.append(cls._rdbms)
     return cls._rdbms
 def initializeDBMSInfo(cls, xml_data_path):
     cls._rdbms = grt.unserialize(os.path.join(ModuleInfo.moduleDataDirectory, xml_data_path))
     grt.root.wb.rdbmsMgmt.rdbms.append(cls._rdbms)
     return cls._rdbms
Пример #11
0
def restoreConnections():
    def generate_unique_name(name, name_set):
        new_name = name
        idx = 1
        while True:
            if not new_name in name_set:
                return new_name
            new_name = name + ' (%d)' % idx
            idx += 1

    file_chooser = mforms.newFileChooser(mforms.Form.main_form(),
                                         mforms.OpenFile)
    file_chooser.set_title('Select a Connections Backup File')
    file_chooser.set_extensions('ZIP Files (*.zip)|*.zip', 'import')
    if file_chooser.run_modal():
        backup_path = file_chooser.get_path()
        try:
            backup_file = zipfile.ZipFile(backup_path, 'r')
            try:
                instances_file = tempfile.NamedTemporaryFile(delete=False)
                instances_file.write(backup_file.read('server_instances.xml'))
                instances_file.close()

                connections_file = tempfile.NamedTemporaryFile(delete=False)
                connections_file.write(backup_file.read('connections.xml'))
                connections_file.close()
            except KeyError, error:
                mforms.Utilities.show_error(
                    'Restore Connections Error',
                    'The selected file is not a valid backup file '
                    'or the file is corrupted: %s.' % error.message, 'OK', '',
                    '')
                grt.log_error(
                    'restoreConnections',
                    'The selected file is not a valid backup file '
                    'or the file is corrupted: %s.' % error.message)
                return

            instances = grt.unserialize(instances_file.name)
            connections = grt.unserialize(connections_file.name)

            if not isinstance(instances, grt.List) or not isinstance(
                    connections, grt.List):
                mforms.Utilities.show_error(
                    'Restore Connections Error',
                    'The selected file is not a valid backup file '
                    'or the file is corrupted.', 'OK', '', '')
                grt.log_error(
                    'restoreConnections',
                    'The selected file is not a valid backup file or the file is corrupted.'
                )
                return

            inserted_connections = {}
            existent_connection_names = set(
                conn.name for conn in grt.root.wb.rdbmsMgmt.storedConns)
            for candidate_connection in connections:
                new_name = generate_unique_name(candidate_connection.name,
                                                existent_connection_names)
                if new_name != candidate_connection.name:
                    candidate_connection.name = new_name
                existent_connection_names.add(candidate_connection.name)
                old_id = candidate_connection.__id__
                candidate_connection = candidate_connection.shallow_copy()
                inserted_connections[old_id] = candidate_connection
                grt.root.wb.rdbmsMgmt.storedConns.append(candidate_connection)

            existent_instance_names = set(
                instance.name
                for instance in grt.root.wb.rdbmsMgmt.storedInstances)
            previous_instances_conns = set()
            for candidate_instance in instances:
                if candidate_instance.connection.__id__ in previous_instances_conns:
                    continue  # Skip instances whose connections are associated to previously processed instances
                previous_instances_conns.add(
                    candidate_instance.connection.__id__)
                new_name = generate_unique_name(candidate_instance.name,
                                                existent_instance_names)
                if new_name != candidate_instance.name:
                    candidate_instance.name = new_name
                existent_instance_names.add(candidate_instance.name)
                new_conn = inserted_connections.get(
                    candidate_instance.connection.__id__, None)
                candidate_instance = candidate_instance.shallow_copy()
                candidate_instance.connection = new_conn
                grt.root.wb.rdbmsMgmt.storedInstances.append(
                    candidate_instance)

            grt.modules.Workbench.refreshHomeConnections()
            grt.modules.Workbench.saveConnections()
            grt.modules.Workbench.saveInstances()
        except zipfile.BadZipfile, error:
            mforms.Utilities.show_error(
                'Restore Connections Error',
                'The selected file is not a valid backup file '
                'or the file is corrupted.', 'OK', '', '')
            grt.log_error(
                'restoreConnections',
                'The selected file is not a valid backup file or the file is corrupted: %s'
                % error)
Пример #12
0
def restoreConnections():
    def generate_unique_name(name, name_set):
        new_name = name
        idx = 1
        while True:
            if not new_name in name_set:
                return new_name
            new_name = name + ' (%d)' % idx
            idx += 1

    file_chooser = mforms.newFileChooser(mforms.Form.main_form(), mforms.OpenFile)
    file_chooser.set_title('Select a Connections Backup File')
    file_chooser.set_extensions('ZIP Files (*.zip)|*.zip', 'import')
    if file_chooser.run_modal():
        backup_path = file_chooser.get_path()
        try:
            backup_file = zipfile.ZipFile(backup_path, 'r')
            try:
                instances_file = tempfile.NamedTemporaryFile(delete=False)
                instances_file.write(backup_file.read('server_instances.xml'))
                instances_file.close()

                connections_file = tempfile.NamedTemporaryFile(delete=False)
                connections_file.write(backup_file.read('connections.xml'))
                connections_file.close()
            except KeyError, error:
                mforms.Utilities.show_error('Restore Connections Error', 'The selected file is not a valid backup file '
                                            'or the file is corrupted: %s.' % error.message,
                                            'OK', '', '')
                grt.log_error('restoreConnections', 'The selected file is not a valid backup file '
                              'or the file is corrupted: %s.' % error.message)
                return

            instances   = grt.unserialize(instances_file.name)
            connections = grt.unserialize(connections_file.name)

            if not isinstance(instances, grt.List) or not isinstance(connections, grt.List):
                mforms.Utilities.show_error('Restore Connections Error', 'The selected file is not a valid backup file '
                                            'or the file is corrupted.',
                                            'OK', '', '')
                grt.log_error('restoreConnections', 'The selected file is not a valid backup file or the file is corrupted.')
                return

            inserted_connections = {}
            existent_connection_names = set(conn.name for conn in grt.root.wb.rdbmsMgmt.storedConns)
            for candidate_connection in connections:
                new_name = generate_unique_name(candidate_connection.name, existent_connection_names)
                if new_name != candidate_connection.name:
                    candidate_connection.name = new_name
                existent_connection_names.add(candidate_connection.name)
                old_id = candidate_connection.__id__
                candidate_connection = candidate_connection.shallow_copy()
                inserted_connections[old_id] = candidate_connection
                grt.root.wb.rdbmsMgmt.storedConns.append(candidate_connection)

            existent_instance_names = set(instance.name for instance in grt.root.wb.rdbmsMgmt.storedInstances)
            previous_instances_conns = set()
            for candidate_instance in instances:
                if candidate_instance.connection.__id__ in previous_instances_conns:
                    continue  # Skip instances whose connections are associated to previously processed instances
                previous_instances_conns.add(candidate_instance.connection.__id__)
                new_name = generate_unique_name(candidate_instance.name, existent_instance_names)
                if new_name != candidate_instance.name:
                    candidate_instance.name = new_name
                existent_instance_names.add(candidate_instance.name)
                new_conn = inserted_connections.get(candidate_instance.connection.__id__, None)
                candidate_instance = candidate_instance.shallow_copy()
                candidate_instance.connection = new_conn
                grt.root.wb.rdbmsMgmt.storedInstances.append(candidate_instance)

            grt.modules.Workbench.refreshHomeConnections()
            grt.modules.Workbench.saveConnections()
            grt.modules.Workbench.saveInstances()
        except zipfile.BadZipfile, error:
            mforms.Utilities.show_error('Restore Connections Error', 'The selected file is not a valid backup file '
                                        'or the file is corrupted.',
                                        'OK', '', '')
            grt.log_error('restoreConnections', 'The selected file is not a valid backup file or the file is corrupted: %s' % error)
Пример #13
0
def initializeDBMSInfo():
    rdbms = grt.unserialize(ModuleInfo.moduleDataDirectory +
                            "/sybase_rdbms_info.xml")
    grt.root.wb.rdbmsMgmt.rdbms.append(rdbms)
    return rdbms
Пример #14
0
def restoreConnections():
    def generate_unique_name(name, name_set):
        new_name = name
        idx = 1
        while True:
            if not new_name in name_set:
                return new_name
            new_name = name + ' (%d)' % idx
            idx += 1

    file_chooser = mforms.newFileChooser(mforms.Form.main_form(), mforms.OpenFile)
    file_chooser.set_title('Select a Connections Backup File')
    file_chooser.set_extensions('ZIP Files (*.zip)|*.zip', 'import')
    if file_chooser.run_modal():
        backup_path = file_chooser.get_path()
        try:
            backup_file = zipfile.ZipFile(backup_path, 'r')
            try:
                instances_file = tempfile.NamedTemporaryFile(delete=False)
                instances_file.write(backup_file.read('server_instances.xml'))
                instances_file.close()

                connections_file = tempfile.NamedTemporaryFile(delete=False)
                connections_file.write(backup_file.read('connections.xml'))
                connections_file.close()
            except KeyError, error:
                mforms.Utilities.show_error('Restore Connections Error', 'The selected file is not a valid backup file '
                                            'or the file is corrupted: %s.' % error.message,
                                            'OK', '', '')
                grt.log_error('restoreConnections', 'The selected file is not a valid backup file '
                              'or the file is corrupted: %s.' % error.message)
                return

            connections = grt.unserialize(connections_file.name)

            if not isinstance(connections, grt.List):
                mforms.Utilities.show_error('Restore Connections Error', 'The selected file is not a valid backup file '
                                            'or the file is corrupted.',
                                            'OK', '', '')
                grt.log_error('restoreConnections', 'The selected archive does not have a valid connection backup file.\n')
                return

            inserted_connections = {}
            existent_connection_names = set(conn.name for conn in grt.root.wb.rdbmsMgmt.storedConns)
            existent_connection_ids = set(conn.__id__ for conn in grt.root.wb.rdbmsMgmt.storedConns)
            duplicate_connection_count = 0
            for candidate_connection in connections:
                if candidate_connection.__id__ in existent_connection_ids:
                    duplicate_connection_count = duplicate_connection_count + 1
                    continue
                    
                candidate_connection.name = generate_unique_name(candidate_connection.name, existent_connection_names)

                existent_connection_names.add(candidate_connection.name)
                candidate_connection.owner = grt.root.wb.rdbmsMgmt
                inserted_connections[candidate_connection.__id__] = candidate_connection
                grt.root.wb.rdbmsMgmt.storedConns.append(candidate_connection)

            instances   = grt.unserialize(instances_file.name)
            
            if not isinstance(instances, grt.List):
                mforms.Utilities.show_error('Restore Connections Error', 'The selected file is not a valid backup file '
                                            'or the file is corrupted.',
                                            'OK', '', '')
                grt.log_error('restoreConnections', 'Workbench restored %i valid connections but server configuration data could not be found or is not valid.\n' % len(connections))
                return
     
            existent_instance_names = set(instance.name for instance in grt.root.wb.rdbmsMgmt.storedInstances)
            previous_instances_conns = set()
            duplicated_instance_count = 0
            for candidate_instance in instances:
                if candidate_instance.connection.__id__ in previous_instances_conns:
                    duplicated_instance_count = duplicated_instance_count + 1
                    continue  # Skip instances whose connections are associated to previously processed instances
                previous_instances_conns.add(candidate_instance.connection.__id__)
                candidate_instance.name = generate_unique_name(candidate_instance.name, existent_instance_names)

                existent_instance_names.add(candidate_instance.name)
                new_conn = inserted_connections.get(candidate_instance.connection.__id__, None)
                candidate_instance = candidate_instance.shallow_copy()
                candidate_instance.connection = new_conn
                grt.root.wb.rdbmsMgmt.storedInstances.append(candidate_instance)

            grt.modules.Workbench.refreshHomeConnections()
            grt.modules.Workbench.saveConnections()
            grt.modules.Workbench.saveInstances()
            
            if duplicate_connection_count > 0 or duplicated_instance_count > 0:
                message = []
                message.append('Workbench detected ')
                if duplicate_connection_count > 0:
                    message.append('%i duplicated connections' % duplicate_connection_count)
                if duplicated_instance_count > 0:
                    if duplicate_connection_count > 0:
                        message.append(' and ')
                    message.append('%i duplicated instances' % duplicated_instance_count)
                message.append(', which were not restored.')
                mforms.Utilities.show_warning('Restore Connections', ''.join(message), 'OK', '', '')
            
        except zipfile.BadZipfile, error:
            mforms.Utilities.show_error('Restore Connections Error', 'The selected file is not a valid backup file '
                                        'or the file is corrupted.',
                                        'OK', '', '')
            grt.log_error('restoreConnections', 'The selected file is not a valid backup file or the file is corrupted: %s\n' % error)