#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# reclass — recursive external node classifier
#
# Copyright © 2007–13 martin f. krafft <madduck@madduck.net>
# Released under the terms of the Artistic Licence 2.0
#
__prog__ = 'reclass'
__description__ = 'classify nodes based on an external data source'
__version__ = '1.0'
__author__ = 'martin f. krafft <madduck@madduck.net>'
__copyright__ = 'Copyright © 2007–13 ' + __author__
__licence__ = 'Artistic Licence 2.0'

import sys, os, posix, time
import config
from output import OutputLoader
from storage import StorageBackendLoader

def get_options(config_file=None):
    return config.get_options(__name__, __version__, __description__, config_file)

def get_data(storage_type, nodes_uri, classes_uri, node):
    storage_class = StorageBackendLoader(storage_type).load()
    storage = storage_class(os.path.abspath(os.path.expanduser(nodes_uri)),
                            os.path.abspath(os.path.expanduser(classes_uri)))
    if node is False:
        ret = storage.inventory()
    else:
        ret = storage.nodeinfo(node)
        ret['RECLASS']['timestamp'] = time.strftime('%c')

    return ret

def output(data, fmt, pretty_print=False):
    output_class = OutputLoader(fmt).load()
    outputter = output_class()
    return outputter.dump(data, pretty_print=pretty_print)

if __name__ == '__main__':
    __name__ = __prog__
    config_file = None
    for d in (os.getcwd(), os.path.dirname(sys.argv[0])):
        f = os.path.join(d, __name__ + '-config.yml')
        if os.access(f, os.R_OK):
            config_file = f
            break
    options = get_options(config_file)
    data = get_data(options.storage_type, options.nodes_uri,
                    options.classes_uri, options.node)
    print output(data, options.output, options.pretty_print)
    sys.exit(posix.EX_OK)
