Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cr.commit()
# ----------------------------------------------------- #
# add some fields (which cannot be added automatically) #
# ----------------------------------------------------- #
for line in (
"alter table ir_model_fields add group_name varchar(64)",
"alter table ir_model_fields add view_load boolean",
"alter table ir_model_fields alter group_name set default ''",
"alter table ir_model_fields alter view_load set default False",
"delete from ir_values where value like '%,False'",
):
try:
cr.execute(line)
except psycopg.ProgrammingError, e:
cr.commit()
print e
cr.commit()
cr.close()
def load(self):
'''Load state from database'''
import psycopg
if options["globals", "verbose"]:
print('Loading state from', self.db_name, 'database', file=sys.stderr)
self.db = psycopg.connect('dbname=' + self.db_name)
c = self.cursor()
try:
c.execute("select count(*) from bayes")
except psycopg.ProgrammingError:
self.db.rollback()
self.create_bayes()
if self._has_key(self.statekey):
row = self._get_row(self.statekey)
self.nspam = row["nspam"]
self.nham = row["nham"]
if options["globals", "verbose"]:
print(('%s is an existing database,'
' with %d spam and %d ham') \
% (self.db_name, self.nspam, self.nham), file=sys.stderr)
else:
if options["globals", "verbose"]:
print(self.db_name,'is a new database', file=sys.stderr)
self.nspam = 0
self.nham = 0
class mySQLClassifier(SQLClassifier):
def load(self):
'''Load state from database'''
import psycopg
if options["globals", "verbose"]:
print >> sys.stderr, 'Loading state from',self.db_name,'database'
self.db = psycopg.connect('dbname=' + self.db_name)
c = self.cursor()
try:
c.execute("select count(*) from bayes")
except psycopg.ProgrammingError:
self.db.rollback()
self.create_bayes()
if self._has_key(self.statekey):
row = self._get_row(self.statekey)
self.nspam = row["nspam"]
self.nham = row["nham"]
if options["globals", "verbose"]:
print >> sys.stderr, ('%s is an existing database,'
' with %d spam and %d ham') \
% (self.db_name, self.nspam, self.nham)
else:
# new database
if options["globals", "verbose"]:
print >> sys.stderr, self.db_name,'is a new database'
self.nspam = 0
def load(self):
'''Load state from database'''
import psycopg
if options["globals", "verbose"]:
print >> sys.stderr, 'Loading state from', self.db_name, 'database'
self.db = psycopg.connect('dbname=' + self.db_name)
c = self.cursor()
try:
c.execute("select count(*) from bayes")
except psycopg.ProgrammingError:
self.db.rollback()
self.create_bayes()
if self._has_key(self.statekey):
row = self._get_row(self.statekey)
self.nspam = row["nspam"]
self.nham = row["nham"]
if options["globals", "verbose"]:
print >> sys.stderr, ('%s is an existing database,'
' with %d spam and %d ham') \
% (self.db_name, self.nspam, self.nham)
else:
# new database
if options["globals", "verbose"]:
print >> sys.stderr, self.db_name,'is a new database'
self.nspam = 0
sizein[f] = nr
print "Need to load " + str(totalcount) + " records."
dbconn=psycopg.connect('dbname=tiger host=disk port=2345 user=dustin ' \
+ 'password=blahblah')
c=dbconn.cursor()
stats=Stats.Stats(totalcount)
for f in argv[1:]:
try:
zf = zipfile.ZipFile(f)
loadAll(c, f, zf)
except psycopg.ProgrammingError, e:
if str(e).find("load_filesbyname"):
print "Aready did " + f
stats.reduceWorkload(sizein[f])
print stats.getStats()
else:
raise e
dbconn.close()
def load(self):
'''Load state from database'''
import psycopg
if options["globals", "verbose"]:
print >> sys.stderr, 'Loading state from', self.db_name, 'database'
self.db = psycopg.connect('dbname=' + self.db_name)
c = self.cursor()
try:
c.execute("select count(*) from bayes")
except psycopg.ProgrammingError:
self.db.rollback()
self.create_bayes()
if self._has_key(self.statekey):
row = self._get_row(self.statekey)
self.nspam = row["nspam"]
self.nham = row["nham"]
if options["globals", "verbose"]:
print >> sys.stderr, ('%s is an existing database,'
' with %d spam and %d ham') \
% (self.db_name, self.nspam, self.nham)
else:
if options["globals", "verbose"]:
print >> sys.stderr, self.db_name,'is a new database'
self.nspam = 0
self.nham = 0
class mySQLClassifier(SQLClassifier):
def load(self):
'''Load state from database'''
import psycopg
if options["globals", "verbose"]:
print >> sys.stderr, 'Loading state from',self.db_name,'database'
self.db = psycopg.connect('dbname=' + self.db_name)
c = self.cursor()
try:
c.execute("select count(*) from bayes")
except psycopg.ProgrammingError:
self.db.rollback()
self.create_bayes()
if self._has_key(self.statekey):
row = self._get_row(self.statekey)
self.nspam = row["nspam"]
self.nham = row["nham"]
if options["globals", "verbose"]:
print >> sys.stderr, ('%s is an existing database,'
' with %d spam and %d ham') \
% (self.db_name, self.nspam, self.nham)
else:
if options["globals", "verbose"]:
print >> sys.stderr, self.db_name,'is a new database'
self.nspam = 0
self.nham = 0
class mySQLClassifier(SQLClassifier):
def load(self):
'''Load state from database'''
import psycopg
if options["globals", "verbose"]:
print >> sys.stderr, 'Loading state from',self.db_name,'database'
self.db = psycopg.connect('dbname=' + self.db_name)
c = self.cursor()
try:
c.execute("select count(*) from bayes")
except psycopg.ProgrammingError:
self.db.rollback()
self.create_bayes()
if self._has_key(self.statekey):
row = self._get_row(self.statekey)
self.nspam = row["nspam"]
self.nham = row["nham"]
if options["globals", "verbose"]:
print >> sys.stderr, ('%s is an existing database,'
' with %d spam and %d ham') \
% (self.db_name, self.nspam, self.nham)
else:
if options["globals", "verbose"]:
print >> sys.stderr, self.db_name,'is a new database'
self.nspam = 0
self.nham = 0
class mySQLClassifier(SQLClassifier):
pass
subject_line=''
try:
subject_line=headers['subject'][0]
except IndexError:
pass
try:
self.c.execute('insert into messages(folder_id, messid, ' \
+ 'from_line, to_line, subject_line, timestamp)\n' \
+ '\tvalues(%(boxid)i, %(messid)s, %(from)s, %(to)s, ' \
+ '%(subject)s, now())',
{ 'boxid': boxid, 'messid': messid, 'from': from_line,
'to': to_line, 'subject': subject_line})
except psycopg.ProgrammingError, e:
if str(e).find('messages_bymid') >= 0:
raise DuplicateMessage, messid
else:
raise e
self.c.execute("select currval('messages_message_key_seq')")
rv=self.c.fetchall()
return rv[0][0]