summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-02-19 22:55:47 +0000
committerZac Medico <zmedico@gentoo.org>2006-02-19 22:55:47 +0000
commit1b7593526b974ab1c6acdd39b105a68f5864483a (patch)
tree0dc431d3fd185e000f72ea74a11e06bf4934201f
parent80b381410e4a6519a01e2cfc218bd77a2e987112 (diff)
downloadportage-1b7593526b974ab1c6acdd39b105a68f5864483a.tar.gz
portage-1b7593526b974ab1c6acdd39b105a68f5864483a.tar.bz2
portage-1b7593526b974ab1c6acdd39b105a68f5864483a.zip
Split out 2 reusable functions from fixdbentries and put them in a new portage_update module.
svn path=/main/trunk/; revision=2750
-rw-r--r--pym/portage.py27
-rw-r--r--pym/portage_update.py46
2 files changed, 47 insertions, 26 deletions
diff --git a/pym/portage.py b/pym/portage.py
index 5f260b133..8b3f289cd 100644
--- a/pym/portage.py
+++ b/pym/portage.py
@@ -106,6 +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
# 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
@@ -3651,32 +3652,6 @@ def getmaskingstatus(mycpv):
rValue.append(kmask+" keyword")
return rValue
-def fixdbentries(update_iter, dbdir):
- """Performs update commands which result in search and replace operations
- for each of the files in dbdir (excluding CONTENTS and environment.bz2).
- Returns True when actual modifications are necessary and False otherwise."""
- modified = False
- for myfile in [f for f in os.listdir(dbdir) if f not in ("CONTENTS", "environment.bz2")]:
- file_path = os.path.join(dbdir, myfile)
- f = open(file_path, "r")
- mycontent = f.read()
- f.close()
- orig_content = mycontent
- for update_cmd in update_iter:
- if update_cmd[0] == "move":
- old_value, new_value = update_cmd[1], update_cmd[2]
- if not mycontent.count(old_value):
- continue
- old_value = re.escape(old_value);
- mycontent = re.sub(old_value+"$", new_value, mycontent)
- mycontent = re.sub(old_value+"(\\s)", new_value+"\\1", mycontent)
- mycontent = re.sub(old_value+"(-[^a-zA-Z])", new_value+"\\1", mycontent)
- mycontent = re.sub(old_value+"([^a-zA-Z0-9-])", new_value+"\\1", mycontent)
- if mycontent is not orig_content:
- write_atomic(file_path, mycontent)
- modified = True
- return modified
-
class packagetree:
def __init__(self,virtual,clone=None):
if clone:
diff --git a/pym/portage_update.py b/pym/portage_update.py
new file mode 100644
index 000000000..0aadae1b3
--- /dev/null
+++ b/pym/portage_update.py
@@ -0,0 +1,46 @@
+
+import os, re
+
+from portage_util import write_atomic
+
+ignored_dbentries = ("CONTENTS", "environment.bz2")
+
+def update_dbentry(update_cmd, mycontent):
+ if update_cmd[0] == "move":
+ old_value, new_value = update_cmd[1], update_cmd[2]
+ if mycontent.count(old_value):
+ old_value = re.escape(old_value);
+ mycontent = re.sub(old_value+"$", new_value, mycontent)
+ mycontent = re.sub(old_value+"(\\s)", new_value+"\\1", mycontent)
+ mycontent = re.sub(old_value+"(-[^a-zA-Z])", new_value+"\\1", mycontent)
+ mycontent = re.sub(old_value+"([^a-zA-Z0-9-])", new_value+"\\1", mycontent)
+ return mycontent
+
+def update_dbentries(update_iter, mydata):
+ """Performs update commands and returns a
+ dict containing only the updated items."""
+ updated_items = {}
+ for k, mycontent in mydata.iteritems():
+ if k not in ignored_dbentries:
+ orig_content = mycontent
+ for update_cmd in update_iter:
+ mycontent = update_dbentry(update_cmd, mycontent)
+ if mycontent is not orig_content:
+ updated_items[k] = mycontent
+ return updated_items
+
+def fixdbentries(update_iter, dbdir):
+ """Performs update commands which result in search and replace operations
+ for each of the files in dbdir (excluding CONTENTS and environment.bz2).
+ Returns True when actual modifications are necessary and False otherwise."""
+ mydata = {}
+ for myfile in [f for f in os.listdir(dbdir) if f not in ignored_dbentries]:
+ file_path = os.path.join(dbdir, myfile)
+ f = open(file_path, "r")
+ mydata[myfile] = f.read()
+ f.close()
+ updated_items = update_dbentries(update_iter, mydata)
+ for myfile, mycontent in updated_items.iteritems():
+ file_path = os.path.join(dbdir, myfile)
+ write_atomic(file_path, mycontent)
+ return len(updated_items) > 0