Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 32237 Details for
Bug 52321
Sqlite cache backend for portage
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
portage-sqlite/portage_db_sqlite.py
portage_db_sqlite.py (text/plain), 7.38 KB, created by
Karol Wojtaszek (RETIRED)
on 2004-05-29 00:23:45 UTC
(
hide
)
Description:
portage-sqlite/portage_db_sqlite.py
Filename:
MIME Type:
Creator:
Karol Wojtaszek (RETIRED)
Created:
2004-05-29 00:23:45 UTC
Size:
7.38 KB
patch
obsolete
>import sqlite, re, cPickle, portage_db_template > >def prepare_sql_data(data): > # Replace ' with '' > return re.sub("'","''", data) > >class database(portage_db_template.database): > #ought to do ref counting on the number of open connections. course that's worthless till portage calls database.close(). > connections = {} > cursor = None > path_map = {} > categories = {} > defaultOptions = {'db': '/var/cache/edb/sqlite-cache'} > options = {} > lastkey = lastval = None > category = "" > def __init__(self,path,category,dbkeys,uid,gid,config_path="/etc/portage/module_configs/"): > try: > portage_db_template.database.__init__(self, path,category,dbkeys,uid,gid,config_path) > except: > self.path = path > self.category = category > self.dbkeys = dbkeys > self.uid = uid > self.gid = gid > self.module_init() > > def module_init(self): > options = database.defaultOptions.copy(); options.update(self.options) > self.options = options; del options > > from re import sub > path = sub('/{2,}', '/', self.path) > self.constr = self.options['db'] > > if not database.connections.has_key(self.constr): > try: > database.connections[self.constr] = sqlite.connect(database=self.options['db']) > database.connections[self.constr+":cursor"] = database.connections[self.constr].cursor() > except Exception, msg: > raise Exception, "Error connecting to Database using self.options=('%s'): exception=(%s)" % (str(self.options), str(msg)) > sys.exit(); > > > self.con = database.connections[self.constr] > if not database.connections.has_key(self.constr+":cursor"): > database.connections[self.constr+":cursor"] = self.con.cursor() > self.db = database.connections[self.constr+":cursor"] > > try: > if len(database.categories.keys()) == 0: > self.db.execute("select * from category_table;") > for y, x in self.db.fetchall(): > database.categories[y] = x > except Exception, msg: > raise Exception, "Database Error: failed pulling tables from %s: %s" % (self.options['db'], str(msg)) > > if not database.categories.has_key(self.category) : > #create the category table > try: > try: > self.db.execute("insert into category_table (name) values ('%s');" % str(self.category)) > except Exception, msg: > raise Exception, "DBError: %s" % str(msg) > > database.categories.clear() > self.db.execute("select * from category_table;") > for y, x in self.db.fetchall(): > database.categories[y] = x > except Exception, e: > raise Exception, "Database error: failed creation table for path('%s'), category('%s'), Exception=(%s)" % (path, self.category, str(e)) > > self.cat_id = database.categories[self.category] > > > if not database.path_map.has_key(self.path): > try: > if len( database.path_map.keys()) == 0: > self.db.execute('SELECT name, p_id FROM path_table') > for y,x in self.db.fetchall(): > database.path_map[y] = x > except Exception, e: > raise Exception, "database error: %s" % str(e) > > if not database.path_map.has_key(self.path): > try: > self.db.execute("INSERT INTO path_table (name) VALUES(%s)", path) > #flush the table, and load it anew > database.path_map.clear() > self.db.execute('SELECT * FROM path_table') > for path,id in self.db.fetchall(): > database.path_map[path] = id > except Exception, e: > raise Exception, "Database error, failed loading path map: exc=%s" % str(e) > self.p_id = database.path_map[path] > > def has_key(self,key): > self.check_key(key) > try : > self.db.execute("SELECT data FROM package_name WHERE name = '%s' AND cat_id = '%s' AND path_id = '%s'" % (key, self.cat_id, self.p_id )) > return (self.db.rowcount > 0) > except Exception, e: > print "exception in has_key for Key (%s), Error (%s) " % (key, str(e)) > return False > > def keys(self): > ks = {} > try: > self.db.execute("SELECT name, data from package_name WHERE cat_id = '%s' AND path_id = '%s'" % (self.cat_id, self.p_id )) > for x,y in self.db.fetchall(): > ks[x] = cPickle.loads(y) > return ks > except Exception, e: > raise KeyError, "Keys are dead :( (%s)" % str(e) > > def get_values(self,key): > self.check_key(key) > if self.lastkey == key: > return self.lastval > self.db.execute("SELECT data FROM package_name WHERE name = '%s' AND cat_id = '%s' AND path_id = '%s';" % (key, self.cat_id, self.p_id )) > try: > one = {} > one = self.db.fetchone() > if len(one) > 0 and one[0] != None: > self.lastkey = key > self.lastval = cPickle.loads(one[0]) > return self.lastval > except Exception, e: > raise ValueError, "Value error (%s)" % str(e) > > def set_values(self,key,val): > self.check_key(key) > try: > if self.lastkey == key: self.lastkey = self.lastval = None > self.db.execute("replace into package_name(name, cat_id, path_id, data) VALUES ('%s', '%s', '%s', '%s');" % (key, self.cat_id, self.p_id, prepare_sql_data(cPickle.dumps(val)) ) ) > except Exception, msg: > raise Exception, "Error inserting/updating the database (%s)." % str(msg) > sys.exit() > > def del_key(self,key): > try: > if self.lastkey == key: self.lastkey = self.lastval = None > return (self.db.execute("DELETE FROM package_name WHERE cat_id = %d AND name= '%s' AND path_id = %d" % (self.cat_id, key, self.p_id)) > 0) > except Exception, e: > raise Exception, "Error deleting key (%s)" % str(e) > > def sync(self): > self.con.commit() > > def close(self): > self.db.close() >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 52321
:
32234
|
32235
|
32236
| 32237