Returns valid template file, generating the default template file if it doesn't exist and one wasn't
     specified on command line.

    :param args: Argument collection as generated by parseargs
    :return file

def get_template_file(args):
    """Returns valid template file, generating the default template file if it doesn't exist and one wasn't
     specified on command line.

    :param args: Argument collection as generated by parseargs
    :return file"""
    if args.template is None:
        template_filename  = os.getenv("HOME") + "/.mvmany.template"
        try:
            template_filename = open(template_filename, "r")
        except:
            with open(template_filename, "w") as file:
                print >> file, """#SBATCH --job-name=$jobname
#SBATCH --nodes=1
#SBATCH --tasks-per-node=1
#SBATCH --cpus-per-task=1
#SBATCH --mem=$memory
#SBATCH --time=$walltime
#SBATCH --error $logpath/$jobname.e
#SBATCH --output $respath/$jobname.txt

cd $pwd

$body
    """
            print >> sys.stderr, """PLEASE NOTE: \n
A default template file, %s, has been created. You are encouraged to configure it according to work with your cluster
management software or personalize it with email notifications, etc.\n"""
            template_filename = open(template_filename, "r")

    return template_filename