Beispiel #1
0
def __self_call_generate_model_class_gorp_funcs_and_api(
        instance_profile_obj, model_domain):
    """
    if file exist , check have meta tag
                        if have meta , then replace them
                        if not have meta tag , just give hint and stop
    if not exists , create new 
    """
    #sub_gene_class, sub_gene_funcs_gorp, sub_gene_api
    if not godroid_helper.check_model_funcs_api_meta_flag(
            instance_profile_obj, model_domain):
        comm_funcs.print_error(
            "ERROR: model funcs api meta flag check failed :" +
            instance_profile_obj.ProfileFile)
        sys.exit(1)

    comm_funcs.print_ok("\n\n")
    comm_funcs.print_ok(
        "--- --- --- --- --- --- now begin generate code ... ... ... ... ... ")
    sub_gene_class.generate_model_class_file(instance_profile_obj,
                                             model_domain)
    sub_gene_funcs_gorp.generate_funcs_of_gorp_file(instance_profile_obj,
                                                    model_domain)
    sub_gene_api.generate_api_file(instance_profile_obj, model_domain)
    comm_funcs.print_ok(
        "--- --- --- --- --- --- now begin generate code ... ... ... ... ... end"
    )
    comm_funcs.print_ok("\n\n")
    pass
Beispiel #2
0
def check_model_profile_exist():
    ModelProfilePath = comm_funcs.check_and_get_go_path(
    ) + "/" + ModelProfileDirName
    if not os.path.exists(ModelProfilePath + "/" +
                          AlreadyGeneratedModelProfileName):
        comm_funcs.print_error("ERROR: already profile config not exist. ")
        sys.exit(1)
    return
Beispiel #3
0
def get_full_profile_instance_path(profile_file):
    if not profile_file.endswith(".cfg"):
        comm_funcs.print_error("ERROR: profile file extension not match cfg:" +
                               profile_file)
        sys.exit(1)
    ModelProfileModelsPath = comm_funcs.check_and_get_go_path(
    ) + "/" + ModelProfileDirName + "/models"
    InstanceProfilePath = ModelProfileModelsPath + "/" + profile_file
    if not os.path.exists(InstanceProfilePath):
        comm_funcs.print_error("ERROR: profile file not exist:" +
                               InstanceProfilePath)
        sys.exit(1)
    return InstanceProfilePath
Beispiel #4
0
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
Beispiel #5
0
def check_and_create_model_domain_path(model_domain, gopath):
    """
    check the model domain path 
    if the model domain not exit , sys.exit
    if the sub directories not exits , create them.
    """
    ModelDomainPath = ModelDomainFullPath = gopath + "/src/" + model_domain
    comm_funcs.print_ok("......check_and_create_model_domain_path:" +
                        ModelDomainPath)
    for c in ModelDomainPath:
        pass
        #print c
    if os.path.exists(ModelDomainPath):
        return True
    comm_funcs.print_error("PYTHON ERROR: ModelDomainPath not exist:" +
                           ModelDomainPath)
    sys.exit(1)
Beispiel #6
0
def get_domain_controller_instance_full_path(profile_instance, model_domain):
    """
    1. is module ?
        module path 
        such as :  ${gopath}/src/{model_domain}/{module_type}/app/controllers
    2. not module 
        not module path 
        such as : ${gopath}/src/gobbs/app/controllers/{self_package_name}
    """
    if profile_instance.IsModule:
        return get_domain_module_controller_path(profile_instance, model_domain)
    else:
        return get_domain_non_module_controller_path(profile_instance, model_domain)
        pass
    comm_funcs.print_error("Error when get get_domain_controller_instance_full_path")
    sys.exit(1)
    return None
    pass
