summaryrefslogtreecommitdiffstats
path: root/pym/portage_update.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-02-28 06:40:44 +0000
committerZac Medico <zmedico@gentoo.org>2006-02-28 06:40:44 +0000
commitc04a56293d1d962c963fb050ed10757dfc0406fc (patch)
treeec604a95d4393c9b0c5b733846075874cb80e201 /pym/portage_update.py
parent79d7a6bd32a8734727437bfed97bb94e29c8dd7d (diff)
downloadportage-c04a56293d1d962c963fb050ed10757dfc0406fc.tar.gz
portage-c04a56293d1d962c963fb050ed10757dfc0406fc.tar.bz2
portage-c04a56293d1d962c963fb050ed10757dfc0406fc.zip
Split out a portage_update.grab_updates() function so that it can be reused.
svn path=/main/trunk/; revision=2801
Diffstat (limited to 'pym/portage_update.py')
-rw-r--r--pym/portage_update.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/pym/portage_update.py b/pym/portage_update.py
index 0aadae1b3..a33bc9188 100644
--- a/pym/portage_update.py
+++ b/pym/portage_update.py
@@ -44,3 +44,32 @@ def fixdbentries(update_iter, dbdir):
file_path = os.path.join(dbdir, myfile)
write_atomic(file_path, mycontent)
return len(updated_items) > 0
+
+def grab_updates(updpath, prev_mtimes=None):
+ """Returns all the updates from the given directory as a sorted list of
+ tuples, each containing (file_path, statobj, content). If prev_mtimes is
+ given then only updates with differing mtimes are considered."""
+ mylist = os.listdir(updpath)
+ if prev_mtimes is None:
+ prev_mtimes = {}
+ # validate the file name (filter out CVS directory, etc...)
+ mylist = [myfile for myfile in mylist if len(myfile) == 7 and myfile[1:3] == "Q-"]
+ if len(mylist) == 0:
+ return []
+
+ # update names are mangled to make them sort properly
+ mylist = [myfile[3:]+"-"+myfile[:2] for myfile in mylist]
+ mylist.sort()
+ mylist = [myfile[5:]+"-"+myfile[:4] for myfile in mylist]
+
+ update_data = []
+ for myfile in mylist:
+ file_path = os.path.join(updpath, myfile)
+ mystat = os.stat(file_path)
+ if file_path not in prev_mtimes or \
+ prev_mtimes[file_path] != mystat.st_mtime:
+ f = open(file_path)
+ content = f.read()
+ f.close()
+ update_data.append((file_path, mystat, content))
+ return update_data