| 188 | ctx.master.addons.invoke_addon_sync(mod, evt) |
| 189 | |
| 190 | def configure(self, updated): |
| 191 | if "scripts" in updated: |
| 192 | for s in ctx.options.scripts: |
| 193 | if ctx.options.scripts.count(s) > 1: |
| 194 | raise exceptions.OptionsError("Duplicate script") |
| 195 | |
| 196 | for a in self.addons[:]: |
| 197 | if a.path not in ctx.options.scripts: |
| 198 | logger.info("Un-loading script: %s" % a.path) |
| 199 | ctx.master.addons.remove(a) |
| 200 | self.addons.remove(a) |
| 201 | |
| 202 | # The machinations below are to ensure that: |
| 203 | # - Scripts remain in the same order |
| 204 | # - Scripts are not initialized un-necessarily. If only a |
| 205 | # script's order in the script list has changed, it is just |
| 206 | # moved. |
| 207 | |
| 208 | current = {} |
| 209 | for a in self.addons: |
| 210 | current[a.path] = a |
| 211 | |
| 212 | ordered = [] |
| 213 | newscripts = [] |
| 214 | for s in ctx.options.scripts: |
| 215 | if s in current: |
| 216 | ordered.append(current[s]) |
| 217 | else: |
| 218 | sc = Script(s, True) |
| 219 | ordered.append(sc) |
| 220 | newscripts.append(sc) |
| 221 | |
| 222 | self.addons = ordered |
| 223 | |
| 224 | for s in newscripts: |
| 225 | ctx.master.addons.register(s) |
| 226 | if self.is_running: |
| 227 | # If we're already running, we configure and tell the addon |
| 228 | # we're up and running. |
| 229 | ctx.master.addons.invoke_addon_sync(s, hooks.RunningHook()) |