Beispiel #7
0
def check_model_funcs_api_meta_flag( profile_instance, model_domain ):
    #gopath = comm_funcs.get_gopath()
    #model_file_name = get_model_class_file_name( profile_instance )
    #funcs_of_gorp_file_name = get_model_funcs_of_gorp_file_name( profile_instance )
    #api_file_name = get_api_file_name( profile_instance )
    #
    domain_model_instance_full_path = get_domain_model_instance_full_path(profile_instance, model_domain)
    if not os.path.exists( domain_model_instance_full_path ):
        comm_funcs.print_ok("TIPS:")
        comm_funcs.print_ok("......create for :" + domain_model_instance_full_path )
        os.makedirs(domain_model_instance_full_path)
    domain_api_instance_full_path = get_domain_api_instance_full_path(profile_instance, model_domain)
    if not os.path.exists( domain_api_instance_full_path ):
        comm_funcs.print_ok("TIPS:")
        comm_funcs.print_ok("......create for :" + domain_api_instance_full_path )
        os.makedirs(domain_api_instance_full_path)


    FullPathModelFile = get_model_class_file_name_full_path(profile_instance, model_domain)
    FullPathFuncsOfGropFile = get_model_funcs_of_gorp_file_name_full_path(profile_instance, model_domain)
    FullPathApiFile = get_api_file_name_full_path(profile_instance, model_domain)
    if not os.path.exists(FullPathModelFile):
        touch_and_create_empty_file(FullPathModelFile, profile_instance)
    if not os.path.exists(FullPathFuncsOfGropFile) :
        touch_and_create_empty_file(FullPathFuncsOfGropFile, profile_instance)
    if not os.path.exists(FullPathApiFile):
        touch_and_create_empty_file(FullPathApiFile, profile_instance)
    if True:
        comm_funcs.print_ok(">>>> begin check meta flag is valid")
        model_class_valid = False
        funcs_of_gorp_valid = False
        api_file_valid = False
        #
        model_class_valid = sub_gene_class.__check_model_meta_flag(FullPathModelFile)
        funcs_of_gorp_valid = sub_gene_funcs_gorp.__check_funcs_meta_flag(FullPathFuncsOfGropFile)
        api_file_valid = sub_gene_api.__check_api_meta_flag(FullPathApiFile)
        if model_class_valid and funcs_of_gorp_valid and api_file_valid:
            return True
        else:
            comm_funcs.print_error("PYTHON ERROR: check files meta flag valid is false !  EXIT NOW ")
            sys.exit(1)
        pass
    #sub_gene_class, sub_gene_funcs_gorp, sub_gene_api
    return True
Beispiel #8
0
def __self_call_generate_controller(instance_profile_obj, model_domain):
    """
    sub_gene_controller.py
    """
    if not godroid_helper.check_controller_meta_flag(instance_profile_obj,
                                                     model_domain):
        comm_funcs.print_error("ERROR: controller meta flag check failed: " +
                               instance_profile_obj.ProfileFile)
        sys.exit(1)

    if len(instance_profile_obj.ControlCalssName) == 0:
        comm_funcs.print_error("Tips:")
        comm_funcs.print_ok("ControlCalssName not exist so return .")
        sys.exit(1)
    comm_funcs.print_ok(
        "X : generate the controller and controller_admin file ")
    #if not godroid_helper.check_controller_meta_flag(instance_profile_obj, model_domain):
    #    comm_funcs.print_error("ERROR: controller meta flag check failed:" + instance_profile_obj.ProfileFile)
    #    sys.exit(1)
    #    pass
    sub_gene_controller.generate_controller_file(instance_profile_obj,
                                                 model_domain)
    pass
Beispiel #9
0
    sub_gene_api.generate_api_file(instance_profile_obj, model_domain)
    comm_funcs.print_ok(
        "--- --- --- --- --- --- now begin generate code ... ... ... ... ... end"
    )
    comm_funcs.print_ok("\n\n")
    pass


