#!/usr/bin/python

'''dbcleanup - sagator's database cleaner

(c) 2008 Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
'''

__pychecker__ = 'unusednames=_ \
                 blacklist=StringIO \
                 maxreturns=20 maxlines=300 \
                 no-local no-argsused no-stringiter no-abstract no-isliteral \
                 no-stdlib no-callinit no-badexcept'

import getopt

# load config
try:
  from etc import *
except ImportError,err_str:
  if str(err_str)[-6:]=="etc":
    print "ERROR! Config file not found! Exiting now."
    sys.exit(1)
  else:
    raise

def usage():
    '''Show help.'''
    print "dbcleanup - sagator's database cleanup script"
    sys.exit(0)

if __name__ == '__main__':
  debug.set_logfile('-')
  debug.set_level(0)
  try:
    opts=['help', 'debug=']
    opts,files = getopt.gnu_getopt(sys.argv[1:],'',opts)
  except getopt.GetoptError,(msg,opt):
    print "Error:",msg
    sys.exit(1)

  for key,value in opts:
    if key=="--help":
      usage()
    elif key=="--debug":
      debug.set_level(int(value))
    else:
      print "Unrecognized parameter (%s)." % ('='.join([key,value]))
      sys.exit(1)

  safe.ROOT_PATH=CHROOT

  # walk throught CLEANUP items
  for key, values in CLEANUP.items():
    # for each scanner run cleaning
    for scanner in values:
      scanner.scanbuffer('', dict(dbc=key))
