summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-07-21 06:25:16 +0000
committerZac Medico <zmedico@gentoo.org>2006-07-21 06:25:16 +0000
commitb14f667e022812a69b1354d1d9612cf36e7ff1a7 (patch)
tree10f9cf7bc5804c06d895423fde0aa08433bd51b3 /pym
parente5998321056d36efdc0f8c4d554f166c3516c438 (diff)
downloadportage-b14f667e022812a69b1354d1d9612cf36e7ff1a7.tar.gz
portage-b14f667e022812a69b1354d1d9612cf36e7ff1a7.tar.bz2
portage-b14f667e022812a69b1354d1d9612cf36e7ff1a7.zip
Move new_protect_filename from the core portage module to portage_util.
svn path=/main/trunk/; revision=3978
Diffstat (limited to 'pym')
-rw-r--r--pym/portage.py53
-rw-r--r--pym/portage_util.py51
2 files changed, 52 insertions, 52 deletions
diff --git a/pym/portage.py b/pym/portage.py
index 83aa0c993..15d191269 100644
--- a/pym/portage.py
+++ b/pym/portage.py
@@ -78,7 +78,7 @@ try:
import portage_util
from portage_util import atomic_ofstream, apply_secpass_permissions, apply_recursive_permissions, \
dump_traceback, getconfig, grabdict, grabdict_package, grabfile, grabfile_package, \
- map_dictlist_vals, normalize_path, \
+ map_dictlist_vals, new_protect_filename, normalize_path, \
pickle_read, pickle_write, stack_dictlist, stack_dicts, stack_lists, \
unique_array, varexpand, writedict, writemsg, writemsg_stdout, write_atomic
import portage_exception
@@ -669,57 +669,6 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None):
outfile.write("setenv "+x+" '"+env[x]+"'\n")
outfile.close()
-def new_protect_filename(mydest, newmd5=None):
- """Resolves a config-protect filename for merging, optionally
- using the last filename if the md5 matches.
- (dest,md5) ==> 'string' --- path_to_target_filename
- (dest) ==> ('next', 'highest') --- next_target and most-recent_target
- """
-
- # config protection filename format:
- # ._cfg0000_foo
- # 0123456789012
- prot_num=-1
- last_pfile=""
-
- if (len(mydest) == 0):
- raise ValueError, "Empty path provided where a filename is required"
- if (mydest[-1]=="/"): # XXX add better directory checking
- raise ValueError, "Directory provided but this function requires a filename"
- if not os.path.exists(mydest):
- return mydest
-
- real_filename = os.path.basename(mydest)
- real_dirname = os.path.dirname(mydest)
- for pfile in listdir(real_dirname):
- if pfile[0:5] != "._cfg":
- continue
- if pfile[10:] != real_filename:
- continue
- try:
- new_prot_num = int(pfile[5:9])
- if new_prot_num > prot_num:
- prot_num = new_prot_num
- last_pfile = pfile
- except SystemExit, e:
- raise
- except:
- continue
- prot_num = prot_num + 1
-
- new_pfile = normalize_path(os.path.join(real_dirname,
- "._cfg" + str(prot_num).zfill(4) + "_" + real_filename))
- old_pfile = normalize_path(os.path.join(real_dirname, last_pfile))
- if last_pfile and newmd5:
- if portage_checksum.perform_md5(real_dirname+"/"+last_pfile) == newmd5:
- return old_pfile
- else:
- return new_pfile
- elif newmd5:
- return new_pfile
- else:
- return (new_pfile, old_pfile)
-
# returns a tuple. (version[string], error[string])
# They are pretty much mutually exclusive.
# Either version is a string and error is none, or
diff --git a/pym/portage_util.py b/pym/portage_util.py
index 8fa62c5a2..cf115d1e9 100644
--- a/pym/portage_util.py
+++ b/pym/portage_util.py
@@ -6,6 +6,7 @@ from portage_exception import PortageException, FileNotFound, \
OperationNotPermitted, PermissionDenied, ReadOnlyFileSystem
import portage_exception
from portage_dep import isvalidatom
+import portage_checksum
import sys,string,shlex,os,errno
try:
@@ -853,3 +854,53 @@ class ConfigProtect(object):
#skip, it's in the mask
masked = len(pmpath)
return protected > masked
+
+def new_protect_filename(mydest, newmd5=None):
+ """Resolves a config-protect filename for merging, optionally
+ using the last filename if the md5 matches.
+ (dest,md5) ==> 'string' --- path_to_target_filename
+ (dest) ==> ('next', 'highest') --- next_target and most-recent_target
+ """
+
+ # config protection filename format:
+ # ._cfg0000_foo
+ # 0123456789012
+ prot_num = -1
+ last_pfile = ""
+
+ if len(mydest) == 0:
+ raise ValueError, "Empty path provided where a filename is required"
+ if mydest[-1] == os.path.sep: # XXX add better directory checking
+ raise ValueError, "Directory provided but this function requires a filename"
+ if not os.path.exists(mydest):
+ return mydest
+
+ real_filename = os.path.basename(mydest)
+ real_dirname = os.path.dirname(mydest)
+ for pfile in os.listdir(real_dirname):
+ if pfile[0:5] != "._cfg":
+ continue
+ if pfile[10:] != real_filename:
+ continue
+ try:
+ new_prot_num = int(pfile[5:9])
+ if new_prot_num > prot_num:
+ prot_num = new_prot_num
+ last_pfile = pfile
+ except ValueError:
+ continue
+ prot_num = prot_num + 1
+
+ new_pfile = normalize_path(os.path.join(real_dirname,
+ "._cfg" + str(prot_num).zfill(4) + "_" + real_filename))
+ old_pfile = normalize_path(os.path.join(real_dirname, last_pfile))
+ if last_pfile and newmd5:
+ if portage_checksum.perform_md5(
+ os.path.join(real_dirname, last_pfile)) == newmd5:
+ return old_pfile
+ else:
+ return new_pfile
+ elif newmd5:
+ return new_pfile
+ else:
+ return (new_pfile, old_pfile)