Beispiel #1
0
def connect_private():
	return _pg.connect(
		host=_config.DBHOST,
		dbname=_config.DB_PRIVATE_DATABASE,
		port=_config.DB_PORT,
		user=_config.DB_USER,
		passwd=_config.DB_PASSWORD)
Beispiel #2
0
 def __init__(self, server, ref, file, pgconnect=None, db=None):
     if db == None:
         print pgconnect
         self.db = _pg.connect(pgconnect)
     else:
         self.db = db
     res = self.db.query(
         "SELECT f_handle, type FROM meta WHERE ref=\'%s\'" % file)
     if len(res.getresult()) == 0 and file == '/':
         self.db.query(
             "INSERT INTO meta (f_handle, ref, type) VALUES ('rootfh', '/', 2)"
         )
         self.f_handle = 'rootfh'
         self.type = NF4DIR
     else:
         self.f_handle, self.type = res.getresult()[0]
     if self.type == NF4REG:
         res = self.db.query(
             "SELECT obj_data FROM files WHERE f_handle = '%s'" %
             self.f_handle)
         self.oid = res.getresult()[0][0]
         print "OID: %d" % self.oid
     print "%s, %d" % (self.f_handle, self.type)
     self.handle = self.f_handle
     nfs4state.NFSFileHandle.__init__(self, server, ref, file)
Beispiel #3
0
def connect():
	return _pg.connect(
		host=_config.DBHOST,
		dbname=_config.DB_PUBLIC_DATABASE,
		port=_config.DB_PORT,
		user=_config.DB_USER,
		passwd=_config.DB_PASSWORD)
Beispiel #4
0
def connect(dsn=None, user=None, password=None, host=None, database=None):
    # first get params from DSN
    dbport = -1
    dbhost = ""
    dbbase = ""
    dbuser = ""
    dbpasswd = ""
    dbopt = ""
    dbtty = ""
    try:
        params = string.split(dsn, ":")
        dbhost = params[0]
        dbbase = params[1]
        dbuser = params[2]
        dbpasswd = params[3]
        dbopt = params[4]
        dbtty = params[5]
    except:
        pass

    # override if necessary
    if user != None:
        dbuser = user
    if password != None:
        dbpasswd = password
    if database != None:
        dbbase = database
    if host != None:
        try:
            params = string.split(host, ":")
            dbhost = params[0]
            dbport = int(params[1])
        except:
            pass

    # empty host is localhost
    if dbhost == "":
        dbhost = None
    if dbuser == "":
        dbuser = None

    # open the connection
    cnx = _pg.connect(host=dbhost,
                      dbname=dbbase,
                      port=dbport,
                      opt=dbopt,
                      tty=dbtty,
                      user=dbuser,
                      passwd=dbpasswd)
    return pgdbCnx(cnx)
 def __init__(self, confFile="sql.conf", confSectionName="Database", **props):
     try:
        config=ConfigParser.ConfigParser()
        config.read(confFile)
        self.dbProp = config.get(confSectionName,'db')
        self.hostProp = config.get(confSectionName,'host')
        self.userProp = config.get(confSectionName,'user')
        self.passwordProp = config.get(confSectionName,'password')
        self.db = _pg.connect(dbname=self.dbProp,\
                          host=self.hostProp,\
                          user=self.userProp,\
                          passwd=self.passwordProp)
     except:
        raise DBInitError("StackTrace -> " + traceBack())
