Remove the old scheduler
[cds-indico.git] / indico / core / db / migration.py
blob59602f7c7d67d0d8c57c9e8dee8113cc39bd7922
1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 from ZODB.DB import DB
19 """
20 We have two dictionaries
22 - globalname_dict: We declare the classes that are going to be moved or renamed.
23 The key is the name to be renamed or moved.
24 The value is a tuple with the new module name and the new class; it can have only one value
25 or both.
26 - modulename_dict: We declare the modules that are going to be moved.
27 The key is the old module's name and if it finishes with '.' means that
28 that module and all submodules are going to be moved.
29 The value is the new module and also follows the same rules as the key.
30 """
32 globalname_dict = {
33 "PersistentMapping": ("persistent.mapping", None),
34 "PersistentList": ("persistent.list", None),
35 'SlotSchedule': ('MaKaC.schedule', 'SlotSchedule'),
36 'PosterSlotSchedule': ('MaKaC.schedule', 'PosterSlotSchedule'),
37 'UHConferenceInstantMessaging': ('MaKaC.webinterface.urlHandlers', 'URLHandler'),
38 'Avatar': ('indico.modules.users.legacy', 'AvatarUserWrapper'),
39 'Group': ('indico.modules.groups.legacy', 'LocalGroupWrapper'),
40 'LDAPGroup': ('indico.modules.groups.legacy', 'LDAPGroupWrapper'),
41 'CERNGroup': ('indico.modules.groups.legacy', 'LDAPGroupWrapper')
44 modulename_dict = {
45 "IndexedCatalog.BTrees.": "BTrees."
49 class MigratedDB(DB):
50 """Subclass of ZODB.DB necessary to remove possible existing dependencies
51 from IC"""
53 def classFactory(self, connection, modulename, globalname):
54 # indico_ are new plugins, we don't need/want this kind of migration there
55 # The main reason for this check is not having to rename FoundationSyncTask
56 # which was deleted from core and now resides in a plugin.
57 if globalname in globalname_dict and not modulename.startswith('indico_'):
58 if globalname_dict[globalname][0]:
59 modulename = globalname_dict[globalname][0]
60 if globalname_dict[globalname][1]:
61 globalname = globalname_dict[globalname][1]
62 # There is an else in order to do not overwrite the rule.
63 # It could create some inconsistency
64 elif modulename in modulename_dict:
65 modulename = modulename_dict[modulename]
66 else:
67 # This is the case of a module with submodules
68 for former_mod_name in modulename_dict:
69 if former_mod_name[-1] == "." and modulename.startswith(former_mod_name):
70 modulename = modulename_dict[former_mod_name] + modulename[len(former_mod_name):]
71 return DB.classFactory(self, connection, modulename, globalname)