1
1
# Copyright: 2011 MoinMoin:MichaelMayorov
2
- # Copyright: 2023 MoinMoin project
2
+ # Copyright: 2023-2024 MoinMoin:UlrichB
3
3
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
4
4
5
5
"""
14
14
15
15
from moin .app import create_app , init_backends
16
16
from moin .constants .keys import LATEST_REVS , ALL_REVS
17
+ from moin .utils .filesys import wiki_index_exists
18
+
17
19
18
20
from moin import log
19
21
20
22
logging = log .getLogger (__name__ )
21
23
24
+ ERR_NO_INDEX = "Error: Wiki index does not exist."
22
25
23
26
@click .group (cls = FlaskGroup , create_app = create_app )
24
27
def cli ():
@@ -35,25 +38,31 @@ def cli_IndexCreate(tmp, index_create, storage_create):
35
38
logging .info ("options -i or --index-create are obsolete and will be ignored" )
36
39
if storage_create :
37
40
logging .info ("options -s or --storage-create are obsolete and will be ignored" )
38
- logging .info ("Index creation started" )
39
41
return IndexCreate (tmp = tmp )
40
42
41
43
42
44
def IndexCreate (** kwargs ):
43
45
"""
44
46
Create empty indexes
45
47
"""
48
+ if wiki_index_exists ():
49
+ logging .error ("Error: wiki index exists. Please check and destroy index before running index-create" )
50
+ return False
46
51
logging .info ("Index creation started" )
47
52
init_backends (app , create_backend = True )
48
53
tmp = kwargs .get ('tmp' )
49
54
app .storage .create (tmp = tmp )
50
55
logging .info ("Index creation finished" )
56
+ return True
51
57
52
58
53
59
@cli .command ('index-destroy' , help = 'Destroy the indexes' )
54
60
@click .option ('--tmp' , is_flag = True , required = False , default = False ,
55
61
help = 'use the temporary location.' )
56
62
def IndexDestroy (tmp ):
63
+ if not wiki_index_exists ():
64
+ logging .error (ERR_NO_INDEX )
65
+ raise SystemExit (1 )
57
66
logging .info ("Index destroy started" )
58
67
app .storage .destroy (tmp = tmp )
59
68
logging .info ("Index destroy finished" )
@@ -68,6 +77,9 @@ def IndexDestroy(tmp):
68
77
@click .option ('--index-create' , '-i' , is_flag = True , required = False , default = False )
69
78
@click .option ('--storage-create' , '-s' , is_flag = True , required = False , default = False )
70
79
def IndexBuild (tmp , procs , limitmb , ** kwargs ):
80
+ if not wiki_index_exists ():
81
+ logging .error ("{} Run 'moin index-create' first." .format (ERR_NO_INDEX ))
82
+ raise SystemExit (1 )
71
83
logging .info ("Index build started" )
72
84
flaskg .add_lineno_attr = False # no need to add lineno attributes while building indexes
73
85
app .storage .rebuild (tmp = tmp , procs = procs , limitmb = limitmb )
@@ -77,6 +89,9 @@ def IndexBuild(tmp, procs, limitmb, **kwargs):
77
89
@cli .command ('index-update' , help = 'Update the indexes' )
78
90
@click .option ('--tmp' , is_flag = True , required = False , default = False , help = 'use the temporary location.' )
79
91
def IndexUpdate (tmp ):
92
+ if not wiki_index_exists ():
93
+ logging .error (ERR_NO_INDEX )
94
+ raise SystemExit (1 )
80
95
logging .info ("Index update started" )
81
96
app .storage .update (tmp = tmp )
82
97
logging .info ("Index update started" )
@@ -99,6 +114,9 @@ def IndexOptimize(tmp):
99
114
"""
100
115
Optimize the indexes
101
116
"""
117
+ if not wiki_index_exists ():
118
+ logging .error (ERR_NO_INDEX )
119
+ raise SystemExit (1 )
102
120
logging .info ("Index optimization started" )
103
121
app .storage .optimize_index (tmp = tmp )
104
122
logging .info ("Index optimization finished" )
@@ -108,6 +126,9 @@ def IndexOptimize(tmp):
108
126
@click .option ('--tmp' , is_flag = True , required = False , default = False , help = 'use the temporary location.' )
109
127
@click .option ('--truncate/--no-truncate' , default = True , help = 'truncate long entries' )
110
128
def IndexDump (tmp , truncate ):
129
+ if not wiki_index_exists ():
130
+ logging .error (ERR_NO_INDEX )
131
+ raise SystemExit (1 )
111
132
logging .info ("Index dump started" )
112
133
for idx_name in [LATEST_REVS , ALL_REVS ]:
113
134
print (" {0} {1} {2}" .format ("-" * 10 , idx_name , "-" * 60 ))
0 commit comments