Skip to content

Commit b235340

Browse files
authored
Merge pull request #1651 from UlrichB22/load_add_idx
CLI: add index build to load command
2 parents 1d0fd0a + e0eaefb commit b235340

File tree

10 files changed

+36
-20
lines changed

10 files changed

+36
-20
lines changed

docs/admin/backup.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,4 @@ To load the backup file into your empty wiki, run::
5252

5353
moin load --file backup.moin
5454

55-
Then build an index of the loaded data::
56-
57-
moin index-build
55+
The index is removed and automatically recreated by the load command.

docs/admin/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ If your wiki has data and is shut down
114114
If index needs a rebuild for some reason, e.g. index lost, index damaged,
115115
incompatible upgrade, etc., use::
116116

117+
moin index-destroy
117118
moin index-create
118119
moin index-build # can take a while...
119120

src/moin/cli/_tests/test_serialization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright: 2023 MoinMoin project
2+
# Copyright: 2024 MoinMoin:UlrichB
23
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
34

45
"""
@@ -28,8 +29,7 @@ def load(restore_dir, backup_name, artifact_dir, args=None):
2829
try:
2930
for command in (['moin', 'create-instance'],
3031
['moin', 'index-create'],
31-
['moin', 'load', '-f', getBackupPath(backup_name)] + (args if args else []),
32-
['moin', 'index-build']):
32+
['moin', 'load', '-f', getBackupPath(backup_name)] + (args if args else []),):
3333
p = run(command)
3434
assert_p_succcess(p)
3535
finally:

src/moin/cli/_util.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright: 2023 MoinMoin project
2+
# Copyright: 2024 MoinMoin:UlrichB
23
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
34

45
"""
@@ -32,3 +33,19 @@ def get_backends(backends: Optional[str], all_backends: bool) -> Set[Backend]:
3233
else:
3334
logging.warning('no backends specified')
3435
return set()
36+
37+
38+
def drop_and_recreate_index(indexer):
39+
"""Drop index and recreate, rebuild and optimize
40+
:param indexer: IndexingMiddleware object
41+
"""
42+
indexer.close()
43+
indexer.destroy()
44+
logging.debug("Create index")
45+
indexer.create()
46+
logging.debug("Rebuild index")
47+
indexer.rebuild()
48+
logging.debug("Optimize index")
49+
indexer.optimize_index()
50+
indexer.open()
51+
logging.info("Rebuild index finished")

src/moin/cli/maint/serialization.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright: 2011 MoinMoin:ThomasWaldmann
22
# Copyright: 2023 MoinMoin project
3+
# Copyright: 2024 MoinMoin:UlrichB
34
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
45

