[entropy] some more misc python3.x fixes

This commit is contained in:
Fabio Erculiani
2011-02-10 19:57:22 +01:00
parent 65ddc4e412
commit c5d13d0c60
5 changed files with 32 additions and 12 deletions
+10
View File
@@ -819,6 +819,16 @@ class Dependency(object):
"""
return self.__dep
def __bool__(self):
"""
Same as __nonzero__ but meant for Python 3.x support
"""
for entropy_repository in self.__entropy_repository_list:
pkg_id, res = entropy_repository.atomMatch(self.__dep)
if res == 0:
return True
return False
def __nonzero__(self):
"""
Tries to match entropy_dep and returns True or False if dependency
+1 -1
View File
@@ -148,7 +148,7 @@ class Lifo(object):
@return: None
@rtype: None
"""
for key, buf_entry in self.__buf.items():
for key, buf_entry in tuple(self.__buf.items()):
# identity is generally faster, so try
# this first
if self.__buf is None: # shutting down py
+10 -1
View File
@@ -13,6 +13,7 @@
"""
import os
import sys
import errno
import shutil
import subprocess
@@ -22,7 +23,8 @@ import time
from entropy.exceptions import EntropyException
from entropy.const import etpConst, etpUi, const_setup_perms, \
const_debug_write, const_setup_file, const_convert_to_unicode
const_debug_write, const_setup_file, const_convert_to_unicode, \
const_convert_to_rawstring
from entropy.i18n import _
from entropy.output import blue, bold, red, darkgreen, darkred, purple, brown
from entropy.cache import EntropyCacher
@@ -1558,6 +1560,8 @@ class Repository:
proc = subprocess.Popen(args,
**self.__default_popen_args(stderr = True))
try:
if sys.hexversion >= 0x3000000:
key_input = const_convert_to_rawstring(key_input)
# feed gpg with data
proc_stdout, proc_stderr = proc.communicate(input = key_input)
# wait for process to terminate
@@ -1569,6 +1573,9 @@ class Repository:
raise Repository.GPGError(
"cannot generate key, exit status %s" % (proc_rc,))
if sys.hexversion >= 0x3000000:
proc_stdout = const_convert_to_unicode(proc_stdout)
proc_stderr = const_convert_to_unicode(proc_stderr)
# now get fucking fingerprint
key_data = [x.strip() for x in (proc_stdout+proc_stderr).split("\n") \
if x.strip() and "KEY_CREATED" in x.split()]
@@ -1812,6 +1819,8 @@ class Repository:
fingerprint, proc_rc,))
key_string = proc.stdout.read()
if sys.hexversion >= 0x3000000:
key_string = const_convert_to_unicode(key_string)
return key_string
finally:
self.__default_popen_close(proc)
@@ -928,7 +928,6 @@ class PortagePlugin(SpmPlugin):
tmp_fd, tmp_file = tempfile.mkstemp(prefix = "etp_portage")
try:
with os.fdopen(tmp_fd, "w") as std_f:
cmd = const_convert_to_rawstring(cmd)
proc = subprocess.Popen(shlex.split(cmd), stdout = std_f,
stderr = std_f)
sts = proc.wait()
@@ -1686,7 +1685,7 @@ class PortagePlugin(SpmPlugin):
static_file_class = sets_obj.files.StaticFileSet
# filter out Portage-generated sets object, those not being
# an instance of portage._sets.files.StaticFileSet
for key, obj in mysets.items():
for key, obj in tuple(mysets.items()):
if not isinstance(obj, static_file_class):
mysets.pop(key)
@@ -2518,7 +2517,10 @@ class PortagePlugin(SpmPlugin):
portdb = self._get_portage_portagetree(root).dbapi
mdigest = hashlib.md5()
# this way, if no matches are found, the same value is returned
mdigest.update("begin")
if sys.hexversion >= 0x3000000:
mdigest.update(const_convert_to_rawstring("begin"))
else:
mdigest.update("begin")
for repo_name in portdb.getRepositories():
repo_path = portdb.getRepositoryPath(repo_name)
@@ -3172,12 +3174,12 @@ class PortagePlugin(SpmPlugin):
new = open(world_file_tmp, "wb")
old = open(world_file, "rb")
line = old.readline()
key = const_convert_to_rawstring(key)
key_raw = const_convert_to_rawstring(key)
keyslot = const_convert_to_rawstring(key+":"+slot)
while line:
if line.find(key) != -1:
if line.find(key_raw) != -1:
line = old.readline()
continue
if line.find(keyslot) != -1:
@@ -45,7 +45,7 @@ def _addtolist(mylist, curdir, _nested = False):
mylist.append(x_path)
if not _nested:
for idx in xrange(len(mylist)):
for idx in range(len(mylist)):
mylist[idx] = mylist[idx][len(curdir)+1:]
def encodeint(myint):
@@ -86,10 +86,9 @@ def xpak(rootdir, outfile=None):
mylist.sort()
mydata = {}
for x in mylist:
x_path = os.path.join(rootdir, x)
a = open(x_path, "rb")
mydata[x] = a.read()
a.close()
x_path = os.path.join(const_convert_to_rawstring(rootdir), x)
with open(x_path, "rb") as a:
mydata[x] = a.read()
xpak_segment = xpak_mem(mydata)
if outfile: