diff options
Diffstat (limited to 'pym/portage_update.py')
-rw-r--r-- | pym/portage_update.py | 29 |
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 |