#!/usr/bin/env python
"""
    %prog config_file

Description

    Run an image through a generic code. The config file is a yaml
    file with input/output files and other parameters needed for the run.

        required keys in config
            - 'run' The run id, just for identification

            - 'input_files', which is itself a dictionary.  The files will be
            checked to see if any files are in hdfs and if so these will be staged
            out.

            - 'output_files', a dictionary.  HDFS files will be first written
            locally and then pushed in.
                - This dict must contain an entry called 'stat' which will
                should be a .yaml file or .json file. It will contain the
                exit_status for the process and other metadata

            - 'command'.  This can refer to objects in the config file, including
            sub-objects of input_files and output_files.  Reference should be
            made using formats like %(name)s %(name)0.2f etc.

        Some optional fields

            - 'timeout': a timeout for the code in seconds.  Default two hours,
            2*60*60
"""

import sys
import deswl

from optparse import OptionParser
parser = OptionParser(__doc__)

options, args = parser.parse_args(sys.argv[1:])

if len(args) < 1:
    parser.print_help()
    sys.exit(1)

config_file=args[0]

with open(config_file) as fobj:
    import yaml
    conf=yaml.load(fobj)

with deswl.generic.GenericProcessor(conf) as gp:
    gp.run()
