cwconfig.py
changeset 5159 2543cfa5d54a
parent 5121 a63d7886fcf5
parent 5143 43afbdd5c8b4
child 5163 3079b8345915
equal deleted inserted replaced
5158:5e9055b8c10a 5159:2543cfa5d54a
     1 # -*- coding: utf-8 -*-
     1 # -*- coding: utf-8 -*-
     2 """common configuration utilities for cubicweb
     2 #:organization: Logilab
     3 
     3 #:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     4 :organization: Logilab
     4 #:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     5 #:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 
     7 
     7 # docstring included in doc/book/en/admin/setup.rst
     8 
     8 """
     9 If cubicweb is a mercurial checkout (eg `CWDEV` is true), located in
     9 .. _ResourceMode:
    10 `CW_SOFTWARE_ROOT`:
    10 
    11 
    11 Resource mode
    12  * main cubes directory is `<CW_SOFTWARE_ROOT>/../cubes`. You can specify
    12 -------------
    13    another one with `CW_INSTANCES_DIR` environment variable or simply add some
    13 
    14    other directories by using `CW_CUBES_PATH`.
    14 A resource *mode* is a predifined set of settings for various resources
    15 
    15 directories, such as cubes, instances, etc. to ease development with the
    16  * cubicweb migration files are by default searched in
    16 framework. There are two running modes with |cubicweb|:
    17    `<CW_SOFTWARE_ROOT>/misc/migration` instead of
    17 
    18    `<install prefix>/share/cubicweb/migration/`
    18 * 'user', resources are searched / created in the user home directory:
    19 
    19 
    20  * Cubicweb will start in 'user' mode (see below)
    20   - instances are stored in :file:`~/etc/cubicweb.d`
    21 
    21   - temporary files (such as pid file) in :file:`/tmp`
    22 
    22 
    23 On startup, Cubicweb is using a specific *mode*. A mode corresponds to some
    23 * 'system', resources are searched / created in the system directories (eg
    24 default setting for various resource directories. There are currently 2 main
    24   usually requiring root access):
    25 modes : 'system', for system wide installation, and 'user', fur user local
    25 
    26 installation (e.g. no root privileges).
    26   - instances are stored in :file:`<INSTALL_PREFIX>/etc/cubicweb.d`
    27 
    27   - temporary files (such as pid file) in :file:`/var/run/cubicweb`
    28 'user' mode is activated automatically when cubicweb is a mercurial checkout
    28 
    29 (e.g.  has a .hg directory). You can also force mode by using the `CW_MODE`
    29   where `<INSTALL_PREFIX>` is the detected installation prefix ('/usr/local' for
    30 environment variable, to:
    30   instance).
    31 
    31 
    32 * use system wide installation but user specific instances and all, without root
    32 
    33   privileges on the system (`export CW_MODE=user`)
    33 Notice that each resource path may be explicitly set using an environment
    34 
    34 variable if the default doesn't suit your needs. Here are the default resource
    35 * use local checkout of cubicweb on system wide instances (requires root
    35 directories that are affected according to mode:
    36   privileges on the system (`export CW_MODE=system`)
       
    37 
       
    38  Here is the default resource directories settings according to mode:
       
    39 
    36 
    40 * 'system': ::
    37 * 'system': ::
    41 
    38 
    42         CW_INSTANCES_DIR = /etc/cubicweb.d/
    39         CW_INSTANCES_DIR = <INSTALL_PREFIX>/etc/cubicweb.d/
    43         CW_INSTANCES_DATA_DIR = /var/lib/cubicweb/instances/
    40         CW_INSTANCES_DATA_DIR = /var/lib/cubicweb/instances/
    44         CW_RUNTIME_DIR = /var/run/cubicweb/
    41         CW_RUNTIME_DIR = /var/run/cubicweb/
    45 
    42 
    46  * 'user': ::
    43  * 'user': ::
    47 
    44 
    48         CW_INSTANCES_DIR = ~/etc/cubicweb.d/
    45         CW_INSTANCES_DIR = ~/etc/cubicweb.d/
    49         CW_INSTANCES_DATA_DIR = ~/etc/cubicweb.d/
    46         CW_INSTANCES_DATA_DIR = ~/etc/cubicweb.d/
    50         CW_RUNTIME_DIR = /tmp
    47         CW_RUNTIME_DIR = /tmp
    51 
    48 
       
    49 Cubes search path is also affected, see the :ref:Cube section.
       
    50 
       
    51 By default, the mode automatically set to 'user' if a :file:`.hg` directory is found
       
    52 in the cubicweb package, else it's set to 'system'. You can force this by setting
       
    53 the :envvar:`CW_MODE` environment variable to either 'user' or 'system' so you can
       
    54 easily:
       
    55 
       
    56 * use system wide installation but user specific instances and all, without root
       
    57   privileges on the system (`export CW_MODE=user`)
       
    58 
       
    59 * use local checkout of cubicweb on system wide instances (requires root
       
    60   privileges on the system (`export CW_MODE=system`)
       
    61 
       
    62 If you've a doubt about the mode you're currently running, check the first line
       
    63 outputed by the :command:`cubicweb-ctl list` command.
       
    64 
       
    65 Also, if cubicweb is a mercurial checkout located in `<CW_SOFTWARE_ROOT>`:
       
    66 
       
    67 * main cubes directory is `<CW_SOFTWARE_ROOT>/../cubes`. You can specify
       
    68   another one with :envvar:`CW_INSTANCES_DIR` environment variable or simply
       
    69   add some other directories by using :envvar:`CW_CUBES_PATH`
       
    70 
       
    71 * cubicweb migration files are searched in `<CW_SOFTWARE_ROOT>/misc/migration`
       
    72   instead of `<INSTALL_PREFIX>/share/cubicweb/migration/`.
       
    73 
       
    74 
       
    75 .. _ConfigurationEnv:
       
    76 
       
    77 Environment configuration
       
    78 -------------------------
       
    79 
       
    80 Python
       
    81 ``````
       
    82 
       
    83 If you installed |cubicweb| by cloning the Mercurial forest or from source
       
    84 distribution, then you will need to update the environment variable PYTHONPATH by
       
    85 adding the path to the forest `cubicweb`:
       
    86 
       
    87 Add the following lines to either :file:`.bashrc` or :file:`.bash_profile` to
       
    88 configure your development environment ::
       
    89 
       
    90     export PYTHONPATH=/full/path/to/cubicweb-forest
       
    91 
       
    92 If you installed |cubicweb| with packages, no configuration is required and your
       
    93 new cubes will be placed in `/usr/share/cubicweb/cubes` and your instances will
       
    94 be placed in `/etc/cubicweb.d`.
       
    95 
       
    96 
       
    97 CubicWeb
       
    98 ````````
       
    99 
       
   100 Here are all environment variables that may be used to configure |cubicweb|:
    52 
   101 
    53 .. envvar:: CW_MODE
   102 .. envvar:: CW_MODE
    54    Resource mode: user or system
   103 
       
   104    Resource mode: user or system, as explained in :ref:ResourceMode.
    55 
   105 
    56 .. envvar:: CW_CUBES_PATH
   106 .. envvar:: CW_CUBES_PATH
    57    Augments the default search path for cubes
   107 
       
   108    Augments the default search path for cubes. You may specify several
       
   109    directories using ':' as separator (';' under windows environment).
    58 
   110 
    59 .. envvar:: CW_INSTANCES_DIR
   111 .. envvar:: CW_INSTANCES_DIR
    60    Directory where cubicweb instances will be found
   112 
       
   113    Directory where cubicweb instances will be found.
    61 
   114 
    62 .. envvar:: CW_INSTANCES_DATA_DIR
   115 .. envvar:: CW_INSTANCES_DATA_DIR
    63    Directory where cubicweb instances data will be written
   116 
       
   117    Directory where cubicweb instances data will be written (backup file...)
    64 
   118 
    65 .. envvar:: CW_RUNTIME_DIR
   119 .. envvar:: CW_RUNTIME_DIR
       
   120 
    66    Directory where pid files will be written
   121    Directory where pid files will be written
    67 
       
    68 
       
    69 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
       
    70 """
   122 """
    71 __docformat__ = "restructuredtext en"
   123 __docformat__ = "restructuredtext en"
    72 _ = unicode
   124 _ = unicode
    73 
   125 
    74 import sys
   126 import sys