mediagoblin-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GMG-Devel] [PATCH 38/83] Add gmg command to delete all indices.


From: Alon Levy
Subject: [GMG-Devel] [PATCH 38/83] Add gmg command to delete all indices.
Date: Tue, 25 Feb 2014 21:58:21 +0200

From: Praveen Kumar <address@hidden>

---
 mediagoblin/gmg_commands/__init__.py |  4 ++++
 mediagoblin/gmg_commands/search.py   | 13 +++++++++++++
 mediagoblin/plugins/search/utils.py  | 24 ++++++++++++++++++++++++
 3 files changed, 41 insertions(+)
 create mode 100644 mediagoblin/gmg_commands/search.py
 create mode 100644 mediagoblin/plugins/search/utils.py

diff --git a/mediagoblin/gmg_commands/__init__.py 
b/mediagoblin/gmg_commands/__init__.py
index a1eb599..c082e52 100644
--- a/mediagoblin/gmg_commands/__init__.py
+++ b/mediagoblin/gmg_commands/__init__.py
@@ -53,6 +53,10 @@ SUBCOMMAND_MAP = {
         'setup': 'mediagoblin.gmg_commands.addmedia:parser_setup',
         'func': 'mediagoblin.gmg_commands.addmedia:addmedia',
         'help': 'Reprocess media entries'},
+    'delete_all_indices': {
+        'setup': 'mediagoblin.gmg_commands.search:search_parser_setup',
+        'func': 'mediagoblin.gmg_commands.search:delete_all_indices',
+        'help': 'Delete all existing indices'},
     # 'theme': {
     #     'setup': 'mediagoblin.gmg_commands.theme:theme_parser_setup',
     #     'func': 'mediagoblin.gmg_commands.theme:theme',
diff --git a/mediagoblin/gmg_commands/search.py 
b/mediagoblin/gmg_commands/search.py
new file mode 100644
index 0000000..5ed4de1
--- /dev/null
+++ b/mediagoblin/gmg_commands/search.py
@@ -0,0 +1,13 @@
+import logging
+
+from mediagoblin.plugins.search import utils
+
+_log = logging.getLogger(__name__)
+
+
+def search_parser_setup(subparser):
+    pass
+
+def delete_all_indices(args):
+    _log.info("Deleting indices...")
+    utils.delete_all_indices()
diff --git a/mediagoblin/plugins/search/utils.py 
b/mediagoblin/plugins/search/utils.py
new file mode 100644
index 0000000..761ba58
--- /dev/null
+++ b/mediagoblin/plugins/search/utils.py
@@ -0,0 +1,24 @@
+import logging
+import shutil
+
+from subprocess import call
+
+from mediagoblin.plugins import search
+
+
+_log = logging.getLogger(__name__)
+
+
+def delete_all_indices():
+    all_indices = search.registry.IndexRegistry.indices()
+
+    for index in all_indices.itervalues():
+        index_dir = index.search_index_dir
+        call(['rm -r %s'%(index_dir)], shell=True)
+        _log.info("Deleting index for %s stored in %s"%(
+            index.model.__class__.__name__, index_dir)) 
+
+
+def create_all_indices():
+    search.register_indices()
+
-- 
1.8.5.3



reply via email to

[Prev in Thread] Current Thread [Next in Thread]