Пример #1
0
def render_controller(name, noforce):
    # 
    print " creating controller: " 
    print " -- ", name 
    
    # add the auto generated warning to the outputfile
    infile = open (os.path.normpath(PARTS_DIR + "autogenerated_warning.txt"), "r")
    ostr = infile.read()
    infile.close()
    
    # add a creation date
    ostr = ostr + os.linesep
    ostr = ostr + "# date created: \t" + str(datetime.date.today())
    ostr = ostr + os.linesep
    
    # Add the model_stub part1 content to the newly generated file. 
    infile = open (os.path.normpath( PARTS_DIR + "controller_stub_part0.py"), "r")
    ostr = ostr + infile.read()
    infile.close()
    
    #pluralname = powlib.plural(model)
    #ostr += powlib.tab +  powlib.tab + "table_name=\"" + pluralname + "\""
    ostr += powlib.linesep
    ostr += "import " + string.capitalize( name ) 
    ostr += powlib.linesep
    ostr += powlib.linesep
    
    classname = string.capitalize( name ) + "Controller"
    ostr += "class " + classname + "(BaseController.BaseController):"
    
    # Add the controller_stub part 1 content to the newly generated file. 
    infile = open (os.path.normpath(PARTS_DIR + "controller_stub_part1.py"), "r")
    ostr = ostr + infile.read()
    ostr+= powlib.tab + powlib.tab + "self.modelname = \"" + string.capitalize( name ) + "\"" + powlib.linesep
    
    # Add the controller_stub part2 content to the newly generated file. 
    infile = open (os.path.normpath(PARTS_DIR + "controller_stub_part2.py"), "r")
    ostr = ostr + infile.read()
    infile.close()
    
    filename = os.path.normpath ( "./controllers/" + classname +".py" )
    
    if os.path.isfile( os.path.normpath(filename) ) and noforce:
        print " --", filename + " already exists... (Not overwrtitten. Use -f to force ovewride)"
    else:
        ofile = open(  filename , "w+") 
        print  " -- created controller " + filename
        ofile.write( ostr )
        ofile.close()
    #
    # check if BaseModel exist and repair if necessary
    if os.path.isfile(os.path.normpath( "./controllers/BaseController.py")):
        #BaseModel exists, ok.
        pass
    else:
        # copy the BaseClass
        powlib.check_copy_file(os.path.normpath( "./stubs/controllers/BaseController.py"), os.path.normpath( "./controllers/"))
    
    render_test_stub( name, classname )
    return
Пример #2
0
def render_migration_job(filename):
        """create a 'job' or task that has to be done on the database.
        typical examples are backup/restore scripts for dbs or tables or loading data into a table.
        These migrations are not part of the migration versioning system.
        They can be executed with python migrate.py -f <migrationname>
        """
        print " -- creating migration job:"
        powlib.check_copy_file(os.path.normpath( PARTS_DIR + "migration_job.py"), "./migrations/" + filename + "_migration.py")
        return
Пример #3
0
def render_controller(name, force, prefix_path="./"):
    """ generates a controller according to the given options
        @param name: name prefix of the Controller fullname NameController
        @param force: if true: forces overwrtiting existing controllers"""
    
    print " creating controller: ", name 
    # add the auto generated warning to the outputfile
    infile = open (os.path.normpath(PARTS_DIR + "controller_stub.py"), "r")
    ostr = infile.read()
    infile.close()
    
    #pluralname = powlib.plural(model)
    ostr = ostr.replace( "#DATE", str(datetime.date.today()) )  
    modelname = string.capitalize( name ) 
    ostr = ostr.replace("#MODELNAME", modelname)
    ostr = ostr.replace("#CONTROLLERNAME", modelname)
    classname = modelname + "Controller"
    filename = os.path.normpath ( 
        os.path.join( prefix_path + "./controllers/",  classname + ".py" ) )
    
    if os.path.isfile( os.path.normpath(filename) ):
        if not force:
            print " --", filename,
            print " already exists... (Not overwritten. Use -f to force ovewride)"
        else:
            ofile = open(  filename , "w+") 
            print  " -- created controller " + filename
            ofile.write( ostr )
            ofile.close()
    else:
        ofile = open(  filename , "w+") 
        print  " -- created controller " + filename
        ofile.write( ostr )
        ofile.close()
    #
    # check if BaseController exist and repair if necessary
    if not os.path.isfile(os.path.normpath( "./controllers/BaseController.py")):
        # copy the BaseClass
        powlib.check_copy_file(
            os.path.normpath( "./stubs/controllers/BaseController.py"), 
            os.path.normpath( "./controllers/") )
    
    render_test_stub( name, classname )
    return
