def open(self, create=True, timeout=0, dictcursor=True): if self.connection: raise Database.SQLConnectionError, \ "database file is already opened, call close() first" # make sure the directories for the dbfile are created if create: import os import rpg.pathutil as pathutil pathutil.makedirs(os.path.dirname(self.dbfile)) # check if the dbfile exists if os.path.exists(self.dbfile): create = False # open db connection self.dprint('open database file: %s' % self.dbfile) try: import sqlite3 except ImportError: from pysqlite2 import dbapi2 as sqlite3 self.connection = sqlite3.connect(self.dbfile) # establish a cursor for future queries if dictcursor: self.connection.row_factory = sqlite3.Row self.cursor = self.connection.cursor() # create the tables if create: self._create()
def setProcessLock(self): """Before setting the lock with our pid, daemonize.""" # fork off if not self.opts.nofork: if self.opts.log: log = self.opts.log else: log = self.logfile import rpg.pathutil as pathutil pathutil.makedirs(os.path.dirname(log)) osutil.stdoutToFile(log) osutil.daemonize() # finish the locking now super(DaemonCmdLineTool, self).setProcessLock()