====================
Python Fedora Module
====================

:Author: Toshio Kuratomi
:Date: 30 July 2009
:Version: 0.3.x

The Fedora module provides a python API for building `Fedora Services`_ and
clients that connect to them.  It has functions and classes that help to build
TurboGears_ applications and classes to make building clients of those
services much easier.

.. _`Fedora Services`: doc/service.html
.. _TurboGears: http://www.turbogears.org

.. contents::

-------
License
-------

This python module is distributed under the terms of the GNU Lesser General
Public License Version 2 or later.

----------
Installing
----------

``python-fedora`` is found in rpm form in Fedora proper.  Sometimes a new
version will be placed in the Fedora Infrastructure yum repository for testing
within Infrastructure before being released to the general public.  Installing
from the yum repository should be as easy as::

	# yum install python-fedora

If you want to install from a checkout of the development branch, follow these
procedures::

    # bzr branch bzr://bzr.fedorahosted.org/bzr/python-fedora/python-fedora-devel
    # cd python-fedora-devel
    # paver install

You'll need Paver 1.0 or higher for this to work.  In Fedora, this can be
installed with::

    # yum install -y python-paver

See the configuration notes in each section for information on configuring
your application after install.

---------------------------
Fedora Accounts Integration
---------------------------

We provide several modules that make connecting to the `Fedora Account
System`_ easier.

.. _`Fedora Account System`: https://fedorahosted.org/fas

General Purpose API
===================
The ``fedora.accounts.fas2`` module allows code to integrate with the `Fedora
Account System`_. It uses the JSON interface provided by the Account System
servre to retrieve information about users.

Note: This API is not feature complete. If you'd like to help add methods,
document the existing methods, or otherwise aid in development of this API
please contact us on the infrastructure list: fedora-infrastructure@redhat.com
or on IRC: lmacken, abadger1999, and ricky in #fedora-admin, irc.freenode.net.

Using the general API requires instantiating an ``AccountSystem`` object. You
then use methods on the ``AccountSystem`` to get and set information on the
people in the account system.

At the moment, there are only a few methods implemented. Full documentation on
these methods is available from the ``AccountSystem``'s docstrings from the
interpreter or, for instance, by running::

    $ pydoc fedora.accounts.fas2.AccountSystem

Here's an example of using the ``AccountSystem``::

	from fedora.accounts.fas2 import AccountSystem
	from fedora.client import AuthError,

	# Get an AccountSystem object.  All AccountSystem methods need to be
	# authenticated so you might as well give username and password here.
	fas = AccountSystem(username='foo', password='bar')

	people = fas.people_by_id()

TurboGears Interface
====================

The TurboGears_ interface also uses the JSON interface to the account system.
It provides a TurboGears_ ``visit`` and ``identity`` plugin so a TurboGears_
application can authorize via FAS. Since the plugin operates over JSON, it is
possible to use these plugins on hosts outside of Fedora Infrastructure as
well as within.  Remember, however, that entering your Fedora password on a
third party website requires you to trust that website. So doing things this
way is more useful for developers wanting to work on their apps outside of
Fedora Infrastructure than a general purpose solution for allowing Fedora
Users to access your web app. (SSL client certificates and OpenID are better
solutions to this problem but they are still being implemented in the FAS2
server.)

Configuring
-----------
To configure your TurboGears_ application, you need to set the following
variables in your pkgname/config/app.cfg file::

    fas.url='https://admin.fedoraproject.org/accounts/'
    visit.on=True
    visit.manager="jsonfas"
    identity.on="True"
    identity.failure_url="/login"
    identity.provider="jsonfas"

---------------
Fedora Services
---------------

``python-fedora`` provides several helper classes and functions for building a
TurboGears_ application that works well with other `Fedora Services`_.  the
`Fedora Services`_ documentation is the best place to learn more about these.

TurboGears Widgets
==================

We've started adding experimental TG Widgets to interact with specific aspects
of Fedora.  This are a needs more work and integration with `MyFedora`_.

.. _`MyFedora`: https://fedorahosted.org/myfedora

-----------------
TurboGears Client
-----------------
There is a module to make writing a client for our TurboGears services very
easy.  Please see the `client documentation`_ for more details

.. _`client documentation`: doc/client.rst

------------
Translations
------------

The strings in python-fedora has mainly error messages.  These are translated
so we should make sure that translators are able to translate them when
necessary.  You will need babel and setuptools to run these commands::
  yum install babel setuptools

Updating the POT File
=====================

When you make changes that change the translatable strings in the package, you
should update the POT file.  Use the following paver command to do that::
  paver extract_messages -o po/python-fedora.pot

Then commit your changes to source control.

Updating the PO Files
=====================

You should merge the new translatable strings into the PO files at the same
time.  Until we build a single paver command for this, we want to do this::
  for po_file in po/*.po ; do
    paver update_catalog -D python_fedora -i po/python-fedora.pot -l `basename $po_file` -d po -o $po_file
  done

Creating a new PO File
======================

If you are working on a translation for the first time, you'll need to create
the PO file.  Run this paver command substituting LOCALE with the locale you
wish to translate for::
  paver init_catalog -D python_fedora -i po/python-fedora.pot -l LOCALE -d po -o po/$LOCALE.po

That will initialize a new PO file from the current POT file.  The PO will be
located in po/LOCALE/LC-MESSAGES/messages.po

After creation, this should be committed to the revision control system.

Compiling Message Catalogs
==========================

Message catalogs can be compiled for testing and should always be compiled
just prior to release.  Do this with the following paver command::
  paver make_catalogs

Compiled message catalogs should not be committed to source control.

Installing Message Catalogs
===========================

``paver install_catalogs`` will install the catalogs.  This commmand has been
added to ``paver install``.

-------
Release
-------

We want to get to the place where a release can be made via a paver target.
Currently, this is more involved.

1) Merge everything into the python-fedora-stable branch.  Push the changes to
   the server.  Eventually this should be the last manual step.  Everything
   else should be automated::

     bzr merge [from feature branches]
     bzr commit
     bzr push bzr+ssh://bzr.fedorahosted.org/bzr/python-fedora/python-fedora-stable

2) Go to a temporary directory and checkout a copy of stable::
     bzr checkout --lightweight bzr+ssh://bzr.fedorahosted.org/bzr/python-fedora/python-fedora-stable release

3) Go to that directory and run::
     paver sdist

4) copy the dist/python-fedora-VERSION.tar.gz and python-fedora.spec files to
   where you build Fedora RPMS.  Do a test build::
     cp dist/python-fedora-*.tar.gz python-fedora.spec /srv/cvs/python-fedora/devel/
     pushd /srv/cvs/python-fedora/devel
     make mockbuild

5) Make sure the build completes.  Run rpmlint on the results.  Install and
   test the new packages::
     rpmlint *rpm
     sudo rpm -Uvh *noarch.rpm
     [test]

6) When satisfied that the build works, tag the repository::
     popd
     bzr tag VERSION
     bzr push bzr+ssh://bzr.fedorahosted.org/bzr/python-fedora/python-fedora-stable

7) Upload the tarball to fedorahosted.  Note: The directory is slightly
   different if you're not a fedorahosted admin::
     scp dist/python-fedora*tar.gz fedorahosted.org:/srv/web/releases/p/y/python-fedora/

8) Finish building and pushing packages for Fedora.
