Collecting Linux Distribution
Ξ March 20th, 2011 | → 0 Comments |
∇ Tools | ∇ Distributiom, Linux, Python |
For me, a really useful tool… I keep it in my dropbox toolbox, always available at ~/bin
#! /usr/bin/env python
# *************************************************************************
# Collect the “Release” information for the Linux Distribution
# *************************************************************************
import os
issue_redhat = “/etc/redhat-release”
issue_ubuntu = “/etc/issue.net”
issue_debian = “/etc/debian_version”
def get_content(file):
return open(file, “rb”).read()
def get_release():
print ” System: ” + os.uname()[0]
print ” Release: ” + os.uname()[2]
print “Architecture: ” + os.uname()[4]
if( os.path.exists(issue_redhat) ):
distribution = get_content(issue_redhat)
elif( os.path.exists(issue_ubuntu) ):
distribution = get_content(issue_ubuntu)
elif( os.path.exists(issue_debian) ):
distribution = get_content(issue_debian)
else:
distribution = “Unable to find distribution.”
print “Distribution: ” + distribution
if __name__ == “__main__”:
get_release()