#!/usr/bin/env python

"""
Generates the complete stack stage DAG for one label
"""
import sys
from ipp.StackManager import StackManager as StackManager

#################################################################
if __name__ == '__main__':
    if len(sys.argv) != 4:
        print 'generate_stack_jobs.py <stage> <label> <recipient>'
        print '  e.g.: generate_stack_jobs.py E010 MD08.jtrp me@nospam.com'
        print '  Acceptable value for <stage>: DAG, E010-E060'
        sys.exit(1)
    STAGE = sys.argv[1]
    LABEL = sys.argv[2]
    RECIPIENT = sys.argv[3]
    STACK_QUERIER = StackManager(LABEL, RECIPIENT)
    if STAGE == 'E010':
        STACK_QUERIER.build_create_stack_entries_job()
    elif STAGE == 'E020':
        STACK_QUERIER.build_new_stack_jobs()
    elif STAGE == 'E030' or STAGE == 'E040' or STAGE == 'E050':
        STACK_QUERIER.build_revert_stack_jobs(STAGE)
    elif STAGE == 'E060':
        STACK_QUERIER.build_stack_summary_jobs()
    elif STAGE == 'DAG':
        DAG_NAME = STACK_QUERIER.build_dag()
        STACK_QUERIER.build_create_stack_entries_job()
        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)