def gen_app(appname, appdir, force=False):
    """ Generates the complete App Filesystem Structure for Non-GAE Apps.
        Filesystem action like file and dir creation, copy fiels etc. NO DB action in this function 
    """
    
    appname = str(appname)
    appname = str.strip(appname)
    appname = str.lower(appname)
    print " -- generating app:", appname

    powlib.check_create_dir(appdir + appname)
    appbase = os.path.abspath(os.path.normpath(appdir +"/"+ appname + "/"))
    #print appbase
    # defines the subdirts to be created. Form { dir : subdirs }
    subdirs = [ {"config" : [] },  
                        {"db" : [] },
                        {"lib" : [] },
                        {"migrations" : [] },
                        {"models" : ["basemodels"] },
                        {"controllers" : [] },
                        {"public" : ["img", "img/bs", "ico", "css", "css/bs", "js", "js/bs", "doc"] },
                        {"stubs" : ["partials"] },
                        {"views" : ["layouts"] },
                        {"tests" : ["models", "controllers", "integration", "fixtures"] },
                        {"ext" : ["auth", "validate"] }                        
                        ]
    for elem in subdirs:
        for key in elem:
            subdir = os.path.join(appbase,str(key))
            powlib.check_create_dir( subdir)
            for subs in elem[key]:
                powlib.check_create_dir( os.path.join(subdir,str(subs)))
    
    #
    # copy the files in subdirs. Form ( from, to )
    #
    deep_copy_list = [  ("stubs/config", "config"),  
                        ("stubs/lib", "lib"), 
                        ("stubs", "stubs"),
                        ("stubs/migrations","migrations"),
                        ("stubs/partials","stubs/partials"),
                        ("stubs/public/doc","/public/doc"),
                        ("stubs/public/ico","/public/ico"),
                        ("stubs/public/img","/public/img"),
                        ("stubs/public/img/bs","/public/img/bs"),
                        ("stubs/public/css","/public/css"),
                        ("stubs/public/css/bs","/public/css/bs"),
                        ("stubs/public/js", "public/js"),
                        ("stubs/public/js/bs", "public/js/bs"),
                        ("stubs/lib", "lib"), 
                        ("stubs/controllers", "controllers"),
                        ("stubs/views", "views"),
                        ("stubs/views/layouts", "views/layouts"),
                        ("stubs/ext/auth", "ext/auth"),
                        ("stubs/ext/validate", "ext/validate"),
                        ]
                        
    print " -- copying files ..."
    exclude_patterns = [".pyc", ".pyo", ".DS_STORE"]
    exclude_files = [ "db.cfg" ]
    for source_dir, dest_dir in deep_copy_list:
        for source_file in os.listdir(source_dir):
            fname, fext = os.path.splitext(source_file)
            if not fext in exclude_patterns and not source_file in exclude_files:
                powlib.check_copy_file(
                    os.path.join(source_dir,source_file),
                    os.path.join(appbase+"/"+dest_dir,source_file)
                )
            else:
                print " excluded:.EXCL", source_file
                continue
                
    #
    # copy the generator files
    #
    powlib.check_copy_file("scripts/generate_model.py", appbase)
    powlib.check_copy_file("scripts/do_migrate.py", appbase)
    powlib.check_copy_file("scripts/generate_controller.py", appbase)
    powlib.check_copy_file("scripts/generate_migration.py", appbase)
    powlib.check_copy_file("scripts/generate_scaffold.py", appbase)
    powlib.check_copy_file("scripts/generate_mvc.py", appbase)
    powlib.check_copy_file("scripts/simple_server.py", appbase)
    powlib.check_copy_file("pow_router.wsgi", appbase)
    powlib.check_copy_file("scripts/pow_console.py", appbase)
    powlib.check_copy_file("scripts/runtests.py", appbase)
        
    powlib.replace_string_in_file(
        os.path.join(appbase + "/" + "simple_server.py"),
        "#POWAPPNAME",
        appname
    )
    
    powlib.replace_string_in_file(
        os.path.join(appbase + "/" + "pow_router.wsgi"),
        "#POWAPPNAME",
        appname
    )
    
    #
    # copy the initial db's
    #
    appdb = "stubs/db/app_db_including_app_versions_small.db"
    powlib.check_copy_file(appdb, os.path.normpath(appbase + "/db/" + appname + "_prod.db") )
    powlib.check_copy_file(appdb, os.path.normpath(appbase + "/db/" + appname + "_test.db") )
    powlib.check_copy_file(appdb, os.path.normpath(appbase + "/db/" + appname + "_devel.db") )
    #powlib.check_copy_file("stubs/db/empty_app.db", os.path.normpath(appbase + "/db/app.db") )
    
    #
    # initiate the db.cfg file
    #
    render_db_config(appname, appbase)
    
    generate_model.render_model("App", False, "System class containing the App Base Informations", appname)
    generate_model.render_model("Version", False, "System class containing the Versions", appname)
    return
    print "#########################################################################"
    sys.exit()
    
 print "######################################################"
 print "# setting up auth plugin"
 print "######################################################"
 f = open("./exec_once.nfo", "w")
 f.write("1")
 f.close()
 
 print "setup plugin: Auth"
 #
 # Copy the Controllers
 #
 print " -- copying the AuthController... to " + os.path.normpath("../../" + ext.auth["controllers_dir"])
 powlib.check_copy_file("AuthController.py",os.path.join("../../" + ext.auth["controllers_dir"],"AuthController.py") )
 print " -- copying the UserController... to " + os.path.normpath("../../" + ext.auth["controllers_dir"])
 powlib.check_copy_file("UserController.py",os.path.join("../../" + ext.auth["controllers_dir"],"UserController.py") )
 
 
 #
 # Generate The Model
 #
 print " -- generating the User model."
 generate_model.render_model("user", False, "User model for py_auth", "../../", None, "../../stubs/partials/")
 
 
 #
 # render the User views
 #
 generate_scaffold.scaffold("user", True,