def run(parser, options, args): """launch an object In: - ``parser`` -- the ``optparse.OptParser`` object used to parse the configuration file - ``options`` -- options in the command lines - ``args`` -- arguments in the command lines The unique argument is the path of the object to launch. The path syntax is described into the module ``nagare.admin.util``. For example, ``/tmp/counter.py:Counter`` is the path to the class ``Counter`` of the module ``tmp.counter.py`` """ if len(args) != 2: parser.error('Bad number of arguments') if 'nagare_reloaded' not in os.environ: return reloader.restart_with_monitor() # With the ``serve-module`` command, the automatic reloader is always activated reloader.install(excluded_directories=(pkg_resources.get_default_cache(),)) # Load the object if os.path.sep in args[0]: path = 'file ' + args[0] else: path = 'python ' + args[0] app = util.load_object(path)[0] # Wrap it into a WSGIApp app = wsgi.create_WSGIApp(app) # Always use the standalone publisher (Python HTTP server) publishers = dict([(entry.name, entry) for entry in pkg_resources.iter_entry_points('nagare.publishers')]) publisher = publishers['standalone'].load()() wsgi_pipe = debugged_app(app) if options.debug else app publisher.register_application(args[0], args[1], app, wsgi_pipe) app.set_config('', { 'application' : { 'redirect_after_post' : False, 'name' : args[1], 'always_html' : True } }, None) app.set_publisher(publisher) # Always use the standalone session manager (in memory sessions) sessions_managers = dict([(entry.name, entry) for entry in pkg_resources.iter_entry_points('nagare.sessions')]) sessions_manager = sessions_managers['standalone'].load()() app.set_sessions_manager(sessions_manager) # Set the application logger level to DEBUG log.configure({ 'logger' : { 'level' : 'DEBUG' } }, args[1]) log.activate() log.set_logger('nagare.application.'+args[1]) # The static contents of the framework are served by the standalone server publisher.register_static('nagare', lambda path, r=pkg_resources.Requirement.parse('nagare'): get_file_from_package(r, path)) # Launch the object publisher.serve(None, dict(host=options.host, port=options.port), None)
def create(parser, options, args): """Create the database tables of the application If the ``--drop`` option is on, delete the existing tables before to re-create them If the ``--no-populate`` option is off, call the populate function (if it exists) after the creation of the tables In: - ``parser`` -- the optparse.OptParser object used to parse the configuration file - ``options`` -- options in the command lines - ``args`` -- arguments in the command lines : application name """ for (database_settings, populate) in read_options(options.debug, args, parser.error): database.set_metadata(*database_settings) with database.session.begin(): if options.drop: database_settings[0].drop_all() database_settings[0].create_all() if options.populate and populate: util.load_object(populate)[0]()
def create_wsgi_pipe(app, options, config_filename, config, error): """Wrap the application into one or more WSGI "middlewares" to create a WSGI pipe In: - ``app`` -- the application - ``options`` -- options in the command line - ``config_filename`` -- the path to the configuration file - ``config`` -- the ``ConfigObj`` object, created from the configuration file - ``error`` -- the function to call in case of configuration errors Return: - the wsgi pipe """ if options.debug or config['application']['debug']: app = debugged_app(app) wsgi_pipe = config['application']['wsgi_pipe'] if not wsgi_pipe: return app return util.load_object(wsgi_pipe)[0](app, options, config_filename, config, error)