nagare.admin package¶
Subpackages¶
Submodules¶
nagare.admin.admin_app module¶
This is the admin application. By default, when launched, it’s mapped to url
/admin
and /
.
The default view of this application is the administration view of the framework.
-
class
nagare.admin.admin_app.
Admin
(apps)¶ Bases:
object
The root component of the admin application
It loads all the components registered under the
nagare.admin
entry point and renders them into its view.
-
class
nagare.admin.admin_app.
WSGIApp
(root_factory)¶ Bases:
nagare.wsgi.WSGIApp
The admin application
Read the additional boolean parameter
as_root
into the[application]
section. IfTrue
, mappes itself to the/
url.-
create_root
()¶ Create an
admin
object- Return:
- the admin object
-
set_config
(config_filename, conf, error)¶ Read the value of the
as_root
parameter and keeps the list of all the launched applications- In:
config_filename
– the path to the configuration fileconfig
– theConfigObj
object, created from the configuration fileerror
– the function to call in case of configuration errors
-
set_publisher
(publisher)¶ Read the value of the
as_root
parameter and keeps a reference to the publisher- In:
publisher
– the publisher of the application
-
-
nagare.admin.admin_app.
render
(self, h, comp, *args)¶ Aggregates all the default views of the components
nagare.admin.command module¶
The nagare-admin
executable
The run()
function is called by the nagare-admin
console script, created
by setuptools
-
class
nagare.admin.command.
Command
¶ Bases:
object
The base class of all the commands
-
desc
= ''¶
-
get_description
(commands)¶ Return the description of the command
- In:
commands
– parent commands of this command
- Return:
- A list with a single tuple (full name of the command, description of the command)
-
parse
(argv, commands)¶ Parse the command line
- In:
argv
– list of the arguments on the command linecommands
– parent commands of this command
- Return:
- the Unix command status
-
classmethod
run
(parser, options, args)¶ Command code
- In:
parser
– thisoptparse.OptionParser
has parsed the command lineoptions
– the options read on the command lineargs
– arguments left on the command line
- Return:
- the Unix command status
-
classmethod
set_options
(parser)¶ Define the available options for this command
- Out:
parser
– thisoptparse.OptionParser
will parse the command line
-
-
class
nagare.admin.command.
Commands
¶ Bases:
dict
Command with sub-commands
-
add_command
(names, command)¶ Define a sub-commands
- In:
names
– list of names of the sub-commandcommand
– the sub-command object
-
get_description
(commands)¶ Return the description of the command
- In:
commands
– parent commands of this command
- Return:
- A list of tuples (full name of the sub-command, description of the sub-command)
-
parse
(argv, commands)¶ Parse the command line
- In:
argv
– list of the arguments on the command linecommands
– parent commands of this command
- Return:
- the Unix command status
-
usage
(commands, error=None)¶ Print the usage of this command on
stderr
- In:
commands
– parent commands of this commanderror
- optional error message
- Return:
- no return, interpreter exit
-
-
nagare.admin.command.
run
(entry_point_section='nagare.commands')¶ Dispatcher for the
nagare-admin
commandsThe commands are classes, registered under the
entry_point_section
entry point
nagare.admin.create module¶
The create
administrative command
Generate the directory structure and the skeleton of an application.
-
class
nagare.admin.create.
Create
¶ Bases:
nagare.admin.command.Command
-
desc
= 'Create an application skeleton'¶
-
static
run
(options, args)¶
-
static
set_options
()¶
-
-
nagare.admin.create.
create_app_py
(filename, params)¶
-
nagare.admin.create.
create_conf
(filename, params)¶
-
nagare.admin.create.
create_empty_file
(filename)¶
-
nagare.admin.create.
create_manifest_in
(filename)¶
-
nagare.admin.create.
create_models_py
(filename)¶
-
nagare.admin.create.
create_or_update
(path, create=None, update=None, *args, **kw)¶
-
nagare.admin.create.
create_setup_py
(filename, params)¶
-
nagare.admin.create.
run
(parser, options, args)¶
-
nagare.admin.create.
set_options
(optparser)¶
-
nagare.admin.create.
upgrade_setup_cfg
(filename)¶
-
nagare.admin.create.
upgrade_setup_py
(filename, params, setup_py=None)¶
nagare.admin.create_rules module¶
The create-rules
administrative command
Generate the rewrite rules for the apache, lighttpd or nginx http servers, to let them serve the static contents of the launched applications, instead of the applications themselves.
-
class
nagare.admin.create_rules.
CreateRules
¶ Bases:
nagare.admin.command.Command
-
desc
= 'Create the rewrite rules'¶
-
static
run
(options, args)¶
-
static
set_options
()¶ Register the possible options
They are:
-a
or--apache
to generate the apache rules (default)-l
or--lighttpd
to generate the lighttpd rules-n
or--nginx
to generate the nginx rules
- In:
optparser
– the options parser
-
-
nagare.admin.create_rules.
create_rules
(app_names, error)¶ Generate the rewrite rules for the given registered applications
- In:
app_names
– list of the applications, read from the command lineerror
– the function to call in case of configuration errors
- Return:
- list of tuples (application, directory of its static contents)
-
nagare.admin.create_rules.
generate_apache_rules
(app_names, error)¶ Generate the apache rewrite rules for the given registered applications
- In:
app_names
– list of the applications, read from the command lineerror
– the function to call in case of configuration errors
- Return:
- yield the apache configuration file fragment
-
nagare.admin.create_rules.
generate_lighttpd_rules
(app_names, error)¶ Generate the lighttpd rewrite rules for the given registered applications
- In:
app_names
– list of the applications, read from the command lineerror
– the function to call in case of configuration errors
- Return:
- yield the lighttpd configuration file fragment
-
nagare.admin.create_rules.
generate_nginx_rules
(app_names, error)¶ Generate the nginx rewrite rules for the given registered applications
- In:
app_names
– list of the applications, read from the command lineerror
– the function to call in case of configuration errors
- Return:
- yield the nginx configuration file fragment
-
nagare.admin.create_rules.
run
(parser, options, args)¶
-
nagare.admin.create_rules.
set_options
(optparser)¶ Register the possible options
They are:
-a
or--apache
to generate the apache rules (default)-l
or--lighttpd
to generate the lighttpd rules-n
or--nginx
to generate the nginx rules
- In:
optparser
– the options parser
nagare.admin.db module¶
The create-db
and drop-db
administrative commands
Create or delete the database tables of an application
-
class
nagare.admin.db.
DBCreate
¶ Bases:
nagare.admin.command.Command
-
desc
= 'Create the database of an application'¶
-
static
run
(options, args)¶ Create the database tables of the application
If the
--drop
option is on, delete the existing tables before to re-create themIf 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 fileoptions
– options in the command linesargs
– arguments in the command lines : application name
-
static
set_options
()¶
-
-
class
nagare.admin.db.
DBDrop
¶ Bases:
nagare.admin.command.Command
-
desc
= 'Drop the database of an application'¶
-
static
run
(options, args)¶ Delete the database tables of the application
- In:
parser
– the optparse.OptParser object used to parse the configuration fileoptions
– options in the command linesargs
– arguments in the command lines : application name
-
static
set_options
()¶
-
-
nagare.admin.db.
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 themIf 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 fileoptions
– options in the command linesargs
– arguments in the command lines : application name
-
nagare.admin.db.
drop
(parser, options, args)¶ Delete the database tables of the application
- In:
parser
– the optparse.OptParser object used to parse the configuration fileoptions
– options in the command linesargs
– arguments in the command lines : application name
-
nagare.admin.db.
read_options
(debug, args, error)¶ Activate all the database metadata objects of an application
Several metadata objects can be activated if there are sub-sections into the [database] section.
- In:
debug
– flag to display the generated SQL statementsargs
– arguments in the command lines: application to activateerror
– the function to call in case of configuration errors
- Return:
- tuples (metadata object, populate function)
nagare.admin.info module¶
The info
administrative command
Display informations about the framework environment
-
class
nagare.admin.info.
Info
¶ Bases:
nagare.admin.command.Command
Display informations about the framework environment
-
desc
= 'Display various informations'¶
-
static
run
(options, args)¶ Display the informations
- In:
parser
– the optparse.OptParser object used to parse the configuration fileoptions
– options in the command linesargs
– arguments in the command lines
-
nagare.admin.reference module¶
Import an object from a string reference
The possible reference syntaxes are:
'python <module>:<object>'
– loads an object from a Python module (for example:'python os.path:isfile'
)'<module>:<object>'
– same as'python <module>:<object>'
'file <file>:<object>'
– loads an object from a file (for example:'file /tmp/counter.py:Counter'
)'egg <dist>:<app>'
– loads the registered application<app>
from the<dist>
distribution (for example:'egg nagare:admin'
or'egg nagare.examples:wiki'
)'app <app>'
– load the registered application<app>
(for example:'app examples'
)
-
nagare.admin.reference.
load_app
(app, _)¶ Load a registered application
- In:
app
– name of the application_
– unused*
- Return:
- (the application, the distribution of the application)
-
nagare.admin.reference.
load_egg
(dist, app)¶ Load a registered application of a distribution
- In:
dist
– name of the distributionapp
– name of the application
- Return:
- (the application, the distribution of the application)
-
nagare.admin.reference.
load_entry_point
(app, entry_point)¶ Load an object registered under an entry point
- In:
app
– name of the objectentry_point
– name of the entry_point
- Return:
- (the object, the distribution of the object)
-
nagare.admin.reference.
load_file
(filename, app)¶ Load an object from a file
- In:
filename
– name of the fileapp
– name of the object to load
- Return:
- (the object, None)
-
nagare.admin.reference.
load_module
(module, app)¶ Load an object from a Python module
- In:
module
– name of the moduleapp
– name of the object to load
- Return:
- (the object, None)
-
nagare.admin.reference.
load_object
(reference)¶ Load an object from a reference
- In:
reference
– reference as a string
- Return:
- a tuple (object loaded, distribution where this object is located or
None
)
- a tuple (object loaded, distribution where this object is located or
nagare.admin.reloader module¶
Utiliy module that watches for files modification and exits the current process when this event happens.
This module is derivated from Ian Bicking’s one to only exit if there is no importation errors into the modified file.
-
class
nagare.admin.reloader.
Monitor
(poll_interval, included_files, excluded_directories)¶ Bases:
object
-
check_modification
(filename)¶
-
check_modifications
()¶
-
periodic_reload
()¶
-
watch_file
(filename)¶
-
-
nagare.admin.reloader.
install
(poll_interval=1, included_files=(), excluded_directories=())¶
-
nagare.admin.reloader.
restart_with_monitor
()¶
nagare.admin.serve module¶
The serve
administrative command
Launch one or more applications.
-
class
nagare.admin.serve.
Serve
¶ Bases:
nagare.admin.command.Command
-
desc
= 'Launch applications'¶
-
static
run
(options, args)¶ Launch one or more applications
- In:
parser
– theoptparse.OptParser
object used to parse the configuration fileoptions
– options in the command linesargs
– arguments in the command lines
The arguments are a list of names of registered applications or paths to application configuration files.
-
static
set_options
()¶
-
-
nagare.admin.serve.
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 applicationoptions
– options in the command lineconfig_filename
– the path to the configuration fileconfig
– theConfigObj
object, created from the configuration fileerror
– the function to call in case of configuration errors
- Return:
- the wsgi pipe
-
nagare.admin.serve.
debugged_app
(app)¶
-
nagare.admin.serve.
get_file_from_package
(package, path)¶ Return the path of a static content, from a setuptools package
- In:
package
– the setuptools package of a registered applicationpath
– the url path of the wanted static content
- Return:
- the path of the static content
-
nagare.admin.serve.
get_file_from_root
(root, path)¶ Return the path of a static content, from a filesystem root
- In:
root
– the path of the rootpath
– the url path of the wanted static content
- Return:
- the path of the static content
-
nagare.admin.serve.
read_publisher_options
(parser, options)¶ Read the configuration file for the publisher
This configuration file is given with the
-c``or ``--config
option- In:
parser
– theoptparse.OptParser
object used to parse the configuration fileoptions
– options in the command line
- Return:
- a
ConfigObj
with the publisher parameters
- a
-
nagare.admin.serve.
run
(parser, options, args)¶ Launch one or more applications
- In:
parser
– theoptparse.OptParser
object used to parse the configuration fileoptions
– options in the command linesargs
– arguments in the command lines
The arguments are a list of names of registered applications or paths to application configuration files.
-
nagare.admin.serve.
set_options
(optparser)¶
nagare.admin.serve_module module¶
The serve-module
administrative command
Launch a standalone (without any database connection) application, in debug mode.
No configuration file in read. The only possible parameters are given on the
command line and are (run nagare-admin serve-module
to see them):
- the host
- the port
- the web debug mode
- the reload mode
Also no static contents can be served.
Warning
Use this command in development mode or to quickly test a piece code. Don’t run a production application with this command
-
class
nagare.admin.serve_module.
Serve
¶ Bases:
nagare.admin.command.Command
-
desc
= 'Launch a python module'¶
-
static
run
(options, args)¶ launch an object
- In:
parser
– theoptparse.OptParser
object used to parse the configuration fileoptions
– options in the command linesargs
– 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.reference
. For example,/tmp/counter.py:Counter
is the path to the classCounter
of the moduletmp.counter.py
-
static
set_options
()¶
-
-
nagare.admin.serve_module.
debugged_app
(app)¶
-
nagare.admin.serve_module.
get_file_from_package
(package, path)¶ Return the path of a static content, located into a setuptools package
- In:
package
– the setuptools package of a registered applicationpath
– the url path of the wanted static content
- Return:
- the path of the static content
-
nagare.admin.serve_module.
run
(parser, options, args)¶ launch an object
- In:
parser
– theoptparse.OptParser
object used to parse the configuration fileoptions
– options in the command linesargs
– 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.reference
. For example,/tmp/counter.py:Counter
is the path to the classCounter
of the moduletmp.counter.py
-
nagare.admin.serve_module.
set_options
(optparser)¶
nagare.admin.shell module¶
The shell
and batch
administrative commands
The shell
command launches an interactive Python shell.
The batch
command execute Python statements from a file.
In both cases:
- the global variable
apps
is a dictionary of application name -> application object- the global variable
session
is the database session- the metadata of the applications are activated
-
class
nagare.admin.shell.
Batch
¶ Bases:
nagare.admin.command.Command
-
desc
= 'Execute Python statements from a file'¶
-
static
run
(options, args)¶ Execute Python statements a file
- In:
parser
– theoptparse.OptParser
object used to parse the configuration fileoptions
– options in the command linesargs
– arguments in the command lines
The arguments are the name of a registered applications, or the path to an applications configuration file, followed by the paths of a file to execute
-
static
set_options
()¶
-
-
class
nagare.admin.shell.
IPythonShellV1
(ipython, banner, app_names, ns)¶ Bases:
object
A IPython < 0.11 interpreter
-
class
nagare.admin.shell.
IPythonShellV2
(ipython, banner, app_names, ns)¶ Bases:
object
A IPython >= 0.11 interpreter
-
class
nagare.admin.shell.
IPythonShellV3
(ipython, banner, app_names, ns)¶ Bases:
object
A IPython >= 5.0 interpreter
-
class
nagare.admin.shell.
PythonShell
(banner, app_names, ns)¶ Bases:
code.InteractiveConsole
A plain Python interpreter
-
raw_input
(prompt)¶
-
-
class
nagare.admin.shell.
PythonShellWithHistory
(banner, app_names, ns)¶ Bases:
nagare.admin.shell.PythonShell
A plain Python interpreter with a readline history
-
class
nagare.admin.shell.
Shell
¶ Bases:
nagare.admin.command.Command
-
desc
= 'Launch a shell'¶
-
static
run
(options, args)¶ Launch an interactive shell
- In:
parser
– theoptparse.OptParser
object used to parse the configuration fileoptions
– options in the command lineargs
– arguments in the command line
The arguments are a list of names of registered applications or paths to applications configuration files.
-
static
set_options
()¶
-
-
nagare.admin.shell.
activate_application
(cfgfile, debug, error)¶ Initialize one application
- In:
cfgfile
– path to an application configuration file or name of a registered applicationdebug
– enable the display of the generated SQL statementserror
– the function to call in case of configuration errors
- Return:
- database session
- application name
- application object
-
nagare.admin.shell.
activate_applications
(cfgfiles, debug, error)¶ Initialize applications
- In:
cfgfile
– paths to application configuration files or names of registered applicationsdebug
– enable the display of the generated SQL statementserror
– the function to call in case of configuration errors
- Return:
- database session
- {application name -> application object}
-
nagare.admin.shell.
batch
(parser, options, args)¶ Execute Python statements a file
- In:
parser
– theoptparse.OptParser
object used to parse the configuration fileoptions
– options in the command linesargs
– arguments in the command lines
The arguments are the name of a registered applications, or the path to an applications configuration file, followed by the paths of a file to execute
-
nagare.admin.shell.
create_globals
(cfgfiles, debug, error)¶ Return a namespace with the initialized applications
- In:
cfgfile
– paths to application configuration files or names of registered applicationsdebug
– enable the display of the generated SQL statementserror
– the function to call in case of configuration errors
- Return:
- the namespace with the
apps
andsession
variables defined
- the namespace with the
-
nagare.admin.shell.
create_python_shell
(ipython, banner, app_names, ns)¶ Shell factory
Create a shell according to the installed modules (
readline
andipython
)- In:
ipython
– does the user want a IPython shell?banner
– banner to displayapp_names
– names of the activated applicationsns
– the namespace with theapps
andsession
variables defined
-
nagare.admin.shell.
set_batch_options
(optparser)¶
-
nagare.admin.shell.
set_shell_options
(optparser)¶
-
nagare.admin.shell.
shell
(parser, options, args)¶ Launch an interactive shell
- In:
parser
– theoptparse.OptParser
object used to parse the configuration fileoptions
– options in the command lineargs
– arguments in the command line
The arguments are a list of names of registered applications or paths to applications configuration files.
nagare.admin.util module¶
Various tools used be the administrative commands
-
nagare.admin.util.
activate_WSGIApp
(app, cfgfile, aconf, error, project_name='', static_path=None, static_url=None, data_path=None, publisher=None, sessions_manager=None, debug=False)¶ Set all the properties of a WSGIApp application
- In:
app
– the WSGIApp application or the application root object factorycfgfile
– the path to the configuration fileaconf
– theConfigObj
object, created from the configuration fileerror
– the function to call in case of configuration errorsproject_name
– name of the distutils distribution where the app is locatedstatic_path
– the directory where the static contents of the application are locatedstatic_url
– the url of the static contents of the applicationdata_path
– the directory where the data of the application are locatedpublisher
– the publisher of the applicationsession_manager
– the sessions managerdebug
– flag to display the generated SQL statements
- Return:
- a tuple:
- the
wsgi.WSGIApp
object - tuples (application databases settings, application databases populate functions)
- the
-
nagare.admin.util.
get_database
(conf, debug)¶ Read the database settings
The location of the metadata object is read from the configuration file
- In:
conf
– theConfigObj
object, created from the configuration filedebug
– debug mode for the database engine
- Return:
- the tuple: - metadata object - database uri - database debug mode - database engines settings
-
nagare.admin.util.
read_application
(cfgfile, error)¶ Read the configuration file for the application and create the application object
- In:
cfgfile
– name of a registered application or path to an application configuration fileerror
– the function to call in case of configuration errors
- Return:
- a tuple:
- name of the application configuration file
- the application object
- the distribution of the application
- a
ConfigObj
of the application parameters
- a tuple:
-
nagare.admin.util.
read_application_options
(cfgfile, error, default={})¶ Read the configuration file for the application
- In:
cfgfile
– path to an application configuration fileerror
– the function to call in case of configuration errorsdefault
– optional default values
- Return:
- a
ConfigObj
of the application parameters
- a