if __name__ == "__main__":
    """

    """
    if 5 != len(sys.argv):
        help()
        comm_funcs.print_error(
            "PYTHON ERROR: shoud assign: prod/dev mode, class profile file , model domain , module;controller;html;"
        )
        sys.exit(1)
    gopath = comm_funcs.check_and_get_go_path()
    sub_gene_comm.check_model_profile_exist()
    run_mode = sys.argv[1]
    if "dev" not in run_mode and "prod" not in run_mode:
        help()
        sys.exit(1)

    profile_file = sys.argv[2]
    model_domain = sys.argv[3]
    generate_components = sys.argv[4]
    sub_gene_comm.check_and_create_model_domain_path(model_domain, gopath)
    InstanceProfilePath = sub_gene_comm.get_full_profile_instance_path(
        profile_file)
Beispiel #10
0
def print_error(text):
    comm_funcs.print_error(text)
Beispiel #11
0
sys.path.append(os.getcwd())
import subprocess
import shutil
import comm_funcs
import signal
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 )
import sys
reload(sys)
import os
sys.setdefaultencoding('utf8')
sys.path.append(os.getcwd())
import subprocess
import shutil
import comm_funcs




if __name__ == "__main__":
    gopath = comm_funcs.get_gopath()
    if 0 == len(gopath):
        comm_funcs.print_error( "ERROR GOPATH not set." )
        sys.exit(1)
    comm_funcs.print_ok( "gopath is :" + gopath )
    files = comm_funcs.listdir_fullpath( gopath )
    for one in files:
        print one
        if not os.path.isfile( one ):
            continue
        if one.endswith(".sh") or one.endswith(".py"):
            os.remove(one)
    self_files = comm_funcs.listdir_fullpath( os.getcwd() )
    for one in self_files:
        print one
        if not os.path.isfile( one ) or  "sync_myself" in one :
            continue
        if one.endswith(".sh") or one.endswith(".py"):
import sys
reload(sys)
import os
sys.setdefaultencoding('utf8')
sys.path.append(os.getcwd())
import subprocess
import shutil
import comm_funcs
import signal
import time

if __name__ == "__main__":
    """
    """
    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:
Beispiel #14
0
def print_error(line):
    comm_funcs.print_error("   htmlcurd  :" + line)
Beispiel #15
0
def print_error(line):
    comm_funcs.print_error("   GENERATOR  :" + line)
Beispiel #16
0
    return __extract_route_one_part(routes_file_name, SelfPart, SelfPartEnd)


def extract_common_part(routes_file_name):
    return __extract_route_one_part(routes_file_name, CommonPart,
                                    CommonPartEnd)


def extract_self_headers(routes_file_name):
    return __extract_route_one_part(routes_file_name, SelfHeader,
                                    SelfHeaderEnd)


if __name__ == "__main__":
    if 5 != len(sys.argv):
        comm_funcs.print_error("PYTHON ERROR: argv count not match")
        comm_funcs.print_error("ERROR , EXIT PYTHON")
        sys.exit(1)
    app_type = sys.argv[1]
    instance_name = sys.argv[2]
    direction = sys.argv[3]
    is_check_app_type_and_instance_name = sys.argv[4]
    app_type = app_type.strip()
    instance_name = instance_name.strip()
    if "true" == is_check_app_type_and_instance_name:
        """
        """
        if comm_funcs.check_app_type_and_instance_name(app_type,
                                                       instance_name):
            comm_funcs.print_ok("check app_type and instance_name OK")
        else:
