Clean up imports and unused variables.
authorZac Medico <zmedico@gentoo.org>
Tue, 2 Mar 2010 21:33:35 +0000 (21:33 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 2 Mar 2010 21:33:35 +0000 (21:33 -0000)
svn path=/main/trunk/; revision=15716

pym/portage/util/__init__.py

index ad2b8b9feda8a47bff906608d5df6c5c1f9106da..e7296126933d04d241b0f8f384090b7aec952d5a 100644 (file)
@@ -12,11 +12,8 @@ __all__ = ['apply_permissions', 'apply_recursive_permissions',
        'stack_dicts', 'stack_lists', 'unique_array', 'varexpand', 'write_atomic',
        'writedict', 'writemsg', 'writemsg_level', 'writemsg_stdout']
 
-try:
-       from subprocess import getstatusoutput as subprocess_getstatusoutput
-except ImportError:
-       from commands import getstatusoutput as subprocess_getstatusoutput
 import codecs
+from copy import deepcopy
 import errno
 import logging
 import re
@@ -24,26 +21,24 @@ import shlex
 import stat
 import string
 import sys
+import traceback
 
 import portage
 from portage import StringIO
 from portage import os
+from portage import pickle
+from portage import subprocess_getstatusoutput
 from portage import _encodings
 from portage import _os_merge
 from portage import _unicode_encode
 from portage import _unicode_decode
 from portage.exception import InvalidAtom, PortageException, FileNotFound, \
        OperationNotPermitted, PermissionDenied, ReadOnlyFileSystem
-from portage.dep import Atom, isvalidatom
+from portage.dep import Atom
 from portage.localization import _
 from portage.proxy.objectproxy import ObjectProxy
 from portage.cache.mappings import UserDict
 
-try:
-       import cPickle as pickle
-except ImportError:
-       import pickle
-
 noiselimit = 0
 
 def initialize_logger(level=logging.WARN):
@@ -611,7 +606,6 @@ def varexpand(mystring, mydict={}):
 pickle_write = None
 
 def pickle_read(filename,default=None,debug=0):
-       import os
        if not os.access(filename, os.R_OK):
                writemsg(_("pickle_read(): File not readable. '")+filename+"'\n",1)
                return default
@@ -632,7 +626,6 @@ def pickle_read(filename,default=None,debug=0):
        return data
 
 def dump_traceback(msg, noiselevel=1):
-       import sys, traceback
        info = sys.exc_info()
        if not info[2]:
                stack = traceback.extract_stack()[:-1]
@@ -751,7 +744,6 @@ def apply_permissions(filename, uid=-1, gid=-1, mode=-1, mask=-1,
                        if follow_links:
                                os.chown(filename, uid, gid)
                        else:
-                               import portage.data
                                portage.data.lchown(filename, uid, gid)
                        modified = True
                except OSError as oe:
@@ -901,7 +893,6 @@ def apply_secpass_permissions(filename, uid=-1, gid=-1, mode=-1, mask=-1,
 
        all_applied = True
 
-       import portage.data # not imported globally because of circular dep
        if portage.data.secpass < 2:
 
                if uid != -1 and \
@@ -1177,7 +1168,6 @@ class LazyItemsDict(UserDict):
                """
                if memo is None:
                        memo = {}
-               from copy import deepcopy
                result = self.__class__()
                memo[id(self)] = result
                for k in self:
@@ -1224,7 +1214,6 @@ class LazyItemsDict(UserDict):
                        """
                        if memo is None:
                                memo = {}
-                       from copy import deepcopy
                        result = self.__copy__()
                        memo[id(self)] = result
                        result.func = deepcopy(self.func, memo)
@@ -1251,7 +1240,6 @@ class ConfigProtect(object):
                for x in self.protect_list:
                        ppath = normalize_path(
                                os.path.join(self.myroot, x.lstrip(os.path.sep)))
-                       mystat = None
                        try:
                                if stat.S_ISDIR(os.stat(ppath).st_mode):
                                        self._dirs.add(ppath)
@@ -1264,7 +1252,6 @@ class ConfigProtect(object):
                for x in self.mask_list:
                        ppath = normalize_path(
                                os.path.join(self.myroot, x.lstrip(os.path.sep)))
-                       mystat = None
                        try:
                                """Use lstat so that anything, even a broken symlink can be
                                protected."""
@@ -1351,7 +1338,6 @@ def new_protect_filename(mydest, newmd5=None):
                "._cfg" + str(prot_num).zfill(4) + "_" + real_filename))
        old_pfile = normalize_path(os.path.join(real_dirname, last_pfile))
        if last_pfile and newmd5:
-               import portage.checksum
                try:
                        last_pfile_md5 = portage.checksum._perform_md5_merge(old_pfile)
                except FileNotFound: