diff options
Diffstat (limited to 'pym/portage/update.py')
-rw-r--r-- | pym/portage/update.py | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/pym/portage/update.py b/pym/portage/update.py index 412956591..d38ddf942 100644 --- a/pym/portage/update.py +++ b/pym/portage/update.py @@ -2,8 +2,16 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ -import errno, os, re, sys - +import codecs +import errno +import re +import sys + +from portage import os +from portage import _content_encoding +from portage import _fs_encoding +from portage import _unicode_decode +from portage import _unicode_encode import portage portage.proxy.lazyimport.lazyimport(globals(), 'portage.dep:dep_getkey,get_operator,isvalidatom,isjustname,remove_slot', @@ -12,7 +20,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.versions:ververify' ) -from portage.const import USER_CONFIG_PATH, WORLD_FILE +from portage.const import USER_CONFIG_PATH from portage.exception import DirectoryNotFound, PortageException from portage.localization import _ @@ -63,9 +71,10 @@ def fixdbentries(update_iter, dbdir): 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() + mydata[myfile] = codecs.open(_unicode_encode(file_path, + encoding=_fs_encoding, errors='strict'), + mode='r', encoding=_content_encoding, + errors='replace').read() updated_items = update_dbentries(update_iter, mydata) for myfile, mycontent in updated_items.iteritems(): file_path = os.path.join(dbdir, myfile) @@ -100,9 +109,9 @@ def grab_updates(updpath, prev_mtimes=None): mystat = os.stat(file_path) if file_path not in prev_mtimes or \ long(prev_mtimes[file_path]) != long(mystat.st_mtime): - f = open(file_path) - content = f.read() - f.close() + content = codecs.open(_unicode_encode(file_path, + encoding=_fs_encoding, errors='strict'), + mode='r', encoding=_content_encoding, errors='replace').read() update_data.append((file_path, mystat, content)) return update_data @@ -142,17 +151,12 @@ def parse_updates(mycontent): return myupd, errors def update_config_files(config_root, protect, protect_mask, update_iter): - """Perform global updates on /etc/portage/package.* and the world file. + """Perform global updates on /etc/portage/package.*. config_root - location of files to update protect - list of paths from CONFIG_PROTECT protect_mask - list of paths from CONFIG_PROTECT_MASK update_iter - list of update commands as returned from parse_updates()""" - if isinstance(config_root, unicode): - # Avoid UnicodeDecodeError raised from - # os.path.join when called by os.walk. - config_root = config_root.encode('utf_8', 'replace') - config_root = normalize_path(config_root) update_files = {} file_contents = {} @@ -166,9 +170,20 @@ def update_config_files(config_root, protect, protect_mask, update_iter): if os.path.isdir(config_file): for parent, dirs, files in os.walk(config_file): for y in dirs: + try: + y = _unicode_decode(y, + encoding=_fs_encoding, errors='strict') + except UnicodeDecodeError: + dirs.remove(y) + continue if y.startswith("."): dirs.remove(y) for y in files: + try: + y = _unicode_decode(y, + encoding=_fs_encoding, errors='strict') + except UnicodeDecodeError: + continue if y.startswith("."): continue recursivefiles.append( @@ -178,9 +193,11 @@ def update_config_files(config_root, protect, protect_mask, update_iter): myxfiles = recursivefiles for x in myxfiles: try: - myfile = open(os.path.join(abs_user_config, x),"r") - file_contents[x] = myfile.readlines() - myfile.close() + file_contents[x] = codecs.open( + _unicode_encode(os.path.join(abs_user_config, x), + encoding=_fs_encoding, errors='strict'), + mode='r', encoding=_content_encoding, + errors='replace').readlines() except IOError: if file_contents.has_key(x): del file_contents[x] |