コード例 #1
0
ファイル: sub_gene_comm.py プロジェクト: cloudtrends/godroid
def check_is_go_file_have_meta_flag(file_path):
    contents_list = comm_funcs.get_file_content_as_list(file_path)
    if contents_list[0].startswith("package "):
        pass
    else:
        comm_funcs.print_error("PYTHON ERROR: " + file_path + " no package ! ")
        sys.exit(1)
    if contents_list[2].startswith(GoTemplateMagicSecondLine):
        pass
    else:
        comm_funcs.print_error("PYTHON ERROR: " + file_path +
                               " no MagicSecondLine ! ")
        sys.exit(1)
    if is_go_file_has_auto_part(contents_list):
        pass
    else:
        comm_funcs.print_error("PYTHON ERROR: " + file_path +
                               " no auto part ! ")
        sys.exit(1)
    if is_go_file_has_custom_part(contents_list):
        pass
    else:
        comm_funcs.print_error("PYTHON ERROR: " + file_path +
                               " no custom part ! ")
        sys.exit(1)
    return True
コード例 #2
0
def generate_apiwebmodule_show_file(profile_instance, model_domain):
    """
    apiwebmodule

    """
    print_ok("begin save to apiwebmodule")
    FullPathApiWebModuleFile = godroid_helper.get_apiwebmodule_file_name_full_path(
        profile_instance, model_domain)
    contents_list = comm_funcs.get_file_content_as_list(
        FullPathApiWebModuleFile)
    part_one = __self_call_get_package(contents_list)

    #---- begin
    part_begin = sub_gene_comm.GoTemplateAutoPartBegin

    part_package_import = ____self_call_get_imports(profile_instance,
                                                    model_domain)

    part_curd = ____self_call_get_curds(profile_instance, model_domain)

    part_end = sub_gene_comm.GoTemplateAutoPartEnd
    #---- end

    part_auto_full = part_begin + "\n" + part_package_import + "\n" + part_curd + "\n" + part_end

    part_custom = __self_call_get_custom_part(contents_list)
    all_file_conent = part_one + "\n" + part_auto_full + "\n" + part_custom

    sub_gene_comm.backup_go_file_in_curr_dir_and_touch_new_one(
        FullPathApiWebModuleFile)
    comm_funcs.add_to_exist_file(FullPathApiWebModuleFile, all_file_conent)

    pass
コード例 #3
0
def generate_api_file(profile_instance, model_domain):
    """
    first , save contents which outside of meta flag
    then , generate new content 
    third , combine them and generate new file
    """
    FullPathApiFile = godroid_helper.get_api_file_name_full_path(
        profile_instance, model_domain)
    contents_list = comm_funcs.get_file_content_as_list(FullPathApiFile)
    part_one = __self_call_get_package(contents_list)

    comm_funcs.print_ok("api part one:" + part_one)

    part_begin = sub_gene_comm.GoTemplateAutoPartBegin
    part_two = __self_call_get_stands_methods(profile_instance, model_domain)
    #()
    part_three = ""
    #(profile_instance, model_domain)
    part_four = ""
    part_five = ""

    part_end = sub_gene_comm.GoTemplateAutoPartEnd

    part_six = __self_call_get_custom_part(contents_list)
    all_file_conent = part_one + "\n" + part_begin + "\n" + part_two + "\n" + part_three + "\n" + part_four + "\n" + part_five + "\n" + part_end + "\n" + part_six
    sub_gene_comm.backup_go_file_in_curr_dir_and_touch_new_one(FullPathApiFile)
    comm_funcs.print_ok("begin save to api:" + FullPathApiFile)
    comm_funcs.add_to_exist_file(FullPathApiFile, all_file_conent)
    pass
コード例 #4
0
def generate_revelcurdfuncs_show_file(profile_instance, model_domain):
    """
    revelcurdfuncs
    """
    print_ok("begin save to revelcurdfuncs")
    FullPathRevelCurdFuncsFile = godroid_helper.get_revelcurdfuncs_file_name_full_path(
        profile_instance, model_domain)
    contents_list = comm_funcs.get_file_content_as_list(
        FullPathRevelCurdFuncsFile)
    part_one = __self_call_get_package(contents_list)

    #---- begin
    part_begin = sub_gene_comm.GoTemplateAutoPartBegin

    part_package_import = ____self_call_get_imports(profile_instance,
                                                    model_domain)

    part_curd = ____self_call_get_curds(profile_instance, model_domain)

    part_end = sub_gene_comm.GoTemplateAutoPartEnd
    #---- end

    part_auto_full = part_begin + "\n" + part_package_import + "\n" + part_curd + "\n" + part_end

    part_custom = __self_call_get_custom_part(contents_list)
    part_custom = part_custom.replace("CLASSNAME", profile_instance.ClassName)

    all_file_conent = part_one + "\n" + part_auto_full + "\n" + part_custom

    sub_gene_comm.backup_go_file_in_curr_dir_and_touch_new_one(
        FullPathRevelCurdFuncsFile)
    comm_funcs.add_to_exist_file(FullPathRevelCurdFuncsFile, all_file_conent)
