Commits

Thomas Waldmann committed c9a78e5

fix script startup deadlock, add script params to create storage and index, fix fs store

To build an index, use this:
moin index-build -s -i
moin index-build --storage-create --index-create

Usually moin would expect an existing index and storage when starting up
and fail if it is not there. This is a problem for moin index-* commands,
which are used to build an index.

By giving -s, you force it to create the storage where specified by the config.
By giving -i, you force it to create the index where specified by the config.

fs storage used os.mkdir. use os.makedirs to support multiple levels of dirs
getting create. catch exception if the dir is already there.

Comments (0)

Files changed (5)

 from MoinMoin.util.clock import Clock
 
 
-def create_app(config=None):
+def create_app(config=None, create_index=False, create_storage=False):
     """
     simple wrapper around create_app_ext() for flask-script
     """
-    return create_app_ext(flask_config_file=config)
+    return create_app_ext(flask_config_file=config,
+                          create_index=create_index,
+                          create_storage=create_storage)
 
 
 def create_app_ext(flask_config_file=None, flask_config_dict=None,
         app.router.create()
     app.router.open()
     app.storage = indexing.IndexingMiddleware(app.cfg.index_dir, app.router, wiki_name=app.cfg.interwikiname) # XXX give user name etc.
-    if app.cfg.create_storage:
+    if app.cfg.create_index:
         app.storage.create()
     app.storage.open()
 
 def deinit_backends(app):
     app.storage.close()
     app.router.close()
+    if app.cfg.destroy_index:
+        app.storage.destroy()
     if app.cfg.destroy_storage:
-        app.storage.destroy()
         app.router.destroy()
 
 

MoinMoin/config/default.py

     "This needs to point to a list of tuples, each tuple containing: name prefix, acl protection to be applied to matching items. " + \
     "E.g.: [('', dict(default='All:read,write,create')), ]. Please see HelpOnStorageConfiguration for further reference."),
     ('create_storage', False, "Create (initialize) the storage backends before trying to use them."),
+    ('create_index', False, "Create (initialize) the index before trying to use them."),
     ('destroy_storage', False, "Destroy (empty) the storage backends after using them."),
+    ('destroy_index', False, "Destroy (empty) the index after using it."),
   )),
   # ==========================================================================
   'items': ('Special item names', None, (

MoinMoin/script/__init__.py

 
     manager = Manager(create_app)
     manager.add_option('-c', '--config', dest='config', required=False, default=wiki_config)
+    manager.add_option('-i', '--index-create', action='store_true', dest='create_index', required=False, default=False)
+    manager.add_option('-s', '--storage-create', action='store_true', dest='create_storage', required=False, default=False)
     manager.add_command("moin", Server(host='127.0.0.1', port=8080))
 
     from MoinMoin.script.maint import index

MoinMoin/script/maint/index.py

     ]
 
     def run(self, tmp):
-        unprotected_storage = flaskg.unprotected_storage = app.unprotected_storage
-        unprotected_storage.create(tmp=tmp)
+        app.storage.create(tmp=tmp)
 
 
 class IndexDestroy(Command):
     ]
 
     def run(self, tmp):
-        unprotected_storage = flaskg.unprotected_storage = app.unprotected_storage
-        unprotected_storage.destroy(tmp=tmp)
+        app.storage.destroy(tmp=tmp)
 
 
 class IndexBuild(Command):
     ]
 
     def run(self, tmp, procs, limitmb):
-        unprotected_storage = flaskg.unprotected_storage = app.unprotected_storage
-        unprotected_storage.rebuild(tmp=tmp, procs=procs, limitmb=limitmb)
+        app.storage.rebuild(tmp=tmp, procs=procs, limitmb=limitmb)
 
 
 class IndexUpdate(Command):
     ]
 
     def run(self, tmp):
-        unprotected_storage = flaskg.unprotected_storage = app.unprotected_storage
-        unprotected_storage.update(tmp=tmp)
+        app.storage.update(tmp=tmp)
 
 
 class IndexMove(Command):
     ]
 
     def run(self):
-        unprotected_storage = flaskg.unprotected_storage = app.unprotected_storage
-        unprotected_storage.move_index()
+        app.storage.move_index()
 
 
 class IndexOptimize(Command):
     ]
 
     def run(self, tmp):
-        unprotected_storage = flaskg.unprotected_storage = app.unprotected_storage
-        unprotected_storage.optimize_index(tmp=tmp)
+        app.storage.optimize_index(tmp=tmp)
 

MoinMoin/storage/stores/fs.py

         self.path = path
 
     def create(self):
-        os.mkdir(self.path)
+        try:
+            os.makedirs(self.path)
+        except OSError as e:
+            if e.errno != errno.EEXIST:
+                raise
 
     def destroy(self):
         shutil.rmtree(self.path)