flake8: depends #1282

Merged
g1itch merged 5 commits from flake8-depends into v0.6 2018-06-27 11:24:56 +02:00
Showing only changes of commit e92a85e1c5 - Show all commits

View File

@ -28,6 +28,14 @@ logger = logging.getLogger('both')
logger.addHandler(handler)
logger.setLevel(logging.ERROR)
OS_RELEASE = {
"fedora": "Fedora",
"opensuse": "openSUSE",
"ubuntu": "Ubuntu",
"gentoo": "Gentoo",
"calculate": "Gentoo"
}
PACKAGE_MANAGER = {
"OpenBSD": "pkg_add",
"FreeBSD": "pkg install",
@ -128,20 +136,9 @@ def detectOSRelease():
version = None
for line in osRelease:
if line.startswith("NAME="):
line = line.lower()
if "fedora" in line:
detectOS.result = "Fedora"
elif "opensuse" in line:
detectOS.result = "openSUSE"
elif "ubuntu" in line:
detectOS.result = "Ubuntu"
elif "debian" in line:
detectOS.result = "Debian"
elif "gentoo" in line or "calculate" in line:
detectOS.result = "Gentoo"
else:
detectOS.result = None
if line.startswith("VERSION_ID="):
detectOS.result = OS_RELEASE.get(
line.split("=")[-1].strip().lower())
elif line.startswith("VERSION_ID="):
try:
version = float(line.split("=")[1].replace("\"", ""))
except ValueError:
omkar1117 commented 2018-06-23 12:20:03 +02:00 (Migrated from github.com)
Review

I think we can move with a easy way instead of this.

I think we can move with a easy way instead of this.
omkar1117 commented 2018-06-23 12:25:58 +02:00 (Migrated from github.com)
Review

/code
with open("/etc/os-release", 'r') as osRelease:
for line in osRelease:
if line.startswith("NAME="):
detectOS.result = line.split("=")[-1].strip().capitalize()

/code with open("/etc/os-release", 'r') as osRelease: for line in osRelease: if line.startswith("NAME="): detectOS.result = line.split("=")[-1].strip().capitalize()
g1itch commented 2018-06-23 12:31:29 +02:00 (Migrated from github.com)
Review

capitalize()? What about openSUSE?

capitalize()? What about openSUSE?
g1itch commented 2018-06-23 12:32:53 +02:00 (Migrated from github.com)
Review

BTW, it's not my code, I just moved it from checkdeps, see above.

BTW, it's not my code, I just moved it from `checkdeps`, see above.
omkar1117 commented 2018-06-23 12:41:00 +02:00 (Migrated from github.com)
Review

ok, I think then we can have a dictionary and call the name based on the key simply.
osname = {'ubuntu' : 'Ubuntu', 'opensuse' : 'openSUSE' , ….}

with open("/etc/os-release", 'r') as osRelease:
for line in osRelease:
if line.startswith("NAME="):
detectOS.result = osname(line.split("=")[-1].strip().lower())

ok, I think then we can have a dictionary and call the name based on the key simply. osname = {'ubuntu' : 'Ubuntu', 'opensuse' : 'openSUSE' , ….} with open("/etc/os-release", 'r') as osRelease: for line in osRelease: if line.startswith("NAME="): detectOS.result = osname(line.split("=")[-1].strip().lower())