blob: d3ec30713c6a3f7ad68d1cdacb3fe5602916d90c [file] [log] [blame]
#!/usr/bin/python
# Copyright 2012 Google Inc. All Rights Reserved.
#
import re
import sys
__author__ = 'Avery Pennarun (apenwarr@google.com)'
def main():
data = sys.stdin.read().strip()
header_comment = re.sub(re.compile(r'^', re.M), '# ', data)
elements = []
ether = None
g = re.search(re.compile(r'^(?:1ST_SERIAL_NUMBER=|SERIAL_NO=)(.+)', re.M),
data)
if g:
elements.append('serialno=%r' % g.group(1))
g = re.search(re.compile(r'^PLATFORM_NAME=(.+)', re.M), data)
if g:
platform = g.group(1).upper()
elements.append('platform=%r' % platform)
if platform.startswith('GFMS'):
elements.append('is_storage=1')
elif platform.startswith('GFHD'):
elements.append('is_tv=1')
if re.search(re.compile(r'^NET_OK=1', re.M), data):
elements.append('is_alive=1')
elements.append('is_alive_net=1')
if re.search(re.compile(r'^IS_NFSROOT=1', re.M), data):
elements.append('is_nfsroot=1')
g = re.search(re.compile(r'^SERIALPORT=(.+)', re.M), data)
if g:
elements.append('is_alive=1')
elements.append('serialport=%r' % g.group(1))
g = re.search(r'inet ([\d\.]+)', data)
if g:
elements.append('ip=%r' % g.group(1))
g = re.search(r'inet6 ([a-fA-F0-9:]+)', data)
if g:
elements.append('ip6=%r' % g.group(1).lower())
g = re.search(r'link/ether ([a-fA-F0-9:]+)', data)
if g:
ether = g.group(1)
elements.append('ether=%r' % g.group(1).lower())
if re.search(r'eth0:.*LOWER_UP', data):
elements.append('has_ether=1')
if re.search(r'eth1:.*LOWER_UP', data):
elements.append('has_moca=1')
if re.search(r'eth2:.*LOWER_UP', data):
elements.append('has_wifi=1')
g = re.search(r'system type\s*:\s*(\S+)', data)
if g:
elements.append('cpu=%r' % g.group(1).upper())
sys.stdout.write('\n%s\n' % header_comment)
if elements and ether:
sys.stdout.write('h = hosts.FindOrAdd(ether=%r)\n' % ether)
for e in elements:
sys.stdout.write('h.%s\n' % e)
if __name__ == '__main__':
main()