def main(args):
    '''Extract command line args, find scene directory & construct ledaps command line'''
    if len(args) == 2:
        scene = args[1]
        topDirs = os.environ['LT_SCENES'].split(
            ':')  #directories where scenes are stored
        scenePath = su.findDir(scene, topDirs)
    else:
        sys.exit(
            "Incorrect number of arguments. Input: [1]path_row \n\n Exiting Process."
        )

    #check that there are tar.gz files in scene folder
    for file in os.listdir(scenePath):
        if file.endswith(".tar.gz"):
            break
    else:
        sys.exit(
            "\nNo tar.gz files found in {0}.\nPlease verify images were downloaded correctly.\n\n Exiting Process."
            .format(scenePath))

    #compile terminal command & display
    jobId = "l" + scene[1:3] + scene[4:6]
    cmdout = "sh landsatPrepSubmit.sh -m 8 -n {0} -w 60 -p 12.5 -d -c 5 -s 4 {1}".format(
        jobId, scenePath)

    print "\n\nYour command line code:"
    print "\n-------------------------------------------------------------------------"
    print cmdout
    print "-------------------------------------------------------------------------"

    #ask user if they want to submit ledaps job
    cmdline = raw_input("Run Ledaps (y/n)?: ")

    while cmdline.lower() != "y" and cmdline.lower() != "n":
        print "Sorry, input not understood. Please enter 'y' or 'n'.\n\n"
        cmdline = raw_input("Run Ledaps (y/n)?: ")

    #make error_output_files dir before running ledaps script
    if cmdline.lower() == "y":
        errOutDir = os.path.join(scenePath, "error_output_files")  #
        if not os.path.exists(errOutDir):
            print "\nNew Directory Made: {0}".format(errOutDir)
            subprocess.call("mkdir {0}".format(errOutDir), shell=True)
        print "\n\nStarting LEDAPS script. Do NOT close this terminal!\n\n"
        subprocess.call(cmdout, shell=True)

    else:
        print "\nLEDAPS has not run. \n\n Exiting."
def main(args):
    """Extract command line args, make some error checks & call functions"""
    # check number of arguments
    if len(args) == 4:
        process = args[1].lower()
        scene = args[2]
    else:
        args_err = (
            "Incorrect number of arguments. \nprep_script.py inputs: "
            + "(1)process (2)path_row (3)sub_bool. \n\n Exiting Process."
        )
        sys.exit(args_err)

    # check 3rd input validity
    err3 = (
        "Invalid 3rd argument. Please enter 0 or 1. \n0=Write qsub file only &"
        + " do NOT submit job to cluster.\n1=Submit job now.\n\n Exiting Process."
    )
    try:
        subNow = int(args[3])
    except ValueError:
        sys.exit(err3)
    else:
        if subNow != 0 and subNow != 1:
            sys.exit(err3)

    # check 1st & 2nd inputs validity, then run create ProcessJob instance & run fillTemplatesAndSubmit
    if sceneUtils.validSceneNum(scene):
        topDirs = SCENES.split(":")  # directories where scenes are stored
        scenePath = sceneUtils.findDir(scene, topDirs)
        if scenePath:
            dirCheckGood = sceneUtils.validDirSetup(scenePath, scene)
            if dirCheckGood:
                myJob = ProcessJob(scene, scenePath)
                myJob.customize(process)  # 1st input is checked here
                if myJob.paramDicts:
                    fillTemplatesAndSubmit(myJob, subNow)
                else:
                    sys.exit("\n\n Exiting Process.")
            else:
                sys.exit("\n\n Exiting Process.")
        else:
            sys.exit("\n\n Exiting Process.")
    else:
        sys.exit("\n\n Exiting Process.")
def main(args):
    '''Extract command line args, find scene directory & construct ledaps command line'''
    if len(args) == 2:
        scene = args[1]    
        topDirs = LT_SCENES.split(':') #directories where scenes are stored
        scenePath = su.findDir(scene,topDirs)
    else:
        sys.exit("Incorrect number of arguments. Input: [1]path_row \n\n Exiting Process.")
    
    #check that there are tar.gz files in scene folder
    for file in os.listdir(scenePath):
        if file.endswith(".tar.gz"):
            break
    else:
        sys.exit("\nNo tar.gz files found in {0}.\nPlease verify images were downloaded correctly.\n\n Exiting Process.".format(scenePath))
    
    #compile terminal command & display        
    jobId = "l" + scene[1:3] + scene[4:6]
    cmdout = "sh landsatPrepSubmit.sh -m 8 -n {0} -w 60 -p 12.5 -d -c 5 -s 4 {1}".format(jobId,scenePath) 

    print "\n\nYour command line code:"
    print "\n-------------------------------------------------------------------------"
    print cmdout 
    print "-------------------------------------------------------------------------"
    
    #ask user if they want to submit ledaps job
    cmdline = raw_input("Run Ledaps (y/n)?: ")

    while cmdline.lower() != "y" and cmdline.lower() != "n":        
        print "Sorry, input not understood. Please enter 'y' or 'n'.\n\n"
        cmdline = raw_input("Run Ledaps (y/n)?: ")
    
    #make error_output_files dir before running ledaps script
    if cmdline.lower() == "y":    
        errOutDir = os.path.join(scenePath,"error_output_files") #
        if not os.path.exists(errOutDir):
            print "\nNew Directory Made: {0}".format(errOutDir)
            subprocess.call("mkdir {0}".format(errOutDir), shell=True)  
        print "\n\nStarting LEDAPS script. Do NOT close this terminal!\n\n"   
        subprocess.call(cmdout, shell=True)
        
    else:
        print "\nLEDAPS has not run. \n\n Exiting."
def main(args):
    '''Extract command line args, make some error checks & call functions'''
    #check number of arguments
    if len(args) == 4:
        process = args[1].lower()
        scene = args[2]
    else:
        args_err = "Incorrect number of arguments. \nprep_script.py inputs: " + \
        "(1)process (2)path_row (3)sub_bool. \n\n Exiting Process."
        sys.exit(args_err)
    
    #check 3rd input validity
    err3 = "Invalid 3rd argument. Please enter 0 or 1. \n0=Write qsub file only &" + \
    " do NOT submit job to cluster.\n1=Submit job now.\n\n Exiting Process."
    try:
        subNow = int(args[3])
    except ValueError:
        sys.exit(err3)
    else:
        if subNow !=0 and subNow!=1:
            sys.exit(err3)
    
    #check 1st & 2nd inputs validity, then run create ProcessJob instance & run fillTemplatesAndSubmit
    if sceneUtils.validSceneNum(scene):
        topDirs = SCENES.split(':') #directories where scenes are stored
        scenePath= sceneUtils.findDir(scene,topDirs)
        if scenePath:
            dirCheckGood = sceneUtils.validDirSetup(scenePath, scene)   
            if dirCheckGood:
                myJob = ProcessJob(scene, scenePath)
                myJob.customize(process) #1st input is checked here
                if myJob.paramDicts:
                    fillTemplatesAndSubmit(myJob, subNow)
                else:
                    sys.exit("\n\n Exiting Process.")
            else:
                sys.exit("\n\n Exiting Process.")
        else:
            sys.exit("\n\n Exiting Process.")
    else:
        sys.exit("\n\n Exiting Process.")