Skip to content

Instantly share code, notes, and snippets.

@tcarrio
Last active February 9, 2016 17:28
Show Gist options
  • Save tcarrio/c2ee34b45d0a1e1734f4 to your computer and use it in GitHub Desktop.
Save tcarrio/c2ee34b45d0a1e1734f4 to your computer and use it in GitHub Desktop.
distro-agnostic-get_os-release
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