refactor dir list reading

This commit is contained in:
Bela 2018-11-02 18:47:53 +01:00
parent 3bbe6b367a
commit 137e1d5195

View file

@ -14,27 +14,21 @@ def readInstallDirectoriesFromConfig():
"""Read the config file and find install dirs.
Returns:
a list consisting of the install directories specified in
a set consisting of the install directories specified in
the config file. An empty list in case of non-existing config
file.
"""
installdirs = []
try:
with open(CONFIGFILE, "r") as configfile:
for line in [l.strip("\n") for l in configfile.readlines() if
l.startswith(CONFIG_INSTALLDIR + CONFIG_SEPARATOR)]:
try:
installdirs.append(line.split(CONFIG_SEPARATOR,
maxsplit=1 # max 2 parts
)[1])
except IndexError:
print("Debug: impossible index error " +
"in config file reading.")
return installdirs
return {
line.strip("\n").split(CONFIG_SEPARATOR, maxsplit=1)[1]
for line in configfile.readlines()
if line.startswith(CONFIG_INSTALLDIR + CONFIG_SEPARATOR)
} # set for removind duplicates
except FileNotFoundError:
print("Debug: no config file found.")
return []
return set()
def removeInstallationLinks(where):