Beispiel #17
0
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
Beispiel #18
0
def print_error(line):
    comm_funcs.print_error("   godroid_helper  :" + line )
 signal.signal(signal.SIGINT, exit_gracefully)
 #
 #
 #
 comm_funcs.helloworld()
 if 2 >= len(sys.argv):
     print "error, should assign: app_type instance_name "
     sys.exit(1)
 app_type = sys.argv[1]
 instance_name = sys.argv[2]
 app_type = app_type.strip()
 instance_name = instance_name.strip()
 if comm_funcs.check_app_type_and_instance_name(app_type, instance_name):
     comm_funcs.print_ok("check app_type and instance_name OK")
 else:
     comm_funcs.print_error("ERROR: app_type or instance_name not match")
     sys.exit(1)
 #run_program()
 print "export PATH=\"$PATH:$GOPATH/bin\""
 os.system("export PATH=\"$PATH:$GOPATH/bin\"")
 if app_type == "gobbs":
     try:
         os.system("./debug_run.sh " + app_type + " " + instance_name)
     except KeyboardInterrupt:
         comm_funcs.print_error("Ctrl+C capture ")
         sys.exit(1)
 if app_type == "martini":
     comm_funcs.print_ok("begin debug_run_martini.sh ")
     try:
         os.system("./debug_run_martini.sh " + app_type + " " +
                   instance_name)
            return_lines = return_lines + line + "\n"
    return_lines = return_lines + end_part + "\n"
    return return_lines


def extract_self_part( routes_file_name ):
    return __extract_route_one_part( routes_file_name , SelfPart , SelfPartEnd )
def extract_common_part( routes_file_name ):
    return __extract_route_one_part( routes_file_name , CommonPart , CommonPartEnd )
def extract_self_headers( routes_file_name):
    return __extract_route_one_part( routes_file_name , SelfHeader , SelfHeaderEnd )


if __name__ == "__main__":
    if 5 != len(sys.argv):
        comm_funcs.print_error("PYTHON ERROR: argv count not match")
        comm_funcs.print_error("ERROR , EXIT PYTHON")
        sys.exit(1)
    app_type = sys.argv[1]
    instance_name = sys.argv[2]
    direction = sys.argv[3]
    is_check_app_type_and_instance_name = sys.argv[4]
    app_type = app_type.strip()
    instance_name = instance_name.strip()
    if "true" == is_check_app_type_and_instance_name:
        """
        """
        if comm_funcs.check_app_type_and_instance_name(app_type, instance_name):
            comm_funcs.print_ok("check app_type and instance_name OK")
        else:
            comm_funcs.print_error("ERROR: app_type or instance_name not match")
def print_error(line):
    comm_funcs.print_error("   revel_curd_funcs  :" + line)
Beispiel #22
0
def print_error(text):
    comm_funcs.print_error(text)
import sys
reload(sys)
import os
sys.setdefaultencoding('utf8')
sys.path.append(os.getcwd())
import subprocess
import shutil
import comm_funcs
import signal
import time

if __name__ == "__main__":
    """
    """
    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")
def print_error(line):
    comm_funcs.print_error("   api_web_module  :" + line)
 signal.signal(signal.SIGINT, exit_gracefully)
 #
 #
 #
 comm_funcs.helloworld()
 if 2 >= len(sys.argv):
     print "error, should assign: app_type instance_name "
     sys.exit(1)
 app_type = sys.argv[1]
 instance_name = sys.argv[2]
 app_type = app_type.strip()
 instance_name = instance_name.strip()
 if comm_funcs.check_app_type_and_instance_name(app_type, instance_name):
     comm_funcs.print_ok("check app_type and instance_name OK")
 else:
     comm_funcs.print_error("ERROR: app_type or instance_name not match")
     sys.exit(1)
 #run_program()
 print "export PATH=\"$PATH:$GOPATH/bin\""
 os.system("export PATH=\"$PATH:$GOPATH/bin\"")
 if app_type == "gobbs":
     try:
         os.system("./debug_run.sh " + app_type + " "  + instance_name )
     except KeyboardInterrupt:
         comm_funcs.print_error( "Ctrl+C capture ")
         sys.exit(1)
 if app_type == "martini":
     comm_funcs.print_ok("begin debug_run_martini.sh ")
     try:
         os.system("./debug_run_martini.sh " + app_type + " "  + instance_name )
     except KeyboardInterrupt: