1
2
3
4
5
6
7 import Ganga.Utility.logging
8 logger = Ganga.Utility.logging.getLogger()
9
10 import Ganga.Utility.Config
11 config = Ganga.Utility.Config.makeConfig('MigrationControl','migration of different job versions in the peristent repository')
12
13
14 config.addOption('migration','deny','no plugin migration')
15 config.addOption('display','compact','display limited number of choices for the interactive migration')
16
17
18
19
20
22
23 _choices_compact = {
24 '1' : 'Yes',
25 '2' : 'No',
26 '3' : 'Yes for All',
27 '4' : 'No for All'}
28
29 _choices_full = {
30 '1' : 'Yes',
31 '2' : 'No',
32 '3' : 'Yes for All',
33 '4' : 'No for All',
34 '5' : 'Yes for All with this version',
35 '6' : 'No for All with this version',
36 '7' : 'Yes for All with this name',
37 '8' : 'No for All with this name',
38 '9' : 'Yes for All within this category',
39 '10': 'No for All within this category'}
40
42
43 - def __init__(self, subtree, flag = None):
46
49
51 self.flag = True
52
53 for k in self:
54 self[k].allow()
55
57 self.flag = False
58
59 for k in self:
60 self[k].deny()
61
62 - def get(self, key, def_value = None):
69
75
76 - def isAllowed(self, category, name, version, msg = ''):
77 """This method checks whether migration for the plugin called 'name' of version 'version'
78 from category 'category' is allowed or not. If migration is not explicitly allowed through
79 MigrationControl.migration object it will warn user with the message 'msg' and
80 ask for permission to allow migration.
81 """
82 res = self._all_categs.get(category).get(name).get(version).is_allowed()
83 if res == None:
84
85 answer = self.getUserInput(msg)
86 if answer == 'Yes':
87 res = True
88 elif answer == 'No':
89 res = False
90 elif answer == 'Yes for All with this version':
91 self.allow(category = category, name = name, version = version)
92 res = True
93 elif answer == 'No for All with this version':
94 self.deny(category = category, name = name, version = version)
95 res = False
96 elif answer == 'Yes for All with this name':
97 self.allow(category = category, name = name)
98 res = True
99 elif answer == 'No for All with this name':
100 self.deny(category = category, name = name)
101 res = False
102 elif answer == 'Yes for All within this category':
103 self.allow(category = category)
104 res = True
105 elif answer == 'No for All within this category':
106 self.deny(category = category)
107 res = False
108 elif answer == 'Yes for All':
109 self.allow()
110 res = True
111 elif answer == 'No for All':
112 self.deny()
113 res = False
114 else:
115
116 res = True
117 return res
118
119 - def allow(self, category = None, name = None, version = None):
120 """This method allows migration.
121 allow() --> allow all
122 allow(category)--> allow all from 'category'
123 allow(category, name) --> allow for all versions of 'name' from 'category'
124 allow(category, name, version) --> allow for 'version' and 'name' from 'category'
125 """
126
127 if category == None:
128
129 self._all_categs.allow()
130 elif name == None:
131
132 self._all_categs.get(category).allow()
133 elif version == None:
134
135 self._all_categs.get(category).get(name).allow()
136 else:
137
138 self._all_categs.get(category).get(name).get(version).allow()
139
140 - def deny(self, category = None, name = None, version = None):
141 """This method denies migration.
142 deny() --> deny all
143 deny(category)--> deny all from 'category'
144 deny(category, name) --> deny for all versions of 'name' from 'category'
145 deny(category, name, version) --> deny for 'version' and 'name' from 'category'
146 """
147
148
149 if category == None:
150
151 self._all_categs.deny()
152 elif name == None:
153
154 self._all_categs.get(category).deny()
155 elif version == None:
156
157 self._all_categs.get(category).get(name).deny()
158 else:
159
160 self._all_categs.get(category).get(name).get(version).deny()
161
182
183
184 migration = MigrationControl()
185 migration.display = config['display']
186 if config['migration'] == 'allow':
187 migration.allow()
188 elif config['migration'] == 'deny':
189 migration.deny()
190
191
192 migrated_jobs = []
193