[equo] "equo query orphans": rework encoding usage, now use "raw_unicode_escape"

This because retrieveContent() returns files encoded using
"raw_unicode_escape". In this way, we can use simple set intersection
afterwards.
This commit is contained in:
Fabio Erculiani
2012-05-28 15:42:01 +02:00
parent 0de9f11990
commit b5a0edbab6

View File

@@ -577,6 +577,10 @@ def search_orphaned_files(entropy_client):
reverse_symlink_map = sys_set['system_rev_symlinks'] reverse_symlink_map = sys_set['system_rev_symlinks']
system_dirs_mask = [x for x in sys_set['system_dirs_mask'] \ system_dirs_mask = [x for x in sys_set['system_dirs_mask'] \
if entropy.tools.is_valid_path(x)] if entropy.tools.is_valid_path(x)]
# make sure we're all rawstring.
system_dirs_mask = [const_convert_to_rawstring(x) for x in \
system_dirs_mask]
system_dirs_mask_regexp = [] system_dirs_mask_regexp = []
for mask in sys_set['system_dirs_mask']: for mask in sys_set['system_dirs_mask']:
reg_mask = re.compile(mask) reg_mask = re.compile(mask)
@@ -584,9 +588,10 @@ def search_orphaned_files(entropy_client):
count = 0 count = 0
for xdir in dirs: for xdir in dirs:
# make sure it's unicode # make sure it's bytes (raw encoding
xdir = const_convert_to_unicode( # as per EntropyRepository.retrieveContent())
xdir, enctype = etpConst['conf_encoding']) xdir = const_convert_to_rawstring(
xdir, from_enctype = etpConst['conf_raw_encoding'])
try: try:
wd = os.walk(xdir) wd = os.walk(xdir)
except RuntimeError: # maximum recursion? except RuntimeError: # maximum recursion?
@@ -617,9 +622,10 @@ def search_orphaned_files(entropy_client):
continue continue
count += 1 count += 1
filename_utf = const_convert_to_unicode(filename)
if not etpUi['quiet'] and ((count == 0) or (count % 500 == 0)): if not etpUi['quiet'] and ((count == 0) or (count % 500 == 0)):
count = 0 count = 0
fname = const_convert_to_unicode(filename[:50]) fname = filename_utf[:50]
print_info(" %s %s: %s" % ( print_info(" %s %s: %s" % (
red("@@"), red("@@"),
blue(_("Analyzing")), blue(_("Analyzing")),
@@ -627,12 +633,7 @@ def search_orphaned_files(entropy_client):
), ),
back = True back = True
) )
try: found_files.add(filename_utf)
found_files.add(const_convert_to_unicode(filename))
except (UnicodeDecodeError, UnicodeEncodeError,) as e:
if etpUi['quiet']:
continue
print_generic("!!! error on", filename, "skipping:", repr(e))
if found_files: if found_files:
file_data |= found_files file_data |= found_files
@@ -703,8 +704,7 @@ def search_orphaned_files(entropy_client):
with open(fname, "wb") as f_out: with open(fname, "wb") as f_out:
for myfile in file_data: for myfile in file_data:
myfile = const_convert_to_rawstring( myfile = const_convert_to_rawstring(myfile)
myfile, from_enctype=etpConst['conf_encoding'])
mysize = 0 mysize = 0
try: try:
mysize += os.stat(myfile)[6] mysize += os.stat(myfile)[6]