[c-c] new server_maintenance hook, called on c-c shell / upgrade stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 25 Mar 2010 15:08:27 +0100
branchstable
changeset 5019 72734c210836
parent 5018 2f2d9bc6dca4
child 5020 30a539c2074d
[c-c] new server_maintenance hook, called on c-c shell / upgrade
server/hook.py
server/migractions.py
--- a/server/hook.py	Thu Mar 25 14:49:24 2010 +0100
+++ b/server/hook.py	Thu Mar 25 15:08:27 2010 +0100
@@ -19,8 +19,11 @@
 Relation (eg before_add_relation, after_add_relation, before_delete_relation,
 after_delete_relation) all have `eidfrom`, `rtype`, `eidto` attributes.
 
-Server start/stop hooks (eg server_startup, server_shutdown) have a `repo`
-attribute, but *their `_cw` attribute is None*.
+Server start/maintenance/stop hooks (eg server_startup, server_maintenance,
+server_shutdown) have a `repo` attribute, but *their `_cw` attribute is None*.
+The `server_startup` is called on regular startup, while `server_maintenance`
+is called on cubicweb-ctl upgrade or shell commands. `server_shutdown` is
+called anyway.
 
 Backup/restore hooks (eg server_backup, server_restore) have a `repo` and a
 `timestamp` attributes, but *their `_cw` attribute is None*.
@@ -57,7 +60,7 @@
 RELATIONS_HOOKS = set(('before_add_relation',   'after_add_relation' ,
                        'before_delete_relation','after_delete_relation'))
 SYSTEM_HOOKS = set(('server_backup', 'server_restore',
-                    'server_startup', 'server_shutdown',
+                    'server_startup', 'server_maintenance', 'server_shutdown',
                     'session_open', 'session_close'))
 ALL_HOOKS = ENTITIES_HOOKS | RELATIONS_HOOKS | SYSTEM_HOOKS
 
--- a/server/migractions.py	Thu Mar 25 14:49:24 2010 +0100
+++ b/server/migractions.py	Thu Mar 25 15:08:27 2010 +0100
@@ -59,7 +59,6 @@
     def __init__(self, config, schema, interactive=True,
                  repo=None, cnx=None, verbosity=1, connect=True):
         MigrationHelper.__init__(self, config, interactive, verbosity)
-        # no config on shell to a remote instance
         if not interactive:
             assert cnx
             assert repo
@@ -67,10 +66,12 @@
             assert repo
             self._cnx = cnx
             self.repo = repo
-            if config is not None:
-                self.session.data['rebuild-infered'] = False
         elif connect:
             self.repo_connect()
+        # no config on shell to a remote instance
+        if config is not None:
+            self.session.data['rebuild-infered'] = False
+            self.repo.hm.call_hooks('server_maintenance', repo=self.repo)
         if not schema:
             schema = config.load_schema(expand_cubes=True)
         self.fs_schema = schema