Forums

Setting up TRAC with a Beginner account

I'm setting up a demo for a client.

I created a "Beginner" account for them. What they want is a customized TRAC system, Possibly integrated with Django, or maybe a fully custom Django app. I dunno yet, part of the reason for this demo is figure out the "best" solution.

So, I created a virtual environment "django16" - I think Django will be needed for something!

And I'm working through these two documents to generate my setup procedure - I would post it but Trac Wiki markup looks like hell in Markdown, and I'm too lazy to translate.

  • http://trac.edgewall.org/wiki/TracInstall#MandatoryDependencies

  • http://trac.edgewall.org/wiki/TracInstallPlatforms

Although I don't actually know what O/S Python Anywhere uses, so I'm trying to stick with the generic procedure.

I can see trouble looming when I want to setup a Subversion Server. That is, I don't know if PA will let me - or if there is a pre-configured one I can use? Or if GIT will work??

Right now, I'm stuck on authentication. The TRAC install guide use of htpasswd is based on the assumption you can access the Apache config files for the server. And I think I read someplace PA isn't using Apache anyway.....

What to do? Have to have some security, even if hard-coded in my wsgi file.

Hi there,

We run our own trac instance on PythonAnywhere, so it's definitely possible. Having a look through our setup notes, it looks like we

  • installed the accountmanager plugin
  • used htdigest auth
  • added a first user using the registration ui, then switched off registration
  • later, switched to mysql as a database (altho IIRC this wasn't related to the auth stuff)

If you could share a few more details that would be great!

My setup procedure is a wiki page, the heart of which has this so far:

  • workon django16 Even though I have not installed Django yet
  • pip install Genshi
  • pip install babel
  • pip install docutils
  • pip install Pygments
  • pip install trac mysql-python
  • Installing trac-admin script to /home/Bittele/.virtualenvs/django16/bin
  • Installing tracd script to /home/Bittele/.virtualenvs/django16/bin
  • trac-admin /home/Bittele/trac initenv
  • Trac name: Jobs
  • DB connection string: mysql://Bittele:neverUmind@mysql.server/Bittele$trac
  • cd trac
  • trac-admin ./ permission add anonymous TRAC_ADMIN
  • easy_install https://trac-hacks.org/svn/accountmanagerplugin/tags/acct_mgr-0.4.3 Note: PIP gets an error, had to use easy_install as per plugin's install manual
  • Reload Web App from Dashboard Plugin should be visible in Trac Admin now (did not work for me)
  • Easy_install build the EGG file so Plan B is: Use Dashboard -> File to download the EGG file to your local hard drive (Win 7 Desktop in my case) File for me was: /home/Bittele/files/home/Bittele/.virtualenvs/django16/lib/python2.7/site-packages/TracAccountManager-0.4.3-py2.7.egg Right-click the download icon and select Save Link As... From Trac Admin Plugin page, browse to the EGG file and install it.
  • On the TRAC admin page, open the Plugins section
  • Expand TracAccountManager 0.4.3, a number of default options should be enabled, adjust to taste.
  • Click on Accounts/Configuration on the LHS
  • Change HtPasswdStore to 1.
  • Enter /home/Bittele/trac/trac.htdigest This is weird because I entered trac.htpasswd
  • hash_type should default to '''crypt'''
  • Click SAVE button at bottom of the screen!
  • Click on Accounts/Users on the LHS If you enabled HtPasswdStore correctly, there will be an empty user list. If you get a message that a list cannot be displayed there is a problem with the password storage setup.
  • Add a new user to take over as Admin for the project.
  • Click on General/Permissions' on the LHS
  • Grant TRAC_ADMIN to your new user.
  • Click login and log in as your new admin user.
  • Verify your user name is shown as logged in and you still have the '''admin''' item on the toolbar.
  • Click on Admin in the toolbar
  • Click on General/Permissions on the LHS
  • Beside the anonymous subject, click the check box beside TRAC_ADMIN
  • Click the Remove Selected Items button to prevent everybody from hacking your system!

WSGI file:

import os
os.environ['TRAC_ENV'] = '/home/Bittele/trac'
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
import trac.web.main
application = trac.web.main.dispatch_request

You now have a working TRAC sans Repository.

Right. I think your next step is to install the Account Manager plugin. It lets you set up auth using an HTML form instead of using apache/HTTP-auth:

http://trac-hacks.org/wiki/AccountManagerPlugin

I figured it out and updated my earlier post with the procedure. Some things did not work as expected, but I was able to work around them. I'd love to know why, or maybe they are symptoms of an something else?

So, what about a Subversion or GIT repo?

<deleted Duplicate>

I've never tried to run a subversion server. You should be able to set up a bare git repository straightforwardly though.

Here are some instructions for how you an access one on PA via SSH: http://blog.pythonanywhere.com/43/

Presumably, since trac will be running on the same machine as your bare git repo, it won't even need SSH, so it should work, even on a beginner account...

A fine theory. I shall test it later today.

OK. To update the repo part. You cannot connect IN to a free account, so it would not be possible to clone the git repo outside of the free account. Which would make it hard for others to work on the code.. So I hosted the Git repo on my paid account, then cloned it to the client's account. Actually the account I'm logged in under now.

Next step is a WSGI file that can handle TRAC and Django. Any templates?

Here's our wsgi file, for the trac instance we host on PA:

import os
os.environ['TRAC_ENV'] = '/home/usernamey/trac_pythonanywhere'
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
import trac.web.main
application = trac.web.main.dispatch_request

@Harry,

Yup. I am using exactly that right now, with the addition of the Virtualenv lines. I setup TRAC on this account first so I had a place to discuss design ideas with the client.

Now its time to get some Django code up and running for a prototype.

I have another account that just has Django, so I have the wsgi file from that.

How to merge them is the question. I am digging into the link(s) previously posted.

Good luck! And, of course, let us know if you have any problems.

I have a working wsgi file to serve up TRAC and Django! Some very important notes:

  • If you use virtualenv, the virtualenv source command has to be FIRST or else you will suffer for days.
  • I'm splitting out all the "Django" traffic by spotting "admin" at the start of the URL. This works with the admin app, but you will need to spot some other urls - like "reset" for password recovery. This could result in changing your urls.py file.
  • Another annoying feature is wsgi strips out the "admin" so its not there when urls.py starts checking. I think this is going to force me to figure something better out. Soon.

Here is my wsgi file:

# Activate a virtual environment, MUST BE FIRST!!
activate_this = '/home/Halim/.virtualenvs/django16/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

from werkzeug.wsgi import DispatcherMiddleware
import os
import sys
import trac.web.main
import django.core.handlers.wsgi

os.environ['TRAC_ENV'] = '/home/Halim/trac'
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
trac_app = trac.web.main.dispatch_request

# +++++++++++ DJANGO +++++++++++
## assuming your Django settings file is at '/home/Halim/ole/deporte/deporte/settings.py'
## assuming your Django settings file is at '/home/my_username/projects/my_project/settings.py'
##path = '/home/my_username/projects'
path = '/home/Halim/ole/deporte'

if path not in sys.path:
    sys.path.append(path)

##os.environ['DJANGO_SETTINGS_MODULE'] = 'my_project.settings'
os.environ['DJANGO_SETTINGS_MODULE'] = 'deporte.settings'

django_app = django.core.handlers.wsgi.WSGIHandler()

## Midleware dispatcher:
application = DispatcherMiddleware(trac_app, {
                '/admin':     django_app
                })

Whew! This has been fun....

Fantastic! I'm really glad you got there finally :-)

I also have Trac working with git, I have to post how that is setup.... someday.....

Right now I have to make up for the time I lost figuring out my folly....

OK. So this client liked the demo, so he upgraded the account!

Now I want to add Grappelli to Django, but it uses a lot of custom urls. Meaning I need a better way to split traffic in the wsgi file.

Or, maybe I should cheat and set up two separate apps?

That's great news, glad to hear it!

Two separate apps on different subdomains sounds like the safest solution...

I need to setup TRAC for another client. Has anything change/progressed or improved since I did it last time?

(Richard Cooke, despite what the signature may say)

The only change I can see from Halim's post above is that you can now specify the virtualenv on the "Web" tab. When you do that, it's activated before your WSGI file is called, so it's even better than doing it first in the WSGI file :-)

heh. They are all me! Even "Deleted User" - which was Bittele I assume. Nuts. I meant to archive that one, its an example of how to heavily customize TRAC for a specific workflow with tight security.

I'm sad PAW is not listed here yet: https://trac.edgewall.org/wiki/TracInstallPlatforms