コード例 #5
0
def generate_controller_show_file(profile_instance, model_domain):
    comm_funcs.print_ok("begin save to controllers")

    FullPathControllerFile = godroid_helper.get_controller_file_name_full_path(
        profile_instance, model_domain)

    contents_list = comm_funcs.get_file_content_as_list(FullPathControllerFile)

    part_one = __self_call_get_package(contents_list)
    comm_funcs.print_ok("controller part one:" + part_one)
    #---- begin
    part_begin = sub_gene_comm.GoTemplateAutoPartBegin

    part_package_import = __self_call_get_packages_part(
        profile_instance, model_domain)

    part_curd = __self_call_get_CURD_part(profile_instance, model_domain)

    part_auto_empty_test = __self_call_get_auto_empty_test_part(
        profile_instance, model_domain)

    part_end = sub_gene_comm.GoTemplateAutoPartEnd
    #---- end

    part_auto_full = part_begin + "\n" + part_package_import + "\n" + part_curd + "\n" + part_auto_empty_test + "\n" + part_end

    part_custom = __self_call_get_custom_part(contents_list)
    all_file_conent = part_one + "\n" + part_auto_full + "\n" + part_custom
    sub_gene_comm.backup_go_file_in_curr_dir_and_touch_new_one(
        FullPathControllerFile)
    comm_funcs.add_to_exist_file(FullPathControllerFile, all_file_conent)

    pass
コード例 #6
0
def check_routes_file_valid(routes_file_name):
    """

    """
    contents = comm_funcs.get_file_content_as_list(routes_file_name)
    self_header_flag = False
    self_header_end_flag = False

    common_part_flag = False
    common_part_end_flag = False

    self_part_flag = False
    self_part_end_flag = False
    for line in contents:
        if line.startswith(SelfHeader):
            self_header_flag = True
        if line.startswith(SelfHeaderEnd):
            self_header_end_flag = True
        if line.startswith(CommonPart):
            common_part_flag = True
        if line.startswith(CommonPartEnd):
            common_part_end_flag = True
        if line.startswith(SelfPart):
            self_part_flag = True
        if line.startswith(SelfPartEnd):
            self_part_end_flag = True
    if self_header_flag and self_header_end_flag and common_part_flag and common_part_end_flag and self_part_flag and self_part_end_flag:
        return True
    return False
コード例 #7
0
def check_routes_file_valid( routes_file_name ):
    """

    """
    contents = comm_funcs.get_file_content_as_list( routes_file_name )
    self_header_flag = False
    self_header_end_flag = False

    common_part_flag = False
    common_part_end_flag = False

    self_part_flag = False
    self_part_end_flag = False
    for line in contents:
        if line.startswith( SelfHeader ):
            self_header_flag = True
        if line.startswith( SelfHeaderEnd ):
            self_header_end_flag = True
        if line.startswith( CommonPart ):
            common_part_flag = True
        if line.startswith( CommonPartEnd ):
            common_part_end_flag = True
        if line.startswith( SelfPart ):
            self_part_flag = True
        if line.startswith( SelfPartEnd ):
            self_part_end_flag = True
    if self_header_flag and self_header_end_flag and common_part_flag and common_part_end_flag and self_part_flag and self_part_end_flag:
        return True
    return False
コード例 #8
0
def generate_funcs_of_gorp_file(profile_instance, model_domain):
    FullPathFuncsOfGorpFile = godroid_helper.get_model_funcs_of_gorp_file_name_full_path(
        profile_instance, model_domain)
    contents_list = comm_funcs.get_file_content_as_list(
        FullPathFuncsOfGorpFile)
    part_one = __self_call_get_package(contents_list)
    comm_funcs.print_ok("gorp funcs part one:" + part_one)
    #
    part_begin = sub_gene_comm.GoTemplateAutoPartBegin
    #
    part_two = __self_call_get_import(contents_list, profile_instance,
                                      model_domain)
    part_three = __self_call_get_class_def(contents_list, profile_instance)
    part_four = __self_call_get_func_for_sql_tri_pairs(contents_list,
                                                       profile_instance)
    part_five = __self_call_get_gorp_map(contents_list, profile_instance)
    #
    part_end = sub_gene_comm.GoTemplateAutoPartEnd
    #
    part_six = __self_call_get_custom_part(contents_list)
    all_file_conent = part_one + "\n" + part_begin + "\n" + part_two + "\n" + part_three + "\n" + part_four + "\n" + part_five + "\n" + part_end + "\n" + part_six
    sub_gene_comm.backup_go_file_in_curr_dir_and_touch_new_one(
        FullPathFuncsOfGorpFile)
    comm_funcs.print_ok("begin save to gorp:" + FullPathFuncsOfGorpFile)
    comm_funcs.add_to_exist_file(FullPathFuncsOfGorpFile, all_file_conent)
    pass
