#! /usr/bin/python

# Args: profile_file, indexing_pause (ms) = 0, notify_flag=0,
#       purge_old=1, update_stats=1

# notify_flag is set to 1 to receive progress reports on
# standard output (intended for use with client).  Set flag to 0
# for batch use.  Set flags purge_old and update_stats to 0
# for quick indexing mode.

# NOTE: this script will not work unless the Pathena definitions
# file ($PATHENA/{bin,config}/definitions) has been loaded to
# provide all necessary environment variables.

import os, sys, time

PATHENA = os.environ['PATHENA']

for dir in ('server', 'types', 'lib'):
    sys.path.insert(0, os.path.join(PATHENA, dir))

sys.stderr = open(os.path.join(PATHENA, 'log', 'index_err_log'), 'a')

print >> sys.stderr, \
      "\n======== Starting Pathena indexing job on %s. ========\n" % \
      time.asctime()

try:
    import index_files
    code = index_files.scan_and_index_files(*sys.argv[1:])
except SystemExit, code:
    pass
except Exception, exc_obj:
    print >> sys.stderr, \
          '*** Unhandled exception in indexing process:\n%s' % \
          ' ; '.join([ str(a) for a in exc_obj.args ])
    print >> sys.stderr, '\nSee file ~/.pathena/log/indexing_log for details.'
    code = 3

sys.exit(code)
