#!/usr/bin/env python

"""
Generates the fake DAG and Condor jobs for one exposure
"""
import sys
from ipp.FakeManager import FakeManager as FakeManager

#################################################################
if __name__ == '__main__':
    if len(sys.argv) != 4 and len(sys.argv) != 5:
        print 'generate_fake_jobs.py <stage> <label> <exposure_name>'
        print '  e.g.: generate_fake_jobs.py C010 MD08.jtrp o5806g0078o'
        print '  Acceptable value for <stage>: DAG, C010, C020, C030, C040, C050'
        sys.exit(1)
    STAGE = sys.argv[1]
    LABEL = sys.argv[2]
    EXPOSURE_NAME = sys.argv[3]
    if len(sys.argv) == 5:
        RECIPIENT = sys.argv[4]
    else:
        RECIPIENT = 'schastel@ifa.hawaii.edu'
    FAKE_MANAGER = FakeManager(LABEL, EXPOSURE_NAME, RECIPIENT)
    if STAGE == 'C010':
        FAKE_MANAGER.build_new_fake_jobs()
    elif STAGE == 'C020' or STAGE == 'C030' or STAGE == 'C040':
        FAKE_MANAGER.build_fake_revert_jobs(STAGE)
    elif STAGE == 'C050':
        FAKE_MANAGER.advance_fake()
    elif STAGE == 'DAG':
        DAG_NAME = FAKE_MANAGER.build_fake_dag()
        FAKE_MANAGER.build_new_fake_jobs()
        print 'DAG file generated now run:'
        print 'condor_submit_dag %s' % DAG_NAME
    else:
        print 'Stage [%s] not supported' % STAGE
        sys.exit(2)
    sys.exit(0)
