1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
To work on sloecode, you need the following installed:
python (version?)
python-docutils - for help page generation.
python-formencode - for web form validation
python-pylons (0.10 minimum)
python-repoze.who (1.0 minimum) - for authentication.
python-repoze.who-plugins - contains SQLAlchemy plugin for easier authentication
python-repoze.what - for authorisation
python-repoze.what-plugins - contains repoze.what / pylons plugins
python-jinja2 - for site templates.
python-sqlalchemy-ext - declarative extension to sqlalchemy.
python-twisted-conch - Conch SSH implementation, used in bzr smart server.
python-zope.component - Zope component architexture, used in smart server.
python-zope.event - Zope event framework, used in smart server.
For the test suite:
python-nose
python-testtools
This document deals with two parts: the web app and the bzr smart server.
Web Application
---------------
To setup the site databse, do this:
$ paster setup-app development.ini
To run the site, do this:
$ paster serve [--reload] development.ini
The --reload argument will reload the website when you make a change to a local
source file. This can be very useful for development!
You should then be able to connect to the website by pointing your web browser
to http://localhost:5000/
sloecode is a typical pylons app. A brief tour of the system follows:
config/routing.py holds the routes map that maps from a URL to a controller
and action. For example, it specifies that the '/me' URI should be mapped to
the 'portal' controller and the 'index' action.
Controllers are all in the 'controllers' directory (what a surprise!). Each
controller is a class, and contains one or more actions. Most actions just
render a template file, and return the result. Some actions process data
requests from forms, in which case we use FormEncode to do form validation.
Template pages are stored in the templates directory. They are written in
the jinja2 template language. All templates derive from 'base.html', which
allows us to have common navigation elements across all pages. Templates can
make sure of macros, which are like python functions. They are all stored in
the 'templates/macros' directory.
Our data is stored in a database. We use sqlite at this point in time, but
you can configure any database backend you want in the .ini file. We use
the SQLAlchemy ORM to interface with the database, and try at all times to
avoid writing SQL directly. Data models are all stored in the 'models'
directory. Since we use the SQLAlchemy declarative style, the models are a
single class. I also store FormEncode schemas in the same file as models,
since there is a strong relationship between the two.
Static content is used throughout the site (CSS files, JS files, images
& icons). This is stored in the 'public' directory, but is still served from
the root URL. For example: '/style.css' gets magically mapped to
'public/style.css'.
The lib folder contains a few items of interest. The 'helpers.py' file is a
module that contains simple functions that are made available to all template
files as 'h'. For example, there are functions to create valid XHTML tags. The
idea is to use this module whenever possible, which allows us to patch HTML
generation functions at a later date. For example, if we want to change the
encoding type of all <form> tags in the app we can do this, in one place.
Also in the lib folder is the base class for all controllers, which defines a
(somewhat) clean interface for showing templates certain objects.
BZR Smart Server
----------------
To run the smartserver, you need to set a couple of environment variables:
* SLOECODE_CONFIG should point to the full path to the INI file
* PYTHONPATH needs to include the location to the sloecode python modules
The BZR smart server lives in sloecode/sshserver/. The smart server uses the
twisted network library, and the conch ssh server implementation. To run it,
type:
make smartserver
You will need to create an SSH key pair, and place it in /var/sloecode/keys.
The keys should be named 'sloecode_rsa' and 'sloecode_rsa.pub'. You will
also need to create the /var/sloecode/logs directory.
|