コード例 #9
0
ファイル: godroid_helper.py プロジェクト: cloudtrends/godroid
def walk_dir_add_magic_tag_to_files(some_path, pattern = '*.go'):
    for root, dirs, files in os.walk(some_path):
        for filename in fnmatch.filter(files, pattern):
            if filename.startswith("."):
                print_error("invalid:" + one_filename )
                continue
            #check magic tag
            #if yes , continue
            #else read content then add tag 
            #backup original file and create new file
            file_path =  os.path.join(root, filename)
            if sub_gene_comm.check_is_go_file_have_meta_flag( file_path ):
                continue
            all_file_conent = ""
            contents_list = comm_funcs.get_file_content_as_list( file_path )
            all_original_code = ""
            line_num = 0
            for line in contents_list:
                if 0 == line_num:
                    line_num = line_num + 1
                    continue
                line_num = line_num + 1
                all_original_code = all_original_code + line
            all_file_conent = all_file_conent + contents_list[0] + "\n" 
            # add empty line
            all_file_conent = all_file_conent + "\n" 
            all_file_conent = all_file_conent + GoTemplateMagicSecondLine  + "\n"
            all_file_conent = all_file_conent + GoTemplateAutoPartBegin + "\n"
            all_file_conent = all_file_conent + GoTemplateAutoPartEnd  + "\n" 
            all_file_conent = all_file_conent + GoTemplateCustomPartBegin  + "\n"
            all_file_conent =  all_file_conent + all_original_code
            all_file_conent = all_file_conent + GoTemplateCustomPartEnd  + "\n"
            sub_gene_comm.backup_go_file_in_curr_dir_and_touch_new_one( file_path )
            comm_funcs.add_to_exist_file( file_path  , all_file_conent  )
コード例 #10
0
ファイル: godroid_helper.py プロジェクト: cloudtrends/godroid
def check_instance_profile(  instance_profile_path = None ):
    """
    """
    log("begin check_instance_profile :" + instance_profile_path )
    contents_list = comm_funcs.get_file_content_as_list(instance_profile_path)
    if __check_instance_profile_items_exists(contents_list):
        pass
    if __check_instance_profile_class_name(contents_list):
        pass
    if __check_instance_profile_columns(contents_list):
        pass
    return True
コード例 #11
0
ファイル: sub_gene_class.py プロジェクト: cloudtrends/godroid
def generate_model_class_file(profile_instance, model_domain):
    FullPathModelFile = godroid_helper.get_model_class_file_name_full_path(profile_instance, model_domain)
    contents_list = comm_funcs.get_file_content_as_list( FullPathModelFile )
    part_one = __self_call_get_package(contents_list)
    comm_funcs.print_ok( "class part one:" + part_one )
    #---- begin
    part_begin = sub_gene_comm.GoTemplateAutoPartBegin
    part_two = __self_call_get_table_name_const(contents_list, profile_instance)
    part_three = __self_call_get_class(profile_instance)
    part_four = __self_call_get_GetColumnsMap(profile_instance)
    part_five = __self_call_get_GetGorpRenameMap(profile_instance)
    part_end = sub_gene_comm.GoTemplateAutoPartEnd
    #---- end 
    part_six  = __self_call_get_custom_part(contents_list)
    all_file_conent = part_one + "\n" + part_begin + "\n" + part_two + "\n" + part_three + "\n" + part_four + "\n" + part_five + "\n" + part_end + "\n" + part_six
    sub_gene_comm.backup_go_file_in_curr_dir_and_touch_new_one( FullPathModelFile )
    comm_funcs.add_to_exist_file( FullPathModelFile  , all_file_conent  )
    pass
