PackagingDrafts/TGApps

From FedoraProject

Jump to: navigation, search
Idea.png
These could be presented to the Packaging Committee to become guidelines or just reside on the PythonSIG page to be hints for packaging !TurboGears Apps. Most of the actual rules (Follow FHS, packaging daemons, etc) are already in the Guidelines. This page just makes it clear how to apply those to a TG app.

Contents

Hints on Packaging TurboGears Applications

!TurboGears applications are a bit complex to package well. These are some hints on how to do it well.

What is a TurboGears App?

!TurboGears applications are a hybrid of several different types of packages:

Python Packages

!TurboGears is a python web framework. Thus TG apps are written in python. What's more, TG apps usually come with a setup.py that installs the main portions of the TG app as a python module in %{python_sitelib}. This is because tg-admin quickstart is the standard way to create a new TG app and that creates a setup.py that installs the programs in this manner.

Web Applications

The web application guidelines were written with php scripts in mind. Those place the data and program scripts in a subdirectory of %{_datadir}. The changeable data is placed in a subdirectory of /var/lib/. Configuration files belong in /etc. And so on. This is all according to the FHS.

Daemons

Unlike php web apps, TG apps are designed to run as a standalone server on their own port. Usually apache or another http server runs in front of the TG app, proxying requests on port 80 to the app. There should be a way to start the application just like any other daemon.

Decisions to Make

Follow the FHS

Precedent is pretty clear in Fedora that we should follow the FHS in regards to placement of files. Thus, these files belong in a certain place:

Starting the TG Apps

start-APP Script

Here's an example start-pkgdb::

#!/usr/bin/python
__requires__ = 'TurboGears[future] '
import pkg_resources

CONFFILE=/etc/pkgdb.cfg
PROGRAMDIR=/usr/share/pkgdb

from turbogears import config, update_config, start_server
import cherrypy
cherrypy.lowercase_api = True
from os.path import *
import sys

if len(sys.argv) > 1:
update_config(configfile=sys.argv[1] ,
modulename="pkgdb.config")
elif exists(join(dirname(__file__), "setup.py")):
update_config(configfile="dev.cfg",modulename="pkgdb.config")
else:
update_config(configfile=CONFFILE, modulename="pkgdb.config")

sys.path.append(PROGRAMDIR)

from pkgdb.controllers import Root

start_server(Root())

Both CONFFILE and PROGRAMDIR should be set from the spec file so that we can substitute distro-wide values for %{_datadir} and %{_sysconfdir}.