Tuesday, 20 December 2011

The record breaking Lego Christmas tree

I am on my way to Derby and just saw this amazing Lego structure in the London st.Pancras train station.


Friday, 16 December 2011

Install and configure trac on Linux/Ubuntu 11.10

In this blog post I am going to explain about how to install 'trac' on linux. 'trac' is a nice project management tool which is written in python, that can be used to track your projects. And it is open-source :D (Win)

I am using 'trac' with 'git' revision control system, for my project. In my next blog post I will be explain how to use 'trac' along with 'git', using the 'GitPlugin'

 Ok, now if you follow the following instructions hopefully you will have a working 'trac' site.

Install 'trac'
   
Make sure you have the latest version of python installed, otherwise apt will install an older version of 'trac'

      sudo apt-get install python python-babel trac
  



Yes, apt may ask you to install few dependencies including apache2. So please install all of them.

'trac' uses SQLite as its default data store. So if you have not already got it installed. Then do the following


     sudo apt-get install sqlite3


It is possible to get 'trac' working with other database systems. If you are interested, click on the following URL.
http://trac.edgewall.org/

Upgrade python packages
   
There are two ways you can do this

With easy_install
 
 easy_install Babel

 easy_install Trac

or

With 'pip'
 
 pip install --upgrade Babel

 pip install --upgrade Trac


If you have not got pip installed, install pip as follows. Please skip this step if you were successfully able to do the previous step.

 sudo apt-get install python-pip

   
Now you have successfully installed all the software that you need to run 'trac'.
   
Configuration

  Change the directory locations as desired.

 Create a directory for 'trac'
 Then change it's access permissions.

sudo mkdir -p /var/local/trac && chown www-data: /var/local/trac
   
Initialise the 'trac' environment
 
 sudo trac-admin /var/local/trac initenv

   
Now create the configuration file using your favourite text editor. I use emacs.
 
 sudo emacs /etc/apache2/sites-available/trac

   
Paste the following code in to it.
       
<VirtualHost *:80>
 ServerName trac.local
        <Location />
           SetHandler mod_python
           PythonInterpreter main_interpreter
           PythonHandler trac.web.modpython_frontend
           PythonOption TracEnv /var/local/trac
           PythonOption TracEnvParentDir /var/local/trac
           PythonOption TracUriRoot /
           PythonOption TracEnv /var/local/trac
            # PythonOption TracEnvIndexTemplate /var/local/trac/templates/index-template.html
           PythonOption TracLocale en_US.UTF8
           PythonOption PYTHON_EGG_CACHE /tmp
           Order allow,deny
           Allow from all
        </Location>
        <Location /login>
          AuthType Basic
          AuthName "myproject"
          AuthUserFile /var/local/trac/.htpasswd
          Require valid-user
        </Location>
      </VirtualHost>


 Now you should have a working 'trac' instance. So check if it works.
 
      sudo tracd -p 8080 /var/local/trac

[-p] flag specifies the port that this particular 'trac' instance belongs to.
   
Note: the flag [-p] is same as [-port]

And then go to:

      http://localhost:8080/

Now you should see the 'trac' instance running.

Adding Authentication
   
Basic Authorisation

In this case we are going to authorise the 'trac' site with a .htpasswd file.

You have to have 'fcrypt' package installed to decode '.htpasswd'

Creating the '.htpasswd'

 sudo htpasswd -c /var/local/trac/.htpasswd admin

To add more users:
 sudo htpasswd -c /var/local/trac/.htpasswd admin

    
'htpasswd' creates the flat-file with the username and password that you are given.
[-c]  =  create the password file in the given path.

Start tracd:

 sudo -p 8080 --basic-auth="projectdirectory,path/to/the/.htpasswd,mname" /path/to/the/environment/directory


 In my case, it is

 sudo -p 8080 --basic-auth="trac,/var/local/trac/.htpasswd, admin" path/to/the/environment/directory

   
 Digest Authentication
   
 'htdigest' will be used to create the digest file.

 sudo htdigest -c /var/local/trac/.htdigest admin admin
   
  Now start 'trac' with 'tracd':

 sudo -p 8080 --auth="projectdirectory,path/to/the/.htpasswd, admin" /path/to/the/environment/directory

  So it will be,


 sudo -p 8080 --auth="trac,/var/local/trac/.htpasswd, admin" /var/local/trac


  If you have just one project in 'trac', then use the [-s] flag with the 'tracd', so it will skip the environment list when it starts.
      eg: sudo tracd -s ...........

There we go, we are done :D

Trouble Shooting Errors


If you get following error. It is most likely because of permission issues. So make sure you have given root access when you start your 'trac' instance.


Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/trac/web/api.py", line 440, in send_error
    data, 'text/html')
  File "/usr/lib/python2.7/dist-packages/trac/web/chrome.py", line 827, in render_template
    message = req.session.pop('chrome.%s.%d' % (type_, i))
  File "/usr/lib/python2.7/dist-packages/trac/web/api.py", line 216, in __getattr__
    value = self.callbacks[name](self)
  File "/usr/lib/python2.7/dist-packages/trac/web/main.py", line 300, in _get_session
    return Session(self.env, req)
  File "/usr/lib/python2.7/dist-packages/trac/web/session.py", line 198, in __init__
    self.get_session(sid)
  File "/usr/lib/python2.7/dist-packages/trac/web/session.py", line 219, in get_session
    super(Session, self).get_session(sid, authenticated)
  File "/usr/lib/python2.7/dist-packages/trac/web/session.py", line 61, in get_session
    db = self.env.get_db_cnx()
  File "/usr/lib/python2.7/dist-packages/trac/env.py", line 328, in get_db_cnx
    return get_read_db(self)
  File "/usr/lib/python2.7/dist-packages/trac/db/api.py", line 90, in get_read_db
    return _transaction_local.db or DatabaseManager(env).get_connection()
  File "/usr/lib/python2.7/dist-packages/trac/db/api.py", line 152, in get_connection
    return self._cnx_pool.get_cnx(self.timeout or None)
  File "/usr/lib/python2.7/dist-packages/trac/db/pool.py", line 226, in get_cnx
    return _backend.get_cnx(self._connector, self._kwargs, timeout)
  File "/usr/lib/python2.7/dist-packages/trac/db/pool.py", line 146, in get_cnx
    raise TimeoutError(errmsg)
TimeoutError: Unable to get database connection within 0 seconds. (TracError(<babel.support.LazyProxy object at 0x22e47d0>,))


If you need more information, please go to http://trac.edgewall.org.