def create(options): if DEMO_MODE: session.flash = T('disabled in demo mode') redirect(URL('step6')) params = dict(session.app['params']) app = session.app['name'] if not app_create(app,request,force=True,key=params['security_key']): session.flash = 'Failure to create application' redirect(URL('step6')) ### save metadata in newapp/wizard.metadata meta = os.path.join(request.folder,'..',app,'wizard.metadata') file=open(meta,'wb') pickle.dump(session.app,file) file.close() ### apply theme if options.apply_layout and params['layout_theme']!='Default': try: fn = 'web2py.plugin.layout_%s.w2p' % params['layout_theme'] theme = urllib.urlopen(LAYOUTS_APP+'/static/plugin_layouts/plugins/'+fn) plugin_install(app, theme, request, fn) except: session.flash = T("unable to download layout") ### apply plugins for plugin in params['plugins']: print plugin try: plugin_name = 'web2py.plugin.'+plugin+'.w2p' stream = urllib.urlopen(PLUGINS_APP+'/static/'+plugin_name) plugin_install(app, stream, request, plugin_name) except Exception, e: session.flash = T("unable to download plugin: %s" % plugin)
def create(options): if DEMO_MODE: session.flash = T("disabled in demo mode") redirect(URL("step6")) params = dict(session.app["params"]) app = session.app["name"] if app_create(app, request, force=True, key=params["security_key"]): if MULTI_USER_MODE: db.app.insert(name=app, owner=auth.user.id) else: session.flash = "Failure to create application" redirect(URL("step6")) ### save metadata in newapp/wizard.metadata try: meta = os.path.join(request.folder, "..", app, "wizard.metadata") file = open(meta, "wb") pickle.dump(session.app, file) file.close() except IOError: session.flash = "Failure to write wizard metadata" redirect(URL("step6")) ### apply theme if options.apply_layout and params["layout_theme"] != "Default": try: fn = "web2py.plugin.layout_%s.w2p" % params["layout_theme"] theme = urllib.urlopen(LAYOUTS_APP + "/static/plugin_layouts/plugins/" + fn) plugin_install(app, theme, request, fn) except: session.flash = T("unable to download layout") ### apply plugins for plugin in params["plugins"]: try: plugin_name = "web2py.plugin." + plugin + ".w2p" stream = urllib.urlopen(PLUGINS_APP + "/static/" + plugin_name) plugin_install(app, stream, request, plugin_name) except Exception, e: session.flash = T("unable to download plugin: %s" % plugin)
def create(options): if DEMO_MODE: session.flash = T('disabled in demo mode') redirect(URL('default','step6')) params = dict(session.app['params']) app = session.app['name'] app_create(app,request,force=True,key=params['security_key']) ### save metadata in newapp/wizard.metadata meta = os.path.join(request.folder,'..',app,'wizard.metadata') file=open(meta,'wb') pickle.dump(session.app,file) file.close() ### apply theme if options.apply_layout and params['layout_theme']!='Default': try: fn = 'web2py.plugin.layout_%s.w2p' % params['layout_theme'] theme = urllib.urlopen(LAYOUTS_APP+'/static/plugin_layouts/plugins/'+fn) plugin_install(app, theme, request, fn) except: response.flash = T("unable to install there") ### write configuration file into newapp/models/0.py model = os.path.join(request.folder,'..',app,'models','0.py') file = open(model,'wb') file.write("from gluon.storage import Storage\n") file.write("settings = Storage()\n\n") file.write("settings.migrate = True\n") for key,value in session.app['params']: file.write("settings.%s = %s\n" % (key,repr(value))) file.close() ### write configuration file into newapp/models/menu.py if options.generate_menu: model = os.path.join(request.folder,'..',app,'models','menu.py') file = open(model,'wb') file.write(make_menu(session.app['pages'])) file.close() ### customize the auth_user table model = os.path.join(request.folder,'..',app,'models','db.py') fix_db(model) ### create newapp/models/db_wizard.py if options.generate_model: model = os.path.join(request.folder,'..',app,'models','db_wizard.py') file = open(model,'wb') file.write('### we prepend t_ to tablenames and f_ to fieldnames for disambiguity\n\n') tables=sort_tables(session.app['tables']) for table in tables: if table=='auth_user': continue file.write(make_table(table,session.app['table_'+table])) file.close() model = os.path.join(request.folder,'..',app, 'models','db_wizard_populate.py') if os.path.exists(model): os.unlink(model) if options.populate_database: file = open(model,'wb') file.write(populate(session.app['tables'])) file.close() ### create newapp/controllers/default.py if options.generate_controller: controller = os.path.join(request.folder,'..',app,'controllers','default.py') file = open(controller,'wb') file.write("""# -*- coding: utf-8 -*- ### required - do no delete def user(): return dict(form=auth()) def download(): return response.download(request,db) def call(): session.forget() return service() ### end requires """) for page in session.app['pages']: file.write(make_page(page,session.app.get('page_'+page,''))) file.close() ### create newapp/views/default/*.html if options.generate_views: for page in session.app['pages']: view = os.path.join(request.folder,'..',app,'views','default',page+'.html') file = open(view,'wb') file.write(make_view(page,session.app.get('page_'+page,''))) file.close() if options.erase_database: path = os.path.join(request.folder,'..',app,'databases','*') for file in glob.glob(path): os.unlink(file)
def create(options): if DEMO_MODE: session.flash = T('disabled in demo mode') redirect(URL('step6')) params = dict(session.app['params']) app = session.app['name'] if app_create(app, request, force=True, key=params['security_key']): if MULTI_USER_MODE: db.app.insert(name=app, owner=auth.user.id) else: session.flash = 'Failure to create application' redirect(URL('step6')) ### save metadata in newapp/wizard.metadata try: meta = os.path.join(request.folder, '..', app, 'wizard.metadata') file = open_file(meta, 'wb') pickle.dump(session.app, file) file.close() except IOError: session.flash = 'Failure to write wizard metadata' redirect(URL('step6')) ### apply theme if options.apply_layout and params['layout_theme'] != 'Default': try: fn = 'web2py.plugin.layout_%s.w2p' % params['layout_theme'] theme = urllib.urlopen(LAYOUTS_APP + '/static/plugin_layouts/plugins/' + fn) plugin_install(app, theme, request, fn) except: session.flash = T("unable to download layout") ### apply plugins for plugin in params['plugins']: try: plugin_name = 'web2py.plugin.' + plugin + '.w2p' stream = urllib.urlopen(PLUGINS_APP + '/static/' + plugin_name) plugin_install(app, stream, request, plugin_name) except Exception as e: session.flash = T("unable to download plugin: %s" % plugin) ### write configuration file into newapp/models/0.py model = os.path.join(request.folder, '..', app, 'models', '0.py') file = open_file(model, 'w') try: file.write("from gluon.storage import Storage\n") file.write("settings = Storage()\n\n") file.write("settings.migrate = True\n") for key, value in session.app['params']: file.write("settings.%s = %s\n" % (key, repr(value))) finally: file.close() ### write configuration file into newapp/models/menu.py if options.generate_menu: model = os.path.join(request.folder, '..', app, 'models', 'menu.py') file = open_file(model, 'w') try: file.write(make_menu(session.app['pages'])) finally: file.close() ### customize the auth_user table model = os.path.join(request.folder, '..', app, 'models', 'db.py') fix_db(model) ### create newapp/models/db_wizard.py if options.generate_model: model = os.path.join(request.folder, '..', app, 'models', 'db_wizard.py') file = open_file(model, 'w') try: file.write( '### we prepend t_ to tablenames and f_ to fieldnames for disambiguity\n\n' ) tables = sort_tables(session.app['tables']) for table in tables: if table == 'auth_user': continue file.write(make_table(table, session.app['table_' + table])) finally: file.close() model = os.path.join(request.folder, '..', app, 'models', 'db_wizard_populate.py') if os.path.exists(model): os.unlink(model) if options.populate_database and session.app['tables']: file = open_file(model, 'w') try: file.write(populate(session.app['tables'])) finally: file.close() ### create newapp/controllers/default.py if options.generate_controller: controller = os.path.join(request.folder, '..', app, 'controllers', 'default.py') file = open_file(controller, 'w') try: file.write("""# -*- coding: utf-8 -*- ### required - do no delete def user(): return dict(form=auth()) def download(): return response.download(request,db) def call(): return service() ### end requires """) for page in session.app['pages']: file.write(make_page(page, session.app.get('page_' + page, ''))) finally: file.close() ### create newapp/views/default/*.html if options.generate_views: for page in session.app['pages']: view = os.path.join(request.folder, '..', app, 'views', 'default', page + '.html') file = open_file(view, 'w') try: file.write(make_view(page, session.app.get('page_' + page, ''))) finally: file.close() if options.erase_database: path = os.path.join(request.folder, '..', app, 'databases', '*') for file in glob.glob(path): os.unlink(file)
def install_plugins(**urls): """ Installs required plugins from urls """ for name, url in urls.items(): plugin_install(request.application, urlopen(url), request, "web2py.plugin.%s.w2p" % name) print "Required plugin %s installed successfully!" % name