Irritatingly, the django-admin.py is not set in the path, you need to symlink it somehwere that is seen (I put it in /opt/local/bin)
Posts Tagged ‘python’
-
28th Jul 2010
-
Python DB API
9th Mar 2010Useful things to remember:
Can get python built (no compile, no need for mysql_config file shenanigans) from launchpad
Need to create a DB cnfig object:
config = {'host': 'localhost', 'database': 'database_name', 'user': 'root', 'password': '', 'charset': 'utf8' ,'use_unicode': True, 'get_warnings': True }
Then connect:
db = mysql.connector.connect(**config)
Then you can get the “cursor” object which allows you to do things:
cursor = db.cursor()
Then perform whatever you want with SQL:
cursor.execute('SELECT * FROM table')
Get the results for your query and iterate through them:
for row in cursor.fetchall(): print row
Get the ID of an insert you have just performed:
cursor.lastrowid -
64bit, virtual-python.py and anoyances caused
8th Dec 2009Host broke, gave us a new server. This however was 64bit and broke Trac. To get it working again:
- Modify the virtual-python file line
stdlib_dir = join(prefix, 'lib', py_version)
to
stdlib_dir = join(prefix, 'lib64', py_version)
and run.
- Then re-follow the first few steps in guide on installing Trac, up to and including the easy_install of Trac, found here
- Now rename the library in the home folder from lib to lib64
All should now be working!
-
Python, Trac and shared hosting
23rd Oct 2009Easy, step by step:
Set up a “virtual” python installation by running this script: virtual-python, then add these to your .bash_profile:
export PYTHONPATH="$HOME/lib/python2.4/site-packages" export LD_LIBRARY_PATH="$HOME/packages/lib" export PATH="$HOME/packages/bin:$PATH"
then reload your bash profile with
source .bash_profileNext get the easy install package: EasyInstall and run it:
sh setuptools-0.6c9-py2.4.egg --prefix=~
This now allows you to install Trac in an easier way:
easy_install --prefix=~ TracNext setup the Trac environment:
trac-admin /path/to/project initenv
then deploy it for use on a webserver. Due to a bug you need to create another directory to deploy to and then copy over:
trac-admin /path/to/project deploy /other/dir mv /other/dir/* /path/to/project
Now the fun begins – you need to makes sure all permissions are correct. Navigate to the
cgi-bindirectory and run:chmod +rx trac.cgiYou also need to change
#!/usr/bin/pythonto your python pathThe next step is to create an index.cgi page to fix the shared server path bugs:
#!/bin/bash export HOME="/your/site/home" export TRAC_ENV="$HOME/path/to/trac" export PYTHONPATH="$HOME/lib/python2.4/site-packages" export PATH="$HOME/bin:$PATH" export LD_LIBRARY_PATH="$HOME/lib" /full/path/to/trac/cgi-bin/trac.cgi
and as before, run
chmod +rx index.cgito get it workingNow we need to setup up a .htaccess file to ensure it all works:
DirectoryIndex cgi-bin/index.cgi AuthType Basic AuthName "Trac" AuthUserFile /path/to/.htpasswd/file Require valid-user
The auth stuff is needed for later. You need to create a htpasswd file with the name of the user you would like to add as admin to it to initially get it running. A better approach will be used when it’s running.
The next step is to check it all works! Once you’ve checked it is in fact live and kicking, you need to add the permissions to access it.
trac-admin /path/to/trac/site >> permissions add admins TRAC_ADMIN >> permissions add {your_name} admins
And you should now be able to log in!
The next step is to get the some better authentication working. First:
easy_install http://trac-hacks.org/svn/accountmanagerplugin/0.9
to install the account manager plugin.
Then simply add the location of the password file in the htpasswd section of the account manager admin. You now need to disable your authentication in the .htaccess file you originally setup so that the HTML login will work. simply comment out the authentication lines.
Next, edit
trac.ini, addingtrac.web.auth.LoginModule = disabledto the components section (or disable in the trac admin).Finally, we need to set up Trac so that it uses a static location for files seen as we’re stuck using CGI. Simply edit the
trac.inisection so that thehtdocs_locationreads the full URL to it: http://your-site.com/htdocs/common/.Now all should be working!