#
# -*- coding: utf-8 -*-

print "\nRebuild concept retrieval index files and grove db"

# suppress annoying future warnings for python 2.4
import warnings
warnings.filterwarnings('ignore', category=FutureWarning)


#-----------------------------------------------------------------------------------------------------------
#   Enable globals:
try:
    g
except NameError:
    import os.path as _p; import inspect as _i
    pathToScript = _p.pardir, 'lib', 'biocase', 'fundamentals.py'
    execfile( _p.join( _p.dirname( _i.getfile( lambda:None ) ), *pathToScript ) )

# Remove existing indexing file first
import shutil, os.path
lupyindex = os.path.join(_p.pardir,'configuration','persistence','lupyindex')
lockdir = os.path.join(_p.pardir,'configuration','persistence','x-datasourceFederatorLocks')
grovedir = os.path.join(_p.pardir,'configuration','persistence','Grove')
print "Remove grove lock files ..."
if os.path.isdir(lockdir):
    shutil.rmtree( lockdir )
os.makedirs( lockdir )
print "Remove old index files ..."
if os.path.isdir(lupyindex):
    shutil.rmtree( lupyindex )
os.makedirs( lupyindex )
# build grove db
print "Build Grove db ..."
if not os.path.isdir(grovedir):
    os.makedirs(grovedir)
g.configtool.utilities.makeDatabases.makeGrove.make()