56
"""
@@ -14,7 +15,7 @@
1415

1516
from moin.storage.middleware.serialization import serialize, deserialize
1617
from moin.app import create_app
17-
from moin.cli._util import get_backends
18+
from moin.cli._util import get_backends, drop_and_recreate_index
1819

1920
from moin import log
2021
logging = log.getLogger(__name__)
@@ -82,4 +83,6 @@ def Deserialize(file=None, new_ns=None, old_ns=None, kill_ns=None):
8283
logging.info("Load backup started")
8384
with open_file(file, "rb") as f:
8485
deserialize(f, app.storage.backend, new_ns=new_ns, old_ns=old_ns, kill_ns=kill_ns)
85-
logging.info("Load Backup finished. You need to run index-build now.")
86+
logging.info("Rebuilding the index ...")
87+
drop_and_recreate_index(app.storage)
88+
logging.info("Load Backup finished.")

src/moin/cli/migration/moin19/import19.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .macros import PageList # noqa
3030

3131
from moin.app import create_app
32+
from moin.cli._util import drop_and_recreate_index
3233
from moin.constants.keys import * # noqa
3334
from moin.constants.contenttypes import CONTENTTYPE_USER, CHARSET19, CONTENTTYPE_MARKUP_OUT
3435
from moin.constants.itemtypes import ITEMTYPE_DEFAULT
@@ -241,15 +242,7 @@ def ImportMoin19(data_dir=None, markup_out=None, namespace=None):
241242
backend.store(meta, out)
242243

243244
logging.info("PHASE4: Rebuilding the index ...")
244-
indexer.close()
245-
indexer.destroy()
246-
logging.debug("Create index")
247-
indexer.create()
248-
logging.debug("Rebuild index")
249-
indexer.rebuild()
250-
logging.debug("Optimize index")
251-
indexer.optimize_index()
252-
indexer.open()
245+
drop_and_recreate_index(app.storage)
253246

254247
logging.info("Finished conversion!")
255248
if hasattr(conv_out, 'unknown_macro_list'):

src/moin/converters/_util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright: 2011 MoinMoin:ThomasWaldmann
2+
# Copyright: 2024 MoinMoin:UlrichB
23
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
34

45
"""
@@ -120,7 +121,7 @@ def add_lineno(self, elem):
120121
"""
121122
Add a custom attribute (data-lineno=nn) that will be used by Javascript to scroll edit textarea.
122123
"""
123-
if flaskg and flaskg.add_lineno_attr:
124+
if flaskg and getattr(flaskg, 'add_lineno_attr', False):
124125
if self.last_lineno != self.iter_content.lineno:
125126
# avoid adding same lineno to parent and multiple children or grand-children
126127
elem.attrib[html.data_lineno] = self.iter_content.lineno

src/moin/converters/docbook_in.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright: 2010 MoinMoin:ValentinJaniaut
2+
# Copyright: 2024 MoinMoin:UlrichB
23
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
34

45
"""
@@ -57,7 +58,7 @@ class XMLParser(ET.XMLParser):
5758
"""
5859
def _start_list(self, tag, attrib_in):
5960
elem = super(XMLParser, self)._start_list(tag, attrib_in)
60-
if flaskg and flaskg.add_lineno_attr:
61+
if flaskg and getattr(flaskg, 'add_lineno_attr', False):
6162
elem.attrib[html.data_lineno] = self._parser.CurrentLineNumber
6263
return elem
6364

src/moin/converters/markdown_in.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright: 2008-2010 MoinMoin:BastianBlank
22
# Copyright: 2012 MoinMoin:AndreasKloeckner
3+
# Copyright: 2024 MoinMoin:UlrichB
34
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
45

56
"""
@@ -599,7 +600,7 @@ def __call__(self, data, contenttype=None, arguments=None):
599600

600601
# }}} end Markdown 3.0.0 core.py convert method
601602

602-
add_lineno = bool(flaskg and flaskg.add_lineno_attr)
603+
add_lineno = bool(flaskg and getattr(flaskg, 'add_lineno_attr', False))
603604

604605
# run markdown post processors and convert from ElementTree to an EmeraldTree object
605606
converted = self.do_children(root, add_lineno=add_lineno)

src/moin/converters/rst_in.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright: 2004 Matthew Gilbert <gilbert AT voxmea DOT net>
33
# Copyright: 2004 Alexander Schremmer <alex AT alexanderweb DOT de>
44
# Copyright: 2010 MoinMoin:DmitryAndreev
5+
# Copyright: 2024 MoinMoin:UlrichB
56
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
67

78
"""
@@ -92,7 +93,7 @@ def unknown_departure(self, node):
9293
pass
9394

9495
def open_moin_page_node(self, mointree_element):
95-
if flaskg and flaskg.add_lineno_attr:
96+
if flaskg and getattr(flaskg, 'add_lineno_attr', False):
9697
# add data-lineno attribute for auto-scrolling edit textarea
9798
if self.last_lineno < self.current_lineno:
9899
mointree_element.attrib[html.data_lineno] = self.current_lineno

0 commit comments

Comments
 (0)