Package dak :: Package dakdb
[hide private]
[frames] | no frames]

Source Code for Package dak.dakdb

 1  """ 
 2  Database update scripts for usage with B{dak update-db} 
 3   
 4  @contact: Debian FTP Master <ftpmaster@debian.org> 
 5  @copyright: 2008  Michael Casadevall <mcasadevall@debian.org> 
 6  @license: GNU General Public License version 2 or later 
 7   
 8  Update scripts have to C{import psycopg2} and 
 9  C{from daklib.dak_exceptions import DBUpdateError}. 
10   
11  There has to be B{at least} the function C{do_update(self)} to be 
12  defined. It should take all neccessary steps to update the 
13  database. If the update fails the changes have to be rolled back and the 
14  C{DBUpdateError} exception raised to properly halt the execution of any 
15  other update. 
16   
17  Example:: 
18   def do_update(self): 
19       print "Doing something" 
20   
21       try: 
22           c = self.db.cursor() 
23           c.execute("SOME SQL STATEMENT") 
24           self.db.commit() 
25   
26       except psycopg2.ProgrammingError, msg: 
27           self.db.rollback() 
28           raise DBUpdateError("Unable to do whatever, rollback issued. Error message : %s" % (str(msg))) 
29   
30  This function can do whatever it wants and use everything from dak and 
31  daklib. 
32   
33  """ 
34