def _start(self): # prepare the new postgres instance cmd = "initdb --encoding=UTF8 --no-locale --pgdata=%s/data -A trust --username=%s >%s" %( self.path, self.user, self.log) returncode, out, err = execute(cmd) if returncode != 0: raise RuntimeError('postgresql db initialization failed: %s' % out+err) # start up the postgres instance self.fork("postmaster", "-D", "%s/data" % self.path, "-p", "%d" % self.port, "-F") import pgsql count = 50 while count: time.sleep(0.1) try: db = pgsql.connect(database = "template1", host = "localhost", user = self.user, port = self.port) db.execute("select version()") except (pgsql.InternalError, pgsql.ProgrammingError): count -= 1 else: break if not count: raise SystemError, "unable to contact postgresql server" try: db.execute('create language "plpgsql"') except: pass db.commit() db.close() del db time.sleep(0.1)
def run(self): try: self.conn = pgsql.connect(database=self.database,user=self.user, password=self.passwd, host=self.host,port=self.port) cursor = self.conn.cursor() except Exception, e: print "Postgresql Error: %s" % (e,) sys.exit(1)
def run(self): try: self.conn = pgsql.connect(database=self.database, user=self.user, password=self.passwd, host=self.host, port=self.port) cursor = self.conn.cursor() except Exception, e: print "Postgresql Error: %s" % (e, ) sys.exit(1)
def connect(self, **kwargs): assert(self.database) cdb = self._connectData() if not cdb.get("port", None): cdb["port"] = -1 try: self.dbh = pgsql.connect(**cdb) except pgsql.DatabaseError, err: exc_info = sys.exc_info() newerr = sqlerrors.DatabaseError( "Could not connect to database %s: %s" % (cdb, str(err))) raise type(newerr), newerr, exc_info[2]
try: import pgsql as db except: import psycopg2 as db DATEFORMAT = "%Y-%m-%d" RE_EXP = re.compile("^\d{4}-\d{2}-\d{2} -?\d{1,3} -?\d{1,3}$") update = False site = wikipedia.getSite() CONF = "/opt/geo/geo.conf" host, dbname, user, password = open(CONF, "r").read().strip().split(",") conn = db.connect(host=host, database=dbname, user=user, password='******'' + password + '\'') cur = conn.cursor() subcat = "Category:Meetup by date" try: args = sys.argv[1:] if "update" in args: update = True for arg in args: if "Category:" in arg: subcat = arg except Exception, ex: print ex pass
from catlib import Category try: import pgsql as db except: import psycopg2 as db DATEFORMAT = "%Y-%m-%d" RE_EXP = re.compile("^\d{4}-\d{2}-\d{2} -?\d{1,3} -?\d{1,3}$") update = False site = wikipedia.getSite() CONF = "/opt/geo/geo.conf" host, dbname, user, password = open(CONF, "r").read().strip().split(",") conn = db.connect(host=host, database=dbname, user=user, password='******''+password+'\'') cur = conn.cursor() subcat = "Category:Meetup by date" try: args = sys.argv[1:] if "update" in args: update = True for arg in args: if "Category:" in arg: subcat = arg except Exception, ex: print ex pass def recurseCategory(cat):