diff options
author | Brian Harring <ferringb@gentoo.org> | 2005-09-24 17:54:05 +0000 |
---|---|---|
committer | Brian Harring <ferringb@gentoo.org> | 2005-09-24 17:54:05 +0000 |
commit | 430ce6fed697eea6c68b13ecdcad14bc6fdac01d (patch) | |
tree | 7e195bcb2c0715c5d663faecf3e84007f7e69ec1 /pym/portage_db_metadata.py | |
parent | f913d92453517074c89a4cd59004d72bee5ba7d8 (diff) | |
download | portage-430ce6fed697eea6c68b13ecdcad14bc6fdac01d.tar.gz portage-430ce6fed697eea6c68b13ecdcad14bc6fdac01d.tar.bz2 portage-430ce6fed697eea6c68b13ecdcad14bc6fdac01d.zip |
EAPI awareness, and flat_hash/flat_list autodetection for rysnc cache.
svn path=/main/branches/2.0/; revision=2022
Diffstat (limited to 'pym/portage_db_metadata.py')
-rw-r--r-- | pym/portage_db_metadata.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/pym/portage_db_metadata.py b/pym/portage_db_metadata.py new file mode 100644 index 000000000..60d87b2d0 --- /dev/null +++ b/pym/portage_db_metadata.py @@ -0,0 +1,49 @@ +# Copyright 2004 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-src/portage/pym/Attic/portage_db_flat.py,v 1.13.2.6 2005/04/19 07:14:17 ferringb Exp $ +cvs_id_string="$Id: portage_db_flat.py,v 1.13.2.6 2005/04/19 07:14:17 ferringb Exp $"[5:-2] + +import os, portage_db_flat_hash, portage_db_flat + +class database(portage_db_flat_hash.database): + + def get_values(self, key): + if not key: + raise KeyError("key is not valid") + + try: + myf = open(self.fullpath + key, "r") + except OSError: + raise KeyError("key is not valid") + mtime = os.fstat(myf.fileno()).st_mtime + data = myf.read().splitlines() + + # easy attempt first. + if len(data) != portage_db_flat.magic_line_count: + d = dict(map(lambda x: x.split("=",1), data)) + d["_mtime_"] = mtime + return portage_db_flat_hash.database.get_values(self, key, d) + # this one's interesting. + d = {} + + for line in data: + # yes, meant to iterate over a string. + hashed = False + for idx, c in enumerate(line): + if not c.isalpha(): + if c == "=" and idx > 0: + hashed = True + d[line[:idx]] = line[idx + 1:] + elif c == "_" or c.isdigit(): + continue + break + elif not c.isupper(): + break + + if not hashed: + # non hashed. + data.append(mtime) + return portage_db_flat.database.get_values(self, key, data=data) + + d["_mtime_"] = mtime + return portage_db_flat_hash.database.get_values(self, key, data=d) |