#!/usr/bin/python2.6
import pickle, pprint, getopt, sys, os

def main(argv):

    errors = 0
    warnings = 0
    database = 0

    modules = { 'lxml'      : [ 'required', 'SAX & DOM XML Processing' ],
                'yaml'      : [ 'required', 'Encode and decode YAML data forms.' ],
                'base64'    : [ 'required', 'Encode and decode Base64 data' ],
                'xlwt'      : [ 'optional', 'XLS<2007 write support' ],
                'xlrd'      : [ 'optional', 'XLS<2007 read support' ],
                'PIL'       : [ 'optional', 'Python Imaging Library' ],
                'paramiko'  : [ 'optional', 'SSH suppport.' ],
                'vobject'   : [ 'required', 'vCard and vEvent parsing' ],
                'coils.foundation.api.elementflow': \
			      [ 'required', 'Streaming XML Creation' ],
                'dateutil'  : [ 'required', 'Date & Time Arithmatic' ],
                'coils.foundation.api.pypdf': \
			      [ 'optional', 'Simple PDF Operations' ],
                'pytz'      : [ 'required', 'Python Time Zone tables' ],
                'informixdb': [ 'database', 'Informix RDBMS connectivity' ],
                'sqlalchemy': [ 'required', 'Object Relational Modeling' ],
                'yaml'      : [ 'required', 'YAML parser & serializer' ],
                'psycopg2'  : [ 'database', 'PostgreSQL RDBMS connectivity' ]
              }

    for module in modules:
        try:
            __import__(module)
        except:
            if (modules[module][0] == 'required'):
                errors = errors + 1
                print('ERR: Module {0} ({1}) not available.'.format(module, modules[module][1]))
            elif (modules[module][0] in ('optional', 'database')):
                warnings = warnings + 1
                print('WARN: Module {0} ({1}) not available.'.format(module, modules[module][1]))
        else:
            print('OK: Module {0} ({1}) available.'.format(module, modules[module][1]))
            if (modules[module][0] == 'database'):
                database = database + 1


    if (database == 0):
        print
        print(' * FATAL ERROR: No RDBMS connectivity available.             *')
        print(' *  You have no module which provides RDBMS connectivity;    *')
        print(' *  the SQLalchecmy ORM will not be able to function.        *')
        sys.exit(1)
    else:
        print
        print('{0} database connectivity modules found.'.format(database))
        print(' * Make sure the RDBMS you intend to use for the SQLalchemy  *')
        print(' * ORM is installed and operational.                         *')

    if (errors > 0):
        print
        print('{0} package errors found.'.format(errors))
        print(' * You are missing modules critical to the basic operation   *')
        print(' * of the OpenGroupware Coils service.  Address these errors *')
        print(' * prior to deploying the service.                           *')
        print
        sys.exit(1)

    if (warnings > 0):
        print
        print('{0} package warnings found.'.format(warnings))
        print(' * You are missing packages that extend the operation and    *')
        print(' * capacity of the OpenGroupware Coils service.  The service *')
        print(' * will provide core functionality but some features,        *')
        print(' * particularly in regard to OIE, may not be available. It   *')
        print(' * is recommended you install the appropriate packages.      *')

    if (warnings == 0 and errors == 0):
        print
        print(' * Your host has all the required modules to provide the     *')
        print(' * full capability of the OpenGroupware Coils servce.        *')

    print

if __name__ == "__main__":
    main(sys.argv[1:])
