summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-08-11 23:00:42 +0000
committerZac Medico <zmedico@gentoo.org>2009-08-11 23:00:42 +0000
commite6ab16f4920e0f426c3096470c35dde22dc15de6 (patch)
tree01094d8cf54623078fafd08fd0b701f27543c390
parent268de910a8e459125c12c6f7eaab1a59d59c2a0e (diff)
downloadportage-e6ab16f4920e0f426c3096470c35dde22dc15de6.tar.gz
portage-e6ab16f4920e0f426c3096470c35dde22dc15de6.tar.bz2
portage-e6ab16f4920e0f426c3096470c35dde22dc15de6.zip
Update imports to import portage.os (with unicode wrappers), and use
_unicode_encode() and _unicode_decode() where appropriate. svn path=/main/trunk/; revision=14002
-rw-r--r--pym/portage/cache/anydbm.py10
-rw-r--r--pym/portage/cache/ebuild_xattr.py13
-rw-r--r--pym/portage/cache/flat_hash.py15
-rw-r--r--pym/portage/cache/flat_list.py15
-rw-r--r--pym/portage/cache/fs_template.py8
-rw-r--r--pym/portage/cache/metadata.py13
-rw-r--r--pym/portage/cache/sqlite.py8
7 files changed, 46 insertions, 36 deletions
diff --git a/pym/portage/cache/anydbm.py b/pym/portage/cache/anydbm.py
index 9007a1a56..226c6d7d0 100644
--- a/pym/portage/cache/anydbm.py
+++ b/pym/portage/cache/anydbm.py
@@ -8,7 +8,8 @@ try:
import cPickle as pickle
except ImportError:
import pickle
-import os
+from portage import _unicode_encode
+from portage import os
import sys
from portage.cache import fs_template
from portage.cache import cache_errors
@@ -30,8 +31,8 @@ class database(fs_template.FsBased):
self._db_path = os.path.join(self.location, fs_template.gen_label(self.location, self.label)+default_db)
self.__db = None
try:
- self.__db = anydbm_module.open(self._db_path, "w", self._perms)
-
+ self.__db = anydbm_module.open(
+ _unicode_encode(self._db_path), 'w', self._perms)
except anydbm_module.error:
# XXX handle this at some point
try:
@@ -43,7 +44,8 @@ class database(fs_template.FsBased):
# try again if failed
try:
if self.__db == None:
- self.__db = anydbm_module.open(self._db_path, "c", self._perms)
+ self.__db = anydbm_module.open(
+ _unicode_encode(self._db_path), 'c', self._perms)
except anydbm_module.error, e:
raise cache_errors.InitializationError(self.__class__, e)
self._ensure_access(self._db_path)
diff --git a/pym/portage/cache/ebuild_xattr.py b/pym/portage/cache/ebuild_xattr.py
index 98e848651..baba94321 100644
--- a/pym/portage/cache/ebuild_xattr.py
+++ b/pym/portage/cache/ebuild_xattr.py
@@ -9,8 +9,8 @@ __all__ = ['database']
from portage.cache import fs_template
from portage.versions import catsplit
from portage import cpv_getkey
-from portage.util import writemsg
-import os
+from portage import os
+from portage import _unicode_decode
import xattr
from errno import ENODATA,ENOSPC,E2BIG
@@ -154,14 +154,9 @@ class database(fs_template.FsBased):
def __iter__(self):
- portdir = self.portdir
- if isinstance(portdir, unicode):
- # Avoid UnicodeDecodeError raised from
- # os.path.join when called by os.walk.
- portdir = portdir.encode('utf_8', 'replace')
-
- for root, dirs, files in os.walk(portdir):
+ for root, dirs, files in os.walk(self.portdir):
for file in files:
+ file = _unicode_decode(file)
if file[-7:] == '.ebuild':
cat = os.path.basename(os.path.dirname(root))
pn_pv = file[:-7]
diff --git a/pym/portage/cache/flat_hash.py b/pym/portage/cache/flat_hash.py
index c3c5955fb..2467f6800 100644
--- a/pym/portage/cache/flat_hash.py
+++ b/pym/portage/cache/flat_hash.py
@@ -6,9 +6,11 @@
import codecs
from portage.cache import fs_template
from portage.cache import cache_errors
-import errno, os, stat
-from portage.cache.template import reconstruct_eclasses
-# store the current key order *here*.
+import errno
+import stat
+from portage import os
+from portage import _unicode_encode
+
class database(fs_template.FsBased):
autocommits = True
@@ -27,7 +29,8 @@ class database(fs_template.FsBased):
def _getitem(self, cpv):
fp = os.path.join(self.location, cpv)
try:
- myf = codecs.open(fp, mode='r', encoding='utf_8', errors='replace')
+ myf = codecs.open(_unicode_encode(fp),
+ mode='r', encoding='utf_8', errors='replace')
try:
d = self._parse_data(myf.readlines(), cpv)
if '_mtime_' not in d:
@@ -55,13 +58,13 @@ class database(fs_template.FsBased):
s = cpv.rfind("/")
fp = os.path.join(self.location,cpv[:s],".update.%i.%s" % (os.getpid(), cpv[s+1:]))
try:
- myf = codecs.open(fp, mode='w',
+ myf = codecs.open(_unicode_encode(fp), mode='w',
encoding='utf_8', errors='replace')
except (IOError, OSError), e:
if errno.ENOENT == e.errno:
try:
self._ensure_dirs(cpv)
- myf = codecs.open(fp, mode='w',
+ myf = codecs.open(_unicode_encode(fp), mode='w',
encoding='utf_8', errors='replace')
except (OSError, IOError),e:
raise cache_errors.CacheCorruption(cpv, e)
diff --git a/pym/portage/cache/flat_list.py b/pym/portage/cache/flat_list.py
index 8734e79b0..9906dd22d 100644
--- a/pym/portage/cache/flat_list.py
+++ b/pym/portage/cache/flat_list.py
@@ -1,6 +1,10 @@
from portage.cache import fs_template
from portage.cache import cache_errors
-import errno, os, stat
+from portage import os
+from portage import _unicode_encode
+import codecs
+import errno
+import stat
# store the current key order *here*.
class database(fs_template.FsBased):
@@ -27,7 +31,8 @@ class database(fs_template.FsBased):
def _getitem(self, cpv):
d = {}
try:
- myf = open(os.path.join(self._base, cpv),"r")
+ myf = codecs.open(_unicode_encode(os.path.join(self._base, cpv)),
+ mode='r', encoding='utf_8', errors='replace')
for k,v in zip(self.auxdbkey_order, myf):
d[k] = v.rstrip("\n")
except (OSError, IOError),e:
@@ -48,12 +53,14 @@ class database(fs_template.FsBased):
s = cpv.rfind("/")
fp=os.path.join(self._base,cpv[:s],".update.%i.%s" % (os.getpid(), cpv[s+1:]))
try:
- myf = open(fp, "w")
+ myf = codecs.open(_unicode_encode(fp), mode='w',
+ encoding='utf_8', errors='replace')
except (OSError, IOError), e:
if errno.ENOENT == e.errno:
try:
self._ensure_dirs(cpv)
- myf=open(fp,"w")
+ myf = codecs.open(_unicode_encode(fp), mode='w',
+ encoding='utf_8', errors='replace')
except (OSError, IOError),e:
raise cache_errors.CacheCorruption(cpv, e)
else:
diff --git a/pym/portage/cache/fs_template.py b/pym/portage/cache/fs_template.py
index d41749186..6d08f345f 100644
--- a/pym/portage/cache/fs_template.py
+++ b/pym/portage/cache/fs_template.py
@@ -3,16 +3,16 @@
# License: GPL2
# $Id$
-import os
from portage.cache import template
+from portage import os
-import portage.proxy.lazyimport
-import portage.proxy as proxy
-proxy.lazyimport.lazyimport(globals(),
+from portage.proxy.lazyimport import lazyimport
+lazyimport(globals(),
'portage.data:portage_gid',
'portage.exception:PortageException',
'portage.util:apply_permissions',
)
+del lazyimport
class FsBased(template.database):
"""template wrapping fs needed options, and providing _ensure_access as a way to
diff --git a/pym/portage/cache/metadata.py b/pym/portage/cache/metadata.py
index b51bf980f..e91ed68d2 100644
--- a/pym/portage/cache/metadata.py
+++ b/pym/portage/cache/metadata.py
@@ -3,7 +3,10 @@
# License: GPL2
# $Id$
-import errno, os, re, sys
+import errno
+import re
+from portage import os
+from portage import _unicode_encode
from portage.cache import cache_errors, flat_hash
import portage.eclass_cache
from portage.cache.template import reconstruct_eclasses
@@ -82,11 +85,11 @@ class database(flat_hash.database):
for i in xrange(magic_line_count - len(self.auxdbkey_order)):
new_content.append(u'\n')
new_content = u''.join(new_content)
- new_content = new_content.encode('utf_8', 'replace')
+ new_content = _unicode_encode(new_content)
new_fp = os.path.join(self.location, cpv)
try:
- f = open(new_fp, 'rb')
+ f = open(_unicode_encode(new_fp), 'rb')
except EnvironmentError:
pass
else:
@@ -114,12 +117,12 @@ class database(flat_hash.database):
fp = os.path.join(self.location,cpv[:s],
".update.%i.%s" % (os.getpid(), cpv[s+1:]))
try:
- myf = open(fp, 'wb')
+ myf = open(_unicode_encode(fp), 'wb')
except EnvironmentError, e:
if errno.ENOENT == e.errno:
try:
self._ensure_dirs(cpv)
- myf = open(fp, 'wb')
+ myf = open(_unicode_encode(fp), 'wb')
except EnvironmentError, e:
raise cache_errors.CacheCorruption(cpv, e)
else:
diff --git a/pym/portage/cache/sqlite.py b/pym/portage/cache/sqlite.py
index a0b11165f..0a8424880 100644
--- a/pym/portage/cache/sqlite.py
+++ b/pym/portage/cache/sqlite.py
@@ -4,10 +4,10 @@
from portage.cache import fs_template
from portage.cache import cache_errors
-import os
+from portage import os
+from portage import _unicode_encode
from portage.cache.template import reconstruct_eclasses
-from portage.util import writemsg, apply_secpass_permissions
-from portage.data import portage_gid
+from portage.util import writemsg
from portage.localization import _
try:
import sqlite3 as db_module # sqlite3 is optional with >=python-2.5
@@ -59,7 +59,7 @@ class database(fs_template.FsBased):
try:
self._ensure_dirs()
self._db_connection = self._db_module.connect(
- database=self._dbpath, **connection_kwargs)
+ database=_unicode_encode(self._dbpath), **connection_kwargs)
self._db_cursor = self._db_connection.cursor()
self._db_cursor.execute("PRAGMA encoding = %s" % self._db_escape_string("UTF-8"))
if not self._ensure_access(self._dbpath):