Update imports to import portage.os (with unicode wrappers), and use
authorZac Medico <zmedico@gentoo.org>
Tue, 11 Aug 2009 23:00:42 +0000 (23:00 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 11 Aug 2009 23:00:42 +0000 (23:00 -0000)
_unicode_encode() and _unicode_decode() where appropriate.

svn path=/main/trunk/; revision=14002

pym/portage/cache/anydbm.py
pym/portage/cache/ebuild_xattr.py
pym/portage/cache/flat_hash.py
pym/portage/cache/flat_list.py
pym/portage/cache/fs_template.py
pym/portage/cache/metadata.py
pym/portage/cache/sqlite.py

index 9007a1a5679d34cba3a1f5b7142a3c8948d0a9b0..226c6d7d0d52d3fe7faf1a1cec3fe93dadf1738e 100644 (file)
@@ -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)
index 98e848651a9ac819815069a28f4a174c9524a383..baba94321b801b1cff78c7ac1f46743761e34741 100644 (file)
@@ -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]
index c3c5955fb211b4c970e812e087b3838714bf8bcd..2467f68002f3673b901b60310c3c1937a72f87c9 100644 (file)
@@ -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)
index 8734e79b05fc93111aeb118ebde324e1c37d809f..9906dd22dbc5405fb2b2242fc747288d8e8298f9 100644 (file)
@@ -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:
index d41749186c1f80754333f126f58ca532e3e73ee6..6d08f345f75a8c48f30145573a184581576a5ade 100644 (file)
@@ -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 
index b51bf980f0ea0b8a245a8c4c7418f4ab5bd4fe2c..e91ed68d22ed82db393236307b37cc58676c38cb 100644 (file)
@@ -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:
index a0b11165f6d1ee8964c9d4aa006a2afe9e380a93..0a842488000eff64cd5ac7a1e20bc62bc6a032bb 100644 (file)
@@ -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):