コード例 #12
0
def __extract_route_one_part(  routes_file_name , begin_part , end_part ):
    contents = comm_funcs.get_file_content_as_list( routes_file_name )
    record_begin = False
    return_lines = ""
    return_lines = return_lines + begin_part + "\n"
    for line in contents:
        if line.startswith( begin_part ):
            record_begin = True
            continue
        if line.startswith( end_part ):
            record_begin = False
            break
        line = line.strip()
        if 0 == len(line):
            continue
        if record_begin:
            return_lines = return_lines + line + "\n"
    return_lines = return_lines + end_part + "\n"
    return return_lines
コード例 #13
0
def __extract_route_one_part(routes_file_name, begin_part, end_part):
    contents = comm_funcs.get_file_content_as_list(routes_file_name)
    record_begin = False
    return_lines = ""
    return_lines = return_lines + begin_part + "\n"
    for line in contents:
        if line.startswith(begin_part):
            record_begin = True
            continue
        if line.startswith(end_part):
            record_begin = False
            break
        line = line.strip()
        if 0 == len(line):
            continue
        if record_begin:
            return_lines = return_lines + line + "\n"
    return_lines = return_lines + end_part + "\n"
    return return_lines
コード例 #14
0
sys.path.append(os.getcwd())
import subprocess
import shutil
import comm_funcs

import sub_gene_class, sub_gene_funcs_gorp, sub_gene_api, sub_gene_comm, godroid_helper
from docopt import docopt



if "__main__" == __name__:
    arguments = docopt(__doc__, version='0.1.1rc')
    print_ok(arguments)
    comm_funcs.print_ok("begin generate cfg ... ")
    """
    generate the cfg files
    """
    tmplt_name = "zhaopin_person_basic.tmplt"
    bb = "cfg_templates"

    json_content = comm_funcs.get_file_content_as_list( tmplt_name )
    gopath = comm_funcs.check_and_get_go_path()
    #ClassCfgTemplate
    #ClassColumnCfgTemplateProfile
    sub_gene_comm.check_model_profile_exist()
    

"""
"""

コード例 #15
0
import time





if __name__ == "__main__":
    """
    """
    if 1 == len(sys.argv):
        comm_funcs.print_error(" push or pull ?")
        sys.exit(1)
    push_or_pull = sys.argv[1]
    if push_or_pull not in "push pull":
        comm_funcs.print_error(" what your input is not match push or pull ")
        sys.exit(1)
    gopath = comm_funcs.get_gopath()
    if gopath is None or 0 == len(gopath):
        comm_funcs.print_error("ERROR: evn path not set , prod mod")
        sys.exit(1)
    auto_gitpush_projs = comm_funcs.get_file_content_as_list(gopath + "/" + "auto_gitpush_projs.txt")
    for one in auto_gitpush_projs:
        one = one.strip()
        if 0 == len(one):
            continue
        comm_funcs.print_ok(" relative path :" + one )
        full_path = "./test_auto_gitpush.sh " + gopath + "/" + one + " " + push_or_pull
        comm_funcs.print_ok("full path:"+full_path)
        os.system( full_path )

