From 707ee6008fecd00bafdd1ac5a5ff40b03e61a29b Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Mon, 18 Jan 2010 17:24:07 +0100 Subject: [PATCH] [entropy.tools] some more module cleanup work --- client/text_smart.py | 14 ++++++-- libraries/entropy/qa.py | 2 +- libraries/entropy/tools.py | 71 +++++++++----------------------------- libraries/tests/tools.py | 5 --- 4 files changed, 28 insertions(+), 64 deletions(-) diff --git a/client/text_smart.py b/client/text_smart.py index 3ebc00ed1..8262682fe 100644 --- a/client/text_smart.py +++ b/client/text_smart.py @@ -105,8 +105,12 @@ def quickpkg_handler(entropy_client, mypackages, savedir = None): else: if not etpUi['quiet']: print_warning(darkred(" * ") + \ red("%s: " % (_("Cannot find"),))+bold(opt)) - packages = entropy.tools.filter_duplicated_entries(packages) - if (not packages): + pkgs = [] + for pkg in packages: + if pkg not in pkgs: + pkgs.append(pkg) + packages = pkgs + if not packages: print_error(darkred(" * ")+red("%s." % (_("No valid packages specified"),))) return 2 @@ -286,7 +290,11 @@ def smart_pkg_handler(entropy_client, mypackages): packages.append(match) else: print_warning(darkred(" * ")+red("%s: " % (_("Cannot find"),))+bold(opt)) - packages = entropy.tools.filter_duplicated_entries(packages) + pkgs = [] + for pkg in packages: + if pkg not in pkgs: + pkgs.append(pkg) + packages = pkgs if not packages: print_error(darkred(" * ")+red("%s." % (_("No valid packages specified"),))) return 2 diff --git a/libraries/entropy/qa.py b/libraries/entropy/qa.py index 766ffa31a..71278cffc 100644 --- a/libraries/entropy/qa.py +++ b/libraries/entropy/qa.py @@ -540,7 +540,7 @@ class QAInterface(EntropyPluginStore): broken_libs_mask_regexp.append(reg_lib) ldpaths = set(entropy.tools.collect_linker_paths()) - ldpaths |= entropy.tools.collect_paths() + ldpaths.update(entropy.tools.collect_paths()) # some crappy packages put shit here too ldpaths.add("/usr/share") diff --git a/libraries/entropy/tools.py b/libraries/entropy/tools.py index 08bb5b95e..6e1fb76ba 100644 --- a/libraries/entropy/tools.py +++ b/libraries/entropy/tools.py @@ -2274,22 +2274,6 @@ def istext(mystring): return False return True -# this functions removes duplicates without breaking the list order -# nameslist: a list that contains duplicated names -# @returns filtered list -def filter_duplicated_entries(alist): - """ - docstring_title - - @param alist: - @type alist: - @return: - @rtype: - """ - mydata = {} - return [mydata.setdefault(e, e) for e in alist if e not in mydata] - - # Escapeing functions mappings = { "'":"''", @@ -3086,14 +3070,6 @@ def resolve_dynamic_library(library, requiring_executable): @rtype: string """ def do_resolve(mypaths): - """ - docstring_title - - @param mypaths: - @type mypaths: - @return: - @rtype: - """ found_path = None for mypath in mypaths: mypath = os.path.join(etpConst['systemroot']+mypath, library) @@ -3426,43 +3402,28 @@ def extract_packages_from_set_file(filepath): def collect_linker_paths(): """ - docstring_title + Collect dynamic linker paths set into /etc/ld.so.conf. This function is + ROOT safe. - @return: - @rtype: + @return: list of dynamic linker paths set + @rtype: list """ - ldpaths = [] - try: - f = open(etpConst['systemroot']+"/etc/ld.so.conf", "r") - paths = f.readlines() - for path in paths: - path = path.strip() - if path: - if path[0] == "/": - ldpaths.append(os.path.normpath(path)) - f.close() - except (IOError, OSError, TypeError, ValueError, IndexError,): - pass + ld_conf = etpConst['systemroot']+"/etc/ld.so.conf" + if not (os.path.isfile(ld_conf) and os.access(ld_conf, os.R_OK)): + return [] - # can happen that /lib /usr/lib are not in LDPATH - if "/lib" not in ldpaths: - ldpaths.append("/lib") - if "/usr/lib" not in ldpaths: - ldpaths.append("/usr/lib") - - return ldpaths + ld_f = open(ld_conf, "r") + paths = [os.path.normpath(x.strip()) for x in ld_f.readlines() \ + if x.startswith("/")] + ld_f.close() + return paths def collect_paths(): """ - docstring_title + Return env var PATH value split using ":" as separator. - @return: - @rtype: + @return: list of PATHs + @rtype: list """ - path = set() - paths = os.getenv("PATH") - if paths != None: - paths = set(paths.split(":")) - path |= paths - return path + return os.getenv("PATH", "").split(":") diff --git a/libraries/tests/tools.py b/libraries/tests/tools.py index 0ea0fa5a7..3ab1305f7 100644 --- a/libraries/tests/tools.py +++ b/libraries/tests/tools.py @@ -531,11 +531,6 @@ class ToolsTest(unittest.TestCase): os.close(fd) os.remove(tmp_path) - def test_filter_duplicated_entries(self): - begin = ["1.0", "2", "1.0", "3"] - end = ["1.0", "2", "3"] - self.assertEqual(et.filter_duplicated_entries(begin), end) - def test_escape(self): begin = "casdasdas\"asdasdasd\" sadasd " end = 'casdasdas""asdasdasd""+sadasd+'