コード例 #1
0
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
コード例 #2
0
ファイル: generate_blog.py プロジェクト: cponeill/pow_devel
def generate_all_for( model ):
    generate_model.render_model(model, True, model + " Model")
    generate_controller.render_controller(model, True)
    generate_scaffold.scaffold(model, True)    
    generate_migration.render_migration(model, model, model + " Migration")
    return
コード例 #3
0
def main():
    """ Executes the render methods to generate a model, controller,
    migration and the views according to the given options """
    parser = OptionParser()
    mode= MODE_CREATE
    parser.add_option("-m", "--model",
                      action="store",
                      type="string",
                      dest="model",
                      help="defines the model for this migration.",
                      default ="None")

    parser.add_option("-c", "--comment",
                      action="store",
                      type="string",
                      dest="comment",
                      help="defines a comment for this migration.",
                      default ="No Comment")

    parser.add_option("-d", "--column-definitions",
                      action="store",
                      type="string", dest="col_defs",
                      help="""column definitions.Form: d- 'NAME TYPE opt, NAME2 TYPE2 opt2'
                              Name, type, options (all SQLAlchemy style).""",
                      default="None")

    parser.add_option("-f", "--force",
                        action="store_true",
                        dest="force",
                        help="forces overrides of existing files",
                        default=False)
    #
    # column definition format: NAME TYPE opt1 opt2 optn, NAME2 TYPE2 opt1 opt2 optn
    #
    start = datetime.datetime.now()


    (options, args) = parser.parse_args()

    #if no model given and no parameter at all, then quit with error
    if options.model == "None" and len(args) < 1:
        parser.error("You must at least specify an migration name by giving -n <name>.")
        return
    else:
        # if no model given but a parameter, than assume that the first parameter
        # is the model
        if options.model == "None":
            options.model = args[0]

        print "generate_mvc for model:", options.model
        # generate the model
        generate_model.render_model(modelname = options.model,
                                    force = options.force,
                                    comment = options.comment
                                    )
        print
        # generate the Controller
        generate_controller.render_controller( name = options.model,
                                               force = options.force
                                              )

        print
        # generate the views
        generate_scaffold.scaffold(modelname = options.model,
                                   force = options.force,
                                   actions = ["list", "show","create", "edit", "message"]
                                   )

        print
        # generate the migration
        # ooptions_col_defs has to be a comma separated list of column names and SQLAlchemy DB types:
        # example: lastname String(100), email String(100)
        col_defs = options.col_defs

        generate_migration.render_migration( modelname = options.model,
                                             comment = options.comment,
                                             col_defs = options.col_defs
                                             )
        print


    end = datetime.datetime.now()
    duration = end - start
    print "generated_mvc in("+ str(duration) +")"
    print
    return
コード例 #4
0
 
 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, 
                           actions = ["list", "show","create", "edit", "message"], 
                           PARTS_DIR = "../../stubs/partials/", prefix_dir = "../../" )
 
 #
 # render the user migration
 #
 col_defs = "firstname String(100),"
 col_defs += "lastname String(100),"
 col_defs += "email String(100),"