[entropy.tools] some more module cleanup work
This commit is contained in:
+11
-3
@@ -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
|
||||
|
||||
@@ -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
@@ -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(":")
|
||||
|
||||
@@ -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+'
|
||||
|
||||
Reference in New Issue
Block a user