[entropy.tools] some more module cleanup work

This commit is contained in:
Fabio Erculiani
2010-01-18 17:24:07 +01:00
parent dc7770c348
commit 707ee6008f
4 changed files with 28 additions and 64 deletions
+11 -3
View File
@@ -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
+1 -1
View File
@@ -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")
+16 -55
View File
@@ -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(":")
-5
View File
@@ -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+'