Using Eclipse and PyDev for django

This guide assumes you’ve already installed Eclipse, PyDev, Python and Django. It also assumes you’re using Eclipse 3.2, PyDev 1.2.4, Django 0.95 and Python 2.4.

  • Go to Window->Preferences->Preferences->PyDev->Python Interpretter and add the django source file to the PYTHONPATH settings.
  • Create a new PyDev pyhon project. Make sure you uncheck the ‘create src folder’ option.
  • Create project on the command line using django e.g. django-admin.py startproject mysite
  • In your newly created project directory create a src directory in it, and move the django generated source files here
  • In eclipse, right-click your project and select refresh
  • Right-click on the project and select Properties->PyDev - PYTHONPATH, and add your src folder to the project source settings

That should be it. I still get red underlines on the Django source imports even thought PyDev seems to know about them – to test this is working properly, open up your urls.py file and ctrl click on the patterns call – it should take you to defaults.py.

Now you can go ahead and create your database & super user.

Launching to built-in server

Open up manage.py and hit F9. This should print out the usage information for the server. To actually start the server, select Run->Run..., and in the Arguments tab for manage.py enter runserver --noreload. The noreload argument gives you output.

Thanks go to PyDev creator Fabio Zadrozny for his guide which got me going.

Specifying a program name in Oracle JDBC connections

When connecting to a database from Java, it’s very handy to tag your connections. When tracking down performance issues and monitoring at a database levels, being able to seperate out your program’s connections (which could come from a variety of machines). Most database drivers allow you to specify a program name when creating your connection.

With SqlServer, you can specify a program name on the query string of your JDBC connection. However with Oracle it’s not quite as simple. I spent ages trying to track down how to do this with Oracle, but it seems that where Oracle is concerned useful documentation lies behind expensive consultants or registration screens. Eventually resident database guru (thanks Jason) sent me a snippet of code which does exactly that, and I’m blogging it here for prosperity (and for consumption by the Google spider).

This code opens a connection with the name Test. By querying the database’s v$session dictionary view we can see each connection from our application (by the way, good luck searching
Google using a $ in a search term). v$session exposes a variety of information – including the program name. The final lines of the code prints out the program name of every session currently connected to the database, helping confirm that the snippets code has worked.

class SetProgram
{
  public static void main (String args [])
       throws SQLException
  {
    // Load the Oracle JDBC driver
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    java.util.Properties props = new java.util.Properties();
    props.put("v$session.program", "Test");
    // Connect to the database
    Connection conn =
      DriverManager.getConnection ("jdbc:oracle:thin:user/tiger@localhost:1521:xe",
   props);
    // Create a Statement
    Statement stmt = conn.createStatement ();
    // Select the PROGRAM field from the V$SESSION table
    ResultSet rset = stmt.executeQuery ("select program from v$session");
    // Iterate through the result
    while (rset.next ())
      System.out.println (rset.getString (1));
  }
} 

Specifying program name with C3P0

When configuring this value using the C3P0 connection pool, if you want to specify properties like v$session.program, you cannot configure login and password using the normal setPasword or setUser methods as it gets its knickers in a twist. Instead you’ll have to place those in the properties object which you pass to the connection pool using the setProperties method on ComboPooledDataSource.

This is worth noting, as where setUser and setPassword will be JDBC driver agnostic, the properties bundle passed in isn’t – or more correctly, the properites themselves aren’t.

Trouble free backups, Part Three - Scheduling backups

Now we’ve worked out what files you want backed up, and we’ve sorted automatic authentication, the only thing left to do is schedule our backups. Unfortunately we can’t make use of the very handy iSync or Backup tools to do this (Apple don’t seem keen on opening up these tools up, as they no-doubt help sell expensive .Mac accounts). Read the rest of this entry »

Trouble free backups, Part Two - SSH Keys for trouble free authentication

In our last part, we used rsync to connect to a remote server to perform incremental backups. The problem is that we really want this to be automatic. Scheduling when a backup occurs is actually fairly simple. What is more work is performing automatic authentication so our backup can occur without user intervention. Read the rest of this entry »

Trouble Free Backups, Part One - rsync and Strongspace

If you’ve been using computers for a while, chances are you’ve lost valuable data more than once. Most computers nowadays come with CD writers (and many with DVD writers) which is great for the occasional manual backup – there is even the nice OSX-specific iSync tool which remind you when to perform the backup, and can manage the files being backed up too. However what would be better would be an automatic solution.

The rsync tool ships with OSX, Linux, and even Windows. Rather than copying and overwriting files on a remote location rsyc performs incremental transfer of files – only those files not already present will be copied – this drastically reduces the time taken to perform backups. Read the rest of this entry »