def connect(dsn = None, user = None, password = None, host = None, database = None):
	# first get params from DSN
	dbport = -1
	dbhost = ""
	dbbase = ""
	dbuser = ""
	dbpasswd = ""
	dbopt = ""
	dbtty = ""
	try:
		params = string.split(dsn, ":")
		dbhost = params[0]
		dbbase = params[1]
		dbuser = params[2]
		dbpasswd = params[3]
		dbopt = params[4]
		dbtty = params[5]
	except:
		pass

	# override if necessary
	if user != None:
		dbuser = user
	if password != None:
		dbpasswd = password
	if database != None:
		dbbase = database
	if host != None:
		try:
			params = string.split(host, ":")
			dbhost = params[0]
			dbport = int(params[1])
		except:
			pass

	# empty host is localhost
	if dbhost == "":
		dbhost = None
	if dbuser == "":
		dbuser = None

	# open the connection
	cnx = _pg.connect(host = dbhost, dbname = dbbase, port = dbport,
						opt = dbopt, tty = dbtty,
						user = dbuser, passwd = dbpasswd)
	return pgdbCnx(cnx)
 def __init__(self,
              confFile="sql.conf",
              confSectionName="Database",
              **props):
     try:
         config = ConfigParser.ConfigParser()
         config.read(confFile)
         self.dbProp = config.get(confSectionName, 'db')
         self.hostProp = config.get(confSectionName, 'host')
         self.userProp = config.get(confSectionName, 'user')
         self.passwordProp = config.get(confSectionName, 'password')
         self.db = _pg.connect(dbname=self.dbProp,\
                           host=self.hostProp,\
                           user=self.userProp,\
                           passwd=self.passwordProp)
     except:
         raise DBInitError("StackTrace -> " + traceBack())
Beispiel #8
0
	def __init__(self, server, ref, file, pgconnect=None, db=None):
		if db == None:
			print pgconnect
			self.db = _pg.connect(pgconnect)
		else:
			self.db = db
		res = self.db.query("SELECT f_handle, type FROM meta WHERE ref=\'%s\'" % file);
		if len(res.getresult()) == 0 and file == '/':
			self.db.query("INSERT INTO meta (f_handle, ref, type) VALUES ('rootfh', '/', 2)");
			self.f_handle = 'rootfh'
			self.type = NF4DIR
		else:
			self.f_handle, self.type = res.getresult()[0]
		if self.type == NF4REG:
			res = self.db.query("SELECT obj_data FROM files WHERE f_handle = '%s'" % self.f_handle)
			self.oid = res.getresult()[0][0]
			print "OID: %d" % self.oid
		print "%s, %d" % (self.f_handle, self.type)
		self.handle = self.f_handle
		nfs4state.NFSFileHandle.__init__(self, server, ref, file)
Beispiel #9
0
#!/usr/bin/python

import _pg
import os
import commands
import string
import sys

tuner_id = "0"
tuner_address = "0"
transcode = "no"
duration = "no"
cur_tuner = "nada"

htdb_db = _pg.connect(host="localhost",
                      user="******",
                      passwd="htdb",
                      dbname="htdb")


def find_tconst(title, runtime):
    tconst = "nada"
    query = "select distinct tconst from tv_files where primarytitle = '" + title + "';"
    print query
    result = htdb_db.query(query)
    result_list = list(result.dictresult())
    for record in result_list:
        tconst = str(record['tconst'])

    if tconst == "nada":
        query = "select tconst from title_basics where primarytitle = '" + title + "' and ttype = 'tvseries' and runtime_int = " + runtime + " order by tconst limit 1;"
        print query
Beispiel #10
0
    schema = argv[7]
    table = argv[8]
    if (len(argv) >= 10):
        score_min = float(argv[9])
    if (len(argv) == 12):
        parall_workers = int(argv[10])
        parall_id = int(argv[11])
    else:
        parall_workers = 1
        parall_id = 0
except NameError as e:
    exit(e)

# Test DB connexion
try:
    db_conn = _pg.connect(db_name, db_ip, db_port, None, db_user, db_password)
except Exception as e:
    exit(e)

# Test BAN API connexion
try:
    response = get(api_url + "?q=8+bd+du+port")
    if (response.status_code > 200):
        raise NameError("API BAN error ! http_status_code=" +
                        str(response.status_code))
except NameError as e:
    exit(e)
except:
    exit("API BAN error !")

Beispiel #11
0
#!/usr/bin/python2.7
import subprocess
import _pg

#conn = _pg.connect("imdb", "w.cs.uvic.ca", 5432, None, None, "csc370", "ecs108")
conn = _pg.connect("postgres", "localhost", 5432, None, None, "postgres", "something")

print "Running question 2. J)...."
x = conn.query("select * from discoverychannel_j()")
subprocess.call("clear")
print x

conn.close()