src/build/html/site.html
changeset 10 1d12ff3f036a
parent 9 562bde22e104
child 11 ba0b83b57c0c
equal deleted inserted replaced
9:562bde22e104 10:1d12ff3f036a
     1 
       
     2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       
     3   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       
     4 
       
     5 <html xmlns="http://www.w3.org/1999/xhtml">
       
     6   <head>
       
     7     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       
     8     <title>PyAMS site management &#8212; PyAMS User Guide 0.1.0 documentation</title>
       
     9     <link rel="stylesheet" href="_static/pyramid.css" type="text/css" />
       
    10     <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
       
    11     <script type="text/javascript">
       
    12       var DOCUMENTATION_OPTIONS = {
       
    13         URL_ROOT:    './',
       
    14         VERSION:     '0.1.0',
       
    15         COLLAPSE_INDEX: false,
       
    16         FILE_SUFFIX: '.html',
       
    17         HAS_SOURCE:  true,
       
    18         SOURCELINK_SUFFIX: '.txt'
       
    19       };
       
    20     </script>
       
    21     <script type="text/javascript" src="_static/jquery.js"></script>
       
    22     <script type="text/javascript" src="_static/underscore.js"></script>
       
    23     <script type="text/javascript" src="_static/doctools.js"></script>
       
    24     <link rel="index" title="Index" href="genindex.html" />
       
    25     <link rel="search" title="Search" href="search.html" />
       
    26     <link rel="next" title="PyAMS namespace traverser" href="traverser.html" />
       
    27     <link rel="prev" title="Managing ZCA with PyAMS" href="zca.html" />
       
    28 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Neuton&amp;subset=latin" type="text/css" media="screen" charset="utf-8" />
       
    29 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nobile:regular,italic,bold,bolditalic&amp;subset=latin" type="text/css" media="screen" charset="utf-8" />
       
    30 <!--[if lte IE 6]>
       
    31 <link rel="stylesheet" href="_static/ie6.css" type="text/css" media="screen" charset="utf-8" />
       
    32 <![endif]-->
       
    33 
       
    34   </head>
       
    35   <body>
       
    36 
       
    37     <div class="related" role="navigation" aria-label="related navigation">
       
    38       <h3>Navigation</h3>
       
    39       <ul>
       
    40         <li class="right" style="margin-right: 10px">
       
    41           <a href="genindex.html" title="General Index"
       
    42              accesskey="I">index</a></li>
       
    43         <li class="right" >
       
    44           <a href="traverser.html" title="PyAMS namespace traverser"
       
    45              accesskey="N">next</a> |</li>
       
    46         <li class="right" >
       
    47           <a href="zca.html" title="Managing ZCA with PyAMS"
       
    48              accesskey="P">previous</a> |</li>
       
    49         <li class="nav-item nav-item-0"><a href="index.html">PyAMS User Guide 0.1.0 documentation</a> &#187;</li> 
       
    50       </ul>
       
    51     </div>  
       
    52 
       
    53     <div class="document">
       
    54       <div class="documentwrapper">
       
    55         <div class="bodywrapper">
       
    56           <div class="body" role="main">
       
    57             
       
    58   <div class="section" id="pyams-site-management">
       
    59 <span id="site"></span><h1>PyAMS site management<a class="headerlink" href="#pyams-site-management" title="Permalink to this headline">¶</a></h1>
       
    60 <p>PyAMS site management is based on the ZODB.</p>
       
    61 <p>On application startup, if PyAMS_utils package is included into Pyramid configuration, several operations take
       
    62 place:</p>
       
    63 <blockquote>
       
    64 <div><ul class="simple">
       
    65 <li>a custom <strong>site factory</strong> is defined</li>
       
    66 <li>custom request methods are defined</li>
       
    67 <li>a custom <strong>traverser</strong> handling <strong>namespaces</strong> is defined</li>
       
    68 <li>a custom subscribers predicate based on interfaces support is defined</li>
       
    69 <li>several adapters are registered, to handle annotations and key references</li>
       
    70 <li>custom TALES extensions are registered.</li>
       
    71 </ul>
       
    72 </div></blockquote>
       
    73 <p>The site factory is an important component in this process. It is this factory which will define the application root
       
    74 and create a <strong>local site manager</strong>.</p>
       
    75 <p>Pyramid application is loaded from ZODB’s root via a key defined in Pyramid’s configuration file; the key is named
       
    76 <em>pyams.application_name</em> and it’s default value is <em>application</em>.</p>
       
    77 <p>If the application can’t be found, PyAMS is looking for an application class name in Pyramid’s configuration file; the
       
    78 class name configuration key is called <em>pyams.application_factory</em> and defined by default as
       
    79 <em>pyams_utils.site.BaseSiteRoot</em>. PyAMS default site factory will then create the application, and add a local site
       
    80 manager to it (see <a class="reference internal" href="zca.html#zca"><span class="std std-ref">Managing ZCA with PyAMS</span></a>).</p>
       
    81 <p>After application creation, a <code class="xref py py-class docutils literal"><span class="pre">NewLocalSiteCreatedEvent</span></code> is
       
    82 notified. Custom packages can subscribe to this event to register custom components.</p>
       
    83 <div class="section" id="pyams-upgrade-command-line-script">
       
    84 <h2><em>pyams_upgrade</em> command line script<a class="headerlink" href="#pyams-upgrade-command-line-script" title="Permalink to this headline">¶</a></h2>
       
    85 <p>Pyramid allows to define custom command line scripts for application management. A script called <em>pyams_upgrade</em> is
       
    86 provided by PyAMS_utils package;&nbsp;this script apply the same process as PyAMS site factory, but can also be used to
       
    87 manage <strong>database generations</strong>. The idea behind this is just to allow custom packages to provide a way to check and
       
    88 upgrade database configuration away from application startup process:</p>
       
    89 <div class="highlight-bash"><div class="highlight"><pre><span></span><span class="c1"># ./bin/pyams_upgrade webapp/development.ini</span>
       
    90 </pre></div>
       
    91 </div>
       
    92 <p>A <strong>site generation checker</strong> is just a named utility providing <code class="xref py py-class docutils literal"><span class="pre">pyams_utils.interfaces.site.ISiteGenerations</span></code>
       
    93 interface. For example, <strong>pyams_security</strong> package provides such utility, to make sure that local site manager
       
    94 contains a PyAMS security manager and a principal annotation utility:</p>
       
    95 <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pyams_utils.site</span> <span class="kn">import</span> <span class="n">check_required_utilities</span>
       
    96 
       
    97 <span class="n">REQUIRED_UTILITIES</span> <span class="o">=</span> <span class="p">((</span><span class="n">ISecurityManager</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">SecurityManager</span><span class="p">,</span> <span class="s1">&#39;Security manager&#39;</span><span class="p">),</span>
       
    98                       <span class="p">(</span><span class="n">IPrincipalAnnotationUtility</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">PrincipalAnnotationUtility</span><span class="p">,</span> <span class="s1">&#39;User profiles&#39;</span><span class="p">))</span>
       
    99 
       
   100 <span class="nd">@utility_config</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;PyAMS security&#39;</span><span class="p">,</span> <span class="n">provides</span><span class="o">=</span><span class="n">ISiteGenerations</span><span class="p">)</span>
       
   101 <span class="k">class</span> <span class="nc">SecurityGenerationsChecker</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
       
   102 <span class="sd">&quot;&quot;&quot;I18n generations checker&quot;&quot;&quot;</span>
       
   103 
       
   104     <span class="n">generation</span> <span class="o">=</span> <span class="mi">1</span>
       
   105 
       
   106     <span class="k">def</span> <span class="nf">evolve</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">site</span><span class="p">,</span> <span class="n">current</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
       
   107         <span class="sd">&quot;&quot;&quot;Check for required utilities&quot;&quot;&quot;</span>
       
   108         <span class="n">check_required_utilities</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">REQUIRED_UTILITIES</span><span class="p">)</span>
       
   109 </pre></div>
       
   110 </div>
       
   111 <p><code class="xref py py-func docutils literal"><span class="pre">check_required_utilities</span></code> is a PyAMS_utils utility function which
       
   112 can to used to verify that a set of local utilities are correctly registered with the given names and interfaces.</p>
       
   113 </div>
       
   114 </div>
       
   115 
       
   116 
       
   117           </div>
       
   118         </div>
       
   119       </div>
       
   120       <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
       
   121         <div class="sphinxsidebarwrapper">
       
   122   <h3><a href="index.html">Table Of Contents</a></h3>
       
   123   <ul>
       
   124 <li><a class="reference internal" href="#">PyAMS site management</a><ul>
       
   125 <li><a class="reference internal" href="#pyams-upgrade-command-line-script"><em>pyams_upgrade</em> command line script</a></li>
       
   126 </ul>
       
   127 </li>
       
   128 </ul>
       
   129 
       
   130   <h4>Previous topic</h4>
       
   131   <p class="topless"><a href="zca.html"
       
   132                         title="previous chapter">Managing ZCA with PyAMS</a></p>
       
   133   <h4>Next topic</h4>
       
   134   <p class="topless"><a href="traverser.html"
       
   135                         title="next chapter">PyAMS namespace traverser</a></p>
       
   136 <div id="searchbox" style="display: none" role="search">
       
   137   <h3>Quick search</h3>
       
   138     <form class="search" action="search.html" method="get">
       
   139       <div><input type="text" name="q" /></div>
       
   140       <div><input type="submit" value="Go" /></div>
       
   141       <input type="hidden" name="check_keywords" value="yes" />
       
   142       <input type="hidden" name="area" value="default" />
       
   143     </form>
       
   144 </div>
       
   145 <script type="text/javascript">$('#searchbox').show(0);</script>
       
   146         </div>
       
   147       </div>
       
   148       <div class="clearer"></div>
       
   149     </div>
       
   150     <div class="related" role="navigation" aria-label="related navigation">
       
   151       <h3>Navigation</h3>
       
   152       <ul>
       
   153         <li class="right" style="margin-right: 10px">
       
   154           <a href="genindex.html" title="General Index"
       
   155              >index</a></li>
       
   156         <li class="right" >
       
   157           <a href="traverser.html" title="PyAMS namespace traverser"
       
   158              >next</a> |</li>
       
   159         <li class="right" >
       
   160           <a href="zca.html" title="Managing ZCA with PyAMS"
       
   161              >previous</a> |</li>
       
   162         <li class="nav-item nav-item-0"><a href="index.html">PyAMS User Guide 0.1.0 documentation</a> &#187;</li> 
       
   163       </ul>
       
   164     </div>
       
   165     <div class="footer" role="contentinfo">
       
   166         &#169; Copyright 2017, Thierry Florac.
       
   167       Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.5.
       
   168     </div>
       
   169   </body>
       
   170 </html>