===========
Development
===========

----
Code
----

Get the code from the development repository::

    bzr init-repo raffle
    cd raffle
    bzr branch http://toshio.fedorapeole.org/raffle/devel
    cd devel

------------
Egg metadata
------------

Setup the egg metadata so that paster can find it::

    python setup.py egg_info
 h   paster setup-app development.ini
 

--------------------
Install dependencies
--------------------

yum install python-tg-devtools


---------------------------------------------
Hack paster because of setuptools limitations
---------------------------------------------

We're going to need a working paster and unfortunately, the nature of
python-setuptools makes this a tiny bit tricky.  We're going to need to edit
paster to make this work::

  $ cp paster .

Edit ./paster's __requires__ to include fedora_raffle like this::

  - __requires__ = 'PasteScript==1.7.3'
  + __requires__ = ['PasteScript==1.7.3', 'fedora_raffle']

--------------
Database setup
--------------

.. note:: If you just want to use sqlite as your database (for instance, if
    this is just to do code development) you can just run the setup-app paster
    command from below.  The other parts of this section deal with setting up
    database permissions which are not applicable to sqlite.

Create the database and database users.  First connect to the database as a
database superuser.  Then run::

  postgres=# create user raffleadmin with encrypted password 'VepDyngowdathPeklyosIkKeLyx';
  postgres=# create user raffleapp with encrypted password 'BlukUryokwoodhyHytdyff=Twej';
  postgres=# create user rafflereadonly with encrypted password 'DovicjobVudvuheghonvegCinWo';
  postgres=# create database raffle;
  postgres=# grant all on database raffle to raffleadmin;

Each database user will serve a different purpose:

:raffleadmin: has schema changing rights on the database.  Will be able to do
    anything it wants to this database.  Should only be used when we need to
    upgrade or otherwise make changes to the database schema.  We can disable
    it at other times.
:raffleapp: has rights to read and modify most of the data in the database.
    This account would be used in the day to day running of the web app.  Some
    things that this account should not do are: modify schema, be able to
    delete from log tables.  It is hard to make general recomendations about
    what else this sort of account cannot do as it varies by application. this
    is the account that is configured for use in the web app.
:rafflereadonly: seldom used currently.  We should configure scripts that only
    need to read data from the database to use this.  May also be given out to
    people who need to connect to the database to query data from it.  Should
    not have write access to anything.

Edit development.ini to have the raffleadmin account::

  - sqlalchemy.url = sqlite:///%(here)s/devdata.db
  + sqlalchemy.url = postgres://raffleadmin:VepDyngowdathPeklyosIkKeLyx@localhost/raffle
  + db.app_user = raffleapp

Then run the setup-app command to setup the initial database tables::

  ./paster setup-app development.ini

Once this is done, set the config file to use the raffleapp user and password:

  - sqlalchemy.url = postgres://raffleadmin:VepDyngowdathPeklyosIkKeLyx@localhost/raffle
  + sqlalchemy.url = postgres://raffleapp:BlukUryokwoodhyHytdyff=Twej@localhost/raffle

You may disable the raffleadmin user now (for security) if you want.  It would
only need to be enabled again if we need to do a database schema update when
the app is updated.

----------------
Start the server
----------------

With paster
===========

Start the paste http server::

    $ paster serve development.ini

While developing you may want the server to reload after changes in package files (or its dependencies) are saved. This can be achieved easily by adding the --reload option::

    $ paster serve --reload development.ini

Then you are ready to go.

With mod_wsgi
=============

Included in the tarball are some sample files for starting the server via
mod_wsgi.  You'll need to substitute some filesystem paths and place the files
in the proper places for mod_wsgi to find them.  Then you should be ready to
go.

Substitute paths
----------------

You need to substitute two paths into the scripts -- the path to the raffle
python module and the path to the directory where the configuration file lives.
In a production system these might be /usr/share/fedora-raffle and
/etc/fedora-raffle respectively.  In a development checkout, these might both
be /home/username/raffle/devel::

    $ PKGDIR=/usr/share/fedora-raffle
    $ CONFDIR=/etc/fedora-raffle
    $ SBINDIR=/usr/sbin
    $ sed -e "s^@pkgdir@^$PKGDIR^" -e "s^@sbindir@^$SBINDIR^" < httpd-raffle.conf.in > httpd-raffle.conf
    $ sed -e "s^@pkgdir@^$PKGDIR^" -e "s^@confdir@^$CONFDIR^" < raffle.wsgi.in > raffle.wsgi

Put the scripts where they belong
---------------------------------

You can then move these files into the proper places on the filesystem::

   $ sudo mv httpd-raffle.conf /etc/httpd/conf.d/
   $ sudo mv raffle.wsgi /usr/sbin/

When you restart apache, the web application should then startup