Package trac :: Module env :: Class Environment

Class Environment

source code

           object --+    
                    |    
       core.Component --+
                        |
           object --+   |
                    |   |
core.ComponentManager --+
                        |
                       Environment
Known Subclasses:

Trac environment manager.

Trac stores project information in a Trac environment. It consists of a
directory structure containing among other things:
 * a configuration file
 * an SQLite database (stores tickets, wiki pages...)
 * project-specific templates and plugins
 * wiki and ticket attachments

Nested Classes

Inherited from core.Component: __metaclass__

Instance Methods
 
__init__(self, path, create=False, options=[])
Initialize the Trac environment.
source code
 
backup(self, dest=None)
Simple SQLite-specific backup of the database.
source code
 
component_activated(self, component)
Initialize additional member variables for components.
source code
 
create(self, options=[])
Create the basic directory structure of the environment, initialize the database and populate the configuration file with default values.
source code
 
enable_component(self, cls)
Enable a component or module.
source code
 
get_db_cnx(self)
Return a database connection from the connection pool (deprecated)
source code
 
get_htdocs_dir(self)
Return absolute path to the htdocs directory.
source code
 
get_known_users(self, cnx=None)
Generator that yields information about all known users, i.e.
source code
 
get_log_dir(self)
Return absolute path to the log directory.
source code
 
get_read_db(self)
Return a database connection for read purposes.
source code
 
get_repository(self, reponame=None, authname=None)
Return the version control repository with the given name, or the default repository if `None`.
source code
 
get_system_info(self) source code
 
get_systeminfo(self)
Return a list of (name, version) tuples describing the name and version information of external packages used by Trac and plugins.
source code
 
get_templates_dir(self)
Return absolute path to the templates directory.
source code
 
get_version(self, db=None, initial=False)
Return the current version of the database.
source code
 
is_component_enabled(self, cls)
Implemented to only allow activation of components that are not disabled in the configuration.
source code
 
needs_upgrade(self)
Return whether the environment needs to be upgraded.
source code
 
setup_config(self, load_defaults=False)
Load the configuration file.
source code
 
setup_log(self)
Initialize the logging sub-system.
source code
 
shutdown(self, tid=None)
Close the environment.
source code
 
upgrade(self, backup=False, backup_dest=None)
Upgrade database.
source code
 
verify(self)
Verify that the provided path points to a valid Trac environment directory.
source code
 
with_transaction(self, db=None)
Decorator for transaction functions.
source code

Inherited from core.ComponentManager: __contains__, __getitem__, disable_component, is_enabled

Inherited from object: __delattr__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Static Methods

Inherited from core.Component: __new__, implements

Class Variables
  base_url = <Option [trac] "base_url">
  base_url_for_redirect = <BoolOption [trac] "use_base_url_for_r...
  log_file = <Option [logging] "log_file">
  log_format = <Option [logging] "log_format">
  log_level = <Option [logging] "log_level">
  log_type = <Option [logging] "log_type">
  project_admin = <Option [project] "admin">
  project_admin_trac_url = <Option [project] "admin_trac_url">
  project_description = <Option [project] "descr">
  project_footer = <Option [project] "footer">
  project_icon = <Option [project] "icon">
  project_name = <Option [project] "name">
  project_url = <Option [project] "url">
  required = True
  secure_cookies = <BoolOption [trac] "secure_cookies">
  shared_plugins_dir = <PathOption [inherit] "plugins_dir">
Properties
  abs_href
  href
  setup_participants
List of components that implement IEnvironmentSetupParticipant
  system_info_providers
List of components that implement ISystemInfoProvider

Inherited from object: __class__

Method Details

__init__(self, path, create=False, options=[])
(Constructor)

source code 
Initialize the Trac environment.

@param path:   the absolute path to the Trac environment
@param create: if `True`, the environment is created and populated with
               default data; otherwise, the environment is expected to
               already exist.
@param options: A list of `(section, name, value)` tuples that define
                configuration options

Overrides: object.__init__

backup(self, dest=None)

source code 

Simple SQLite-specific backup of the database.

@param dest: Destination file; if not specified, the backup is stored in
a file called db_name.trac_version.bak

component_activated(self, component)

source code 

Initialize additional member variables for components.

Every component activated through the Environment object gets three member variables: env (the environment object), config (the environment configuration) and log (a logger object).

Overrides: core.ComponentManager.component_activated

create(self, options=[])

source code 

Create the basic directory structure of the environment, initialize the database and populate the configuration file with default values.

If options contains ('inherit', 'file'), default values will not be loaded; they are expected to be provided by that file or other options.

get_db_cnx(self)

source code 

Return a database connection from the connection pool (deprecated)

Use with_transaction for obtaining a writable database connection and get_read_db for anything else.

get_known_users(self, cnx=None)

source code 

Generator that yields information about all known users, i.e. users that have logged in to this Trac environment and possibly set their name and email.

This function generates one tuple for every user, of the form (username, name, email) ordered alpha-numerically by username.

@param cnx: the database connection; if ommitted, a new connection is
retrieved

get_read_db(self)

source code 

Return a database connection for read purposes.

See trac.db.api.get_read_db for detailed documentation.

get_repository(self, reponame=None, authname=None)

source code 
Return the version control repository with the given name, or the
default repository if `None`.

The standard way of retrieving repositories is to use the methods
of `RepositoryManager`. This method is retained here for backward
compatibility.

@param reponame: the name of the repository
@param authname: the user name for authorization (not used anymore,
                 left here for compatibility with 0.11)

get_version(self, db=None, initial=False)

source code 

Return the current version of the database. If the optional argument initial is set to True, the version of the database used at the time of creation will be returned.

In practice, for database created before 0.11, this will return False which is "older" than any db version number.

is_component_enabled(self, cls)

source code 

Implemented to only allow activation of components that are not disabled in the configuration.

This is called by the ComponentManager base class when a component is about to be activated. If this method returns False, the component does not get activated. If it returns None, the component only gets activated if it is located in the plugins directory of the enironment.

Overrides: core.ComponentManager.is_component_enabled

upgrade(self, backup=False, backup_dest=None)

source code 

Upgrade database.

@param backup: whether or not to backup before upgrading @param backup_dest: name of the backup file @return: whether the upgrade was performed

with_transaction(self, db=None)

source code 

Decorator for transaction functions.

See trac.db.api.with_transaction for detailed documentation.


Class Variable Details

base_url_for_redirect

Value:
<BoolOption [trac] "use_base_url_for_redirect">

Property Details

abs_href

Get Method:
_get_abs_href(self)
Set Method:
'The application URL'

href

Get Method:
_get_href(self)
Set Method:
'The application root path'

setup_participants

List of components that implement IEnvironmentSetupParticipant
Get Method:
unreachable.extensions(component) - Return a list of components that declare to implement the extension point interface.

system_info_providers

List of components that implement ISystemInfoProvider
Get Method:
unreachable.extensions(component) - Return a list of components that declare to implement the extension point interface.