コード例 #16
0
 """
 if 3 != len(sys.argv):
     comm_funcs.print_error(" arguments : app_type and instance_name  need assigned ")
     comm_funcs.print_error(  "ERROR EXIT PYTHON" )
     sys.exit(1)
 gopath = comm_funcs.get_gopath()
 if gopath is None or 0 == len(gopath):
     comm_funcs.print_error("ERROR: evn path not set , prod mod")
     sys.exit(1)
 app_type = sys.argv[1]
 instance_name = sys.argv[2]
 instance_targz_full_path = gopath + "/" + app_type + "/" + instance_name + ".tar.gz"
 if not os.path.exists( instance_targz_full_path ):
     comm_funcs.print_error("ERROR: instance_targz_full_path not set:" + instance_targz_full_path)
     sys.exit(1)
 inst_ports_lines = comm_funcs.get_file_content_as_list(gopath + "/" + "instance_and_ports.txt")
 inst_port = ""
 for one in inst_ports_lines:
     one = one.strip()
     if 0 == one:
         continue
     ones = one.split(",")
     if 2 != len(ones):
         comm_funcs.print_error("PYTHON ERROR: length not right :" + one )
         continue
     inst = ones[0].strip()
     if inst != instance_name:
         continue
     port = ones[1].strip()
     inst_port = port
     break
コード例 #17
0
     comm_funcs.print_error(
         " arguments : app_type and instance_name  need assigned ")
     comm_funcs.print_error("ERROR EXIT PYTHON")
     sys.exit(1)
 gopath = comm_funcs.get_gopath()
 if gopath is None or 0 == len(gopath):
     comm_funcs.print_error("ERROR: evn path not set , prod mod")
     sys.exit(1)
 app_type = sys.argv[1]
 instance_name = sys.argv[2]
 instance_targz_full_path = gopath + "/" + app_type + "/" + instance_name + ".tar.gz"
 if not os.path.exists(instance_targz_full_path):
     comm_funcs.print_error("ERROR: instance_targz_full_path not set:" +
                            instance_targz_full_path)
     sys.exit(1)
 inst_ports_lines = comm_funcs.get_file_content_as_list(
     gopath + "/" + "instance_and_ports.txt")
 inst_port = ""
 for one in inst_ports_lines:
     one = one.strip()
     if 0 == one:
         continue
     ones = one.split(",")
     if 2 != len(ones):
         comm_funcs.print_error("PYTHON ERROR: length not right :" + one)
         continue
     inst = ones[0].strip()
     if inst != instance_name:
         continue
     port = ones[1].strip()
     inst_port = port
     break
コード例 #18
0
ファイル: sub_gene_comm.py プロジェクト: cloudtrends/godroid
def read_model_gorp_api_file(file_path):
    contents_list = comm_funcs.get_file_content_as_list(file_path)
    pass
コード例 #19
0
ファイル: godroid_helper.py プロジェクト: cloudtrends/godroid
def get_instance_profile_from_profile_file( profile_path ):
    print_ok("begin get instance from profile:" + profile_path)
    tmp_cls = sub_gene_comm.ClassProfileCfg()
    tmp_cls.ProfileFile = profile_path
    contents_list = comm_funcs.get_file_content_as_list(profile_path)
    for line in contents_list:
        line = line.strip()
        if 0 == len(line):
            continue
        if line.startswith("#"):
            continue
        if "#" in line:
            line = line[: line.find("#") ]
        line = line.strip()
        if 0 == len(line):
            continue
        #
        #GeneCompontents
        if line.startswith("gene_compontents"):
            line = line.replace("gene_compontents=", "")
            tmp_cls.GeneCompontents = line.strip()
            continue
        if line.startswith("is_module"):
            line = line.replace("is_module=", "")
            if "true" in line:
                tmp_cls.IsModule = True
            else:
                tmp_cls.IsModule = False
            pass
        if line.startswith("module_type"):
            line = line.replace("module_type=", "")
            tmp_cls.ModuleType = line.strip()
            if tmp_cls.IsModule and 0 == len(tmp_cls.ModuleType):
                comm_funcs.print_error("Error when parser module type: no  ModuleType ")
                sys.exit(1)
            pass
        if line.startswith("module_name"):
            line = line.replace("module_name=", "")
            tmp_cls.ModuleName = line.strip()
            if tmp_cls.IsModule and 0 == len(tmp_cls.ModuleName):
                comm_funcs.print_error("Error when parser module name: no module name ")
                sys.exit(1)
            pass
        if line.startswith("controller_class_name"):
            line = line.replace("controller_class_name=", "")
            tmp_cls.ControlCalssName = line.strip()
            pass
        if line.startswith("table_name=") :
            line = line.replace("table_name=", "")
            tmp_cls.TableName = line.strip()
        if line.startswith("package_name="):
            line = line.replace("package_name=", "")
            tmp_cls.PackageName = line.strip()
            if 0 == len( tmp_cls.PackageName ):
                print_error("Error package name can not be empty.")
                sys.exit(1)
        if line.startswith("func_name="):
            '''
            func name is just a help field for generate the go file name
            so ,can be empty
            '''
            line = line.replace("func_name=", "")
            tmp_cls.FuncName = line.strip()
        if line.startswith("class_name=") :
            line = line.replace("class_name=", "")
            tmp_cls.ClassName = line.strip()
        if line.startswith( "columns=" ) :
            line = line.replace("columns=", "").strip()
            obj = sub_gene_comm.ClassColumnProfile()
            lines = line.split(";")
            sql_part = lines[0]
            go_part = lines[1]
            sql_parts = sql_part.split(",")
            go_parts = go_part.split(",")
            obj.SqlName = sql_parts[0]
            if obj.SqlName == "mysql_name" :
                print_error("Error mysql_name should not exist in config file.")
                sys.exit(1)
            obj.SqlType = sql_parts[1]
            obj.GoName = go_parts[0]
            obj.GoType = go_parts[1]
            if 3 <= len(lines):
                part3 = lines[2]
                parts3 = part3.split(",")
                if 2 == len(parts3):
                    if "ShowName" in parts3[0]:
                        obj.ShowName = parts3[1].strip()
                        if obj.ShowName == "XXXXXX":
                            obj.ShowName = obj.GoName
            tmp_cls.ColumnsList.append(obj)
    
    return tmp_cls