from __future__ import print_function
import os


################################################################

def update_output_filenames(inp_dict):
    spec_id       = inp_dict["spec_id"]
    key_list      = inp_dict.keys()
    out_file_list = []
    for key in key_list:
        if "out_file_" in key:
            key_val = inp_dict[key]
            key_val = generate_output_file_name(key_val,spec_id)
            inp_dict.update({key:key_val})
    return inp_dict

def generate_output_file_name(file_name_org,spec_id):
    if spec_id is None:
        file_name = file_name_org
    else:
        file_base,file_ext = (os.path.splitext(file_name_org))
        file_base_new      = file_base + "_" + spec_id
        file_name          = file_base_new + file_ext
    return file_name


################################################################
def get_subdirectory(directory,flag_only_dir_name="n"):
    sub_dir_list	 =	[x[0] for x in os.walk(directory)]

    if flag_only_dir_name == "y":
        sub_dir_list_new = []

        for sub_dir_name in sub_dir_list:
            sub_dir_list_new.append(sub_dir_name.replace(directory,""))

        return sub_dir_list_new[1:]

    else:
        return sub_dir_list[1:]

def MAKE_DIRECTORY(newpath):
    #newpath = base_path + "PYTHON_BACKUP/"
    if not os.path.exists(newpath): os.makedirs(newpath)

def REFORMAT_DIR_PATH(inp_str):
    if inp_str[-1] != "/":
        inp_str = inp_str + "/"
    return inp_str



