Example #1
0
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)
Example #2
0
 def test_admin_compile(self):
     #apps = ['welcome', 'admin', 'examples']
     request = Request(env={})
     request.application = 'a'
     request.controller = 'c'
     request.function = 'f'
     request.folder = 'applications/admin'
     apps = ['welcome']
     for appname in apps:
         appname_path = os.path.join(os.getcwd(), 'applications', appname)
         self.assertEqual(app_compile(appname_path, request), None)
         # remove any existing test_app
         new_app = 'test_app_%s' % (appname)
         if (os.path.exists('applications/%s' % (new_app))):
             shutil.rmtree('applications/%s' % (new_app))
         self.assertEqual(app_create(new_app, request), True)
         self.assertEqual(
             os.path.exists(
                 'applications/test_app_%s/controllers/default.py' %
                 (appname)), True)
         self.assertEqual(app_cleanup(new_app, request), True)
         self.assertEqual(app_uninstall(new_app, request), True)
     self.assertNotEqual(
         check_new_version(global_settings.web2py_version,
                           WEB2PY_VERSION_URL), -1)
     return
Example #3
0
    def app_new(self, name):
        # Fake a request
        from gluon.admin import app_create
        from gluon.globals import Request
        request = Request()
        request.folder = opj(self.w2p_path, 'applications', 'admin')

        ret = app_create(name, request)
        if ret:
            self.tree.rebuild_tree()
            return ret
        import errno
        raise IOError(errno.ENOENT, "'welcome.w2p' probably missing",
                opj(self.w2p_path, 'welcome.w2p'))
    def test_admin_compile(self):
        request = Request(env={})
        request.application = 'a'
        request.controller = 'c'
        request.function = 'f'
        request.folder = 'applications/admin'
        # remove any existing test app
        app_path = os.path.join('applications', test_app2_name)
        if os.path.exists(app_path):
            shutil.rmtree(app_path)

        self.assertTrue(app_create(test_app2_name, request))
        self.assertTrue(os.path.exists('applications/%s/controllers/default.py' % test_app2_name))
        self.assertIsNone(app_compile(test_app2_name, request))
        self.assertTrue(app_cleanup(test_app2_name, request))
        self.assertTrue(app_uninstall(test_app2_name, request))
Example #5
0
 def OnMenuAppNew(self, evt):
     if not self.panel:
         if not self.ChooseApp():
             return
     p = None
     dlg = wx.TextEntryDialog(self, 'App name', 'App name', '')
     if dlg.ShowModal() == wx.ID_OK:
         p = dlg.GetValue().strip()
     dlg.Destroy()
     if p:
         from gluon.admin import app_create
         from gluon.globals import Request
         request = Request()
         request.folder = opj(self.w2p_path, 'applications', 'admin')
         ret = app_create(p, request)
         if not ret:
             wx.MessageDialog(self, 'Could not create app %s' % p, "error").ShowModal()
         else:
             self.panel.tree.rebuild_tree()
Example #6
0
 def test_admin_compile(self):
     #apps = ['welcome', 'admin', 'examples']
     request = Request(env={})
     request.application = 'a'
     request.controller = 'c'
     request.function = 'f'
     request.folder = 'applications/admin'
     apps = ['welcome']
     for appname in apps:
         appname_path = os.path.join(os.getcwd(), 'applications', appname)
         self.assertEqual(app_compile(appname_path, request), None)
         # remove any existing test_app
         new_app = 'test_app_%s' % (appname)
         if(os.path.exists('applications/%s' % (new_app))):
             shutil.rmtree('applications/%s' % (new_app))
         self.assertEqual(app_create(new_app, request), True)
         self.assertEqual(os.path.exists('applications/test_app_%s/controllers/default.py' % (appname)), True)
         self.assertEqual(app_cleanup(new_app, request), True)
         self.assertEqual(app_uninstall(new_app, request), True)
     self.assertNotEqual(check_new_version(global_settings.web2py_version, WEB2PY_VERSION_URL), -1)
     return
Example #7
0
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)
Example #8
0
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)
Example #9
0
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)