Hello Pluto

Hello Pluto!

Given the multitude of scenarios and possibilities, a dead simple Hello World is not particularly instructive. To be a little more useful, we make our Hello World a little more far out than usual. We go to Pluto

There’s many scenarios possible. We are just going to pick one, and get on with it. Here’s the bunch of assumptions and choices that we adopt for our Hello Pluto! example site:

  • We use Gizmo(QP) Directory-based traversal (the default).
  • We run a Durus database server, locally.
  • We initialize the database, creating the user pluto with password pluto.
  • We make an index page that is accessible anonymously.
  • We make a second pluto page, accessible only to authenticated users.
  • We provide a form-based login facility.
  • We use EvoqueTemplating and supply a page template for the site.
  • The site template defines the breadcrumb trail for every page.
  • The site template defines a hierarchical navigation menu for every page.
  • We deploy under QP’s built-in web server.
  • We also deploy behind Apache, using SCGI and tell SCGI to manage up to 3 child processes.

The source for this demo site are included in the gizmo(qp) distribution at gz/demo/hellopluto. Also, for convenience, an instance of this demo site is deployed at http://pluto.gizmojo.org/.

Site source code

Gizmo(QP) sites are QP sites, meaning that they are defined as a python package that implements a slash module, that in turn provides definitions for a SitePublisher, with a site configuration dictionary, and a SiteDirectory class. Here then is the file hellopluto/slash.py where hellopluto is a python package located somewhere on the qp sites search path.

__revision__ = “$Id: slash.py 964 2008-03-17 14:03:29Z mario $” from gz.fill.directory import Directory from gz.fill.exportable import X from gz.fill.login_dir import LoginDir from gz.skin.evoque_templating import EvoqueTemplating from gz.pub.durus_publisher import DurusPublisher from gz.pub.common import page class SitePublisher(DurusPublisher): configuration = dict( durus_address=(‘127.0.0.1’, 5017), scgi_address=(‘127.0.0.1’, 7017), http_address=(”, 8017), as_https_address=(‘127.0.0.1’, 9017), https_address=(‘127.0.0.1’, 10017), max_children=2, secure=False, url_paths = { ‘login’: ‘/login/’, ‘logout’: ‘/login/logout’, }, file_paths = { ‘templates’:”, }, ) skin_class = EvoqueTemplating def __init__(self, connection=None, site=None, **kw): DurusPublisher.__init__(self, connection=connection, site=site, **kw) skin = self.skin skin.set_domain(self.get_file_path_for(‘templates’)) skin.setup_globals() skin.domain.get_collection().set_template(“”, “template.html”, from_string=False) skin.aliases[“login”] = “” def ensure_database_initialized(self): super(SitePublisher, self).ensure_database_initialized() if self.get_users().get(‘pluto’) is None: pluto = self.get_users()[‘pluto’] = self.create_user(‘pluto’) pluto.set_password(‘pluto’) self.commit() class SiteDirectory(Directory): exportables = [ X(”, ‘index’, ‘Kuiper Belt’, ‘Kuiper Belt’), X(‘pluto’, ‘pluto’, ‘Pluto Touchdown’, ‘Planet Pluto Touchdown’, (‘authenticated’,)), X(‘login/’, ‘login’, None, ‘Login’), ] login = LoginDir() def index(self): return page(self.get_x().title, ‘OK, you made it as far as the Kuiper Belt!’) def pluto(self): return page(self.get_x().title, “Hello Pluto! You can’t imagine how heart-warming it is to see you!”)

Site page template

<!– $Id: template.html 912 2008-02-26 17:13:46Z mario $ –> <div class=”crumbs”> ${page.crumbs(root=True)} </div> <div class=”content”> <div class=”left”> ${page.crumbed_menu(0)} </div> <div class=”right”> ${content} <p>${site.link_login_logout()}</p> </div> </div> <div class=”description”> <a href=”https://gizmojo.org/doc/hellopluto”> read the description of this gizmo(qp) demo site </a> </div>

Note that this specifies only our essential template — it has no <head> and <body> elements. The resulting document is however a properly formatted html document, generated by the EvoqueTemplating.

Also, the CSS styling for the site is not shown here. To view it, see the source code in the distribution for this demo.

Site management and deployment

To launch the site, we use the qp command, that is the management tool provided by QP itself.

qp hellopluto start

This will also initialize the durus database, that unless we specify differently is placed at hellopluto/var. Note, it expects that the var subdirectory has already been created. We can now view the site by loading the following URL in a web browser:

http://localhost:8017/

To get a running view of the server logs, or to view status, or restart or stop the site, we do:

qp -l hellopluto # logs qp hellopluto status qp hellopluto restart qp hellopluto stop

To access the Apache/SCGI deployment, we would need to define an Apache VirtualHost, with something such as below.

<VirtualHost *> ServerName www.pluto.gizmojo.org ServerAlias pluto.gizmojo.org SCGIMount / 127.0.0.1:7017 <LocationMatch “^/images/.*”> SCGIHandler off </LocationMatch> </VirtualHost>

If the site had any static files, e.g. /images/, that we would prefer to serve directly from Apache, bypassing SCGI altogether, we can optionally add Location or LocationMatch directives.

Other variations

  • To not run a Durus database server we make our SitePublisher inherit from Publisher and not specify the durus_address in our site configuration.
  • To not deploy under QP’s web server we just not specify http_address in our site configuration.
  • To not deploy under Apache/SCGI we just not specify scgi_address in our site configuration.