#!/usr/bin/python2.6
#
# Copyright (c) 2012 Adam Tauno Williams <awilliam@whitemice.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
from coils.core  import *
from coils.logic.workflow  import ActionMapper

def main(argv):

    initialize_tool('list-actions', argv)

    add_modules = [ ]
    ban_modules = [ ]    

    try:
        opts, args = getopt.getopt(argv,
                                   "hi:x:",
                                   [ "help", 
                                     "add-bundle=", 
                                     "ban-bundle=" ] )
    except getopt.GetoptError, e:
        print e
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit(0)
        elif opt in ("-i", "--add-bundle"):
            add_modules.append(arg)
        elif opt in ("-x", "--ban-bundle"):
            ban_modules.append(arg)
            
    entities = [ 'Contact', 'Enterprise', 'Task', 'Project', 'File', 
                 'Folder', 'Resource', 'Appointment', 'Note' ]        

    initialize_COILS( { 'extra_modules':  add_modules,
                        'banned_modules': ban_modules } )
                        
    ctx = AdministrativeContext()
    
    for kind in entities:
        print('{0}:'.format(kind))
        plugins = BundleManager.get_content_plugins(kind, ctx)
        if plugins:
            for plugin in plugins:
                print('  {0}'.format(plugin))
        else:
            print('  none')


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