#!/usr/bin/env python
from kickstand import ShellCommand
import json
import os

if( __name__ == '__main__' ):
  osname = None
  osversion = None
  oskernel = None
  osarch = None

  osname = ShellCommand.execute('/bin/uname -o')[0].split('\n')[0]
  osversion = ShellCommand.execute('/bin/uname -v')[0].split('\n')[0]
  oskernel = ShellCommand.execute('/bin/uname -r')[0].split('\n')[0]
  osarch = ShellCommand.execute('/bin/uname -i')[0].split('\n')[0]

  # RedHat Check
  if( os.path.exists('/etc/redhat-release') ):
    with file('/etc/redhat-release', 'r') as redhat_file:
      redhat_line = redhat_file.readlines()[0]
      osversion = redhat_line.split()[6]
      osname = ' '.join(redhat_line.split()[:5])

  print json.dumps({
    'system': {
      'os': {
        'os': osname,
        'osversion': osversion,
        'osarch': osarch,
        'oskernel': oskernel,
      }
    }
  })
  
