Last active
February 9, 2016 17:28
-
-
Save tcarrio/c2ee34b45d0a1e1734f4 to your computer and use it in GitHub Desktop.
distro-agnostic-get_os-release
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filenames = ['/etc/os-release'] # add any other distro locations for os-release | |
def read_release(): | |
for filename in filenames: | |
if os.path.isfile(filename): | |
with open('/etc/os-release', 'r') as relfile: | |
for line in relfile: | |
if('NAME ' in line): | |
release_dict(line.split(' ')[1]) | |
def release_dict(file_loc,name): | |
ddict = {} | |
delim = get_delimiter() | |
with open(filename,'r') as relfile: | |
for line in relfile: | |
ll = line.strip('\n').replace('\"', '').split(delim) | |
if len(ll) > 1: | |
ddict[ll[0].lower()] = ll[1] | |
return ddict | |
def get_delimiter(): | |
if("Red Hat" in name): | |
return "=" | |
elif("Ubuntu" in name): | |
return " " | |
elif("Elementary" in name): | |
return " " | |
else | |
return ":" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment