summaryrefslogtreecommitdiffstats
path: root/pym
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
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')
-rw-r--r--pym/portage.py49
-rw-r--r--pym/portage_update.py29
2 files changed, 47 insertions, 31 deletions
diff --git a/pym/portage.py b/pym/portage.py
index c2e113580..5f81dd55b 100644
--- a/pym/portage.py
+++ b/pym/portage.py
@@ -106,7 +106,7 @@ try:
from portage_checksum import perform_md5,perform_checksum,prelink_capable
import eclass_cache
from portage_localization import _
- from portage_update import fixdbentries, update_dbentries
+ from portage_update import fixdbentries, update_dbentries, grab_updates
# Need these functions directly in portage namespace to not break every external tool in existence
from portage_versions import ververify,vercmp,catsplit,catpkgsplit,pkgsplit,pkgcmp
@@ -6734,7 +6734,7 @@ for x in mtimedb.keys():
#,"porttree":portagetree(root,virts),"bintree":binarytree(root,virts)}
features=settings["FEATURES"].split()
-def do_upgrade(mykey):
+def do_upgrade(mykey, mycontent):
"""Valid updates are returned as a list of split update commands."""
writemsg("\n\n")
writemsg(green("Performing Global Updates: ")+bold(mykey)+"\n")
@@ -6742,7 +6742,7 @@ def do_upgrade(mykey):
writemsg(" "+bold(".")+"='update pass' "+bold("*")+"='binary update' "+bold("@")+"='/var/db move'\n"+" "+bold("s")+"='/var/db SLOT move' "+bold("S")+"='binary SLOT move' "+bold("p")+"='update /etc/portage/package.*'\n")
processed=1
myupd = []
- mylines = grabfile(mykey)
+ mylines = mycontent.splitlines()
for myline in mylines:
mysplit = myline.split()
if len(mysplit) == 0:
@@ -6870,37 +6870,24 @@ def update_config_files(update_iter):
def global_updates():
updpath = os.path.join(settings["PORTDIR"], "profiles", "updates")
- mylist = listdir(updpath, EmptyOnError=1)
- # 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:
- # resort the list
- mylist = [myfile[3:]+"-"+myfile[:2] for myfile in mylist]
- mylist.sort()
- mylist = [myfile[5:]+"-"+myfile[:4] for myfile in mylist]
-
- if not mtimedb.has_key("updates"):
- mtimedb["updates"] = {}
-
- didupdate = 0
+ if not mtimedb.has_key("updates"):
+ mtimedb["updates"] = {}
+ if settings["PORTAGE_CALLER"] == "fixpackages":
+ update_data = grab_updates(updpath)
+ else:
+ update_data = grab_updates(updpath, mtimedb["updates"])
+ if len(update_data) > 0:
+ didupdate = 1
do_upgrade_packagesmessage = 0
myupd = []
timestamps = {}
- for myfile in mylist:
- mykey = os.path.join(updpath, myfile)
- mystat = os.stat(mykey)
- if not stat.S_ISREG(mystat.st_mode):
- continue
- if mykey not in mtimedb["updates"] or \
- mtimedb["updates"][mykey] != mystat.st_mtime or \
- settings["PORTAGE_CALLER"] == "fixpackages":
- didupdate = 1
- valid_updates, no_errors = do_upgrade(mykey)
- myupd.extend(valid_updates)
- if no_errors:
- # Update our internal mtime since we
- # processed all of our directives.
- timestamps[mykey] = mystat.st_mtime
+ for mykey, mystat, mycontent in update_data:
+ valid_updates, no_errors = do_upgrade(mykey, mycontent)
+ myupd.extend(valid_updates)
+ if no_errors:
+ # Update our internal mtime since we
+ # processed all of our directives.
+ timestamps[mykey] = mystat.st_mtime
update_config_files(myupd)
db["/"]["bintree"] = binarytree("/", settings["PKGDIR"], virts)
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