#!/usr/bin/python

import isi.hw.hal as hal
import isi.hw.bootstrap as bootstrap
import sys

if len(sys.argv) != 2:
    print 'usage: isi_hal_predicate name (Python)'
    sys.exit(2)

predicate = sys.argv[1]

usebootstrap = False

result = hasattr(hal, predicate)
if result != True:
    result = hasattr(bootstrap, predicate)
    usebootstrap = (result == True)
print result

if result != True:
    print 'isi_hal_predicate: \'%s\' is not a valid HAL predicate' % predicate
    sys.exit(2)

# XXX https://github.west.isilon.com/isilon/onefs/commit/92af6ee519402aabb6f7c173234e5ccf9efe3e45
# XXX Above commit broke isi_hal_predicate because many hal attributes are lists.
# XXX This change introduced a lot of TypeError tracebacks. The commit added
# XXX an int() wrapper, trying to surgically make it at least 'better'?
# XXX If we know a priori if it is an int we're ok, but probably simplest
# XXX to just use try/except.
if usebootstrap:
    rc = getattr(bootstrap, predicate)()
else:
    rc = getattr(hal, predicate)()
try:
    rc = int(rc)
except:
    pass
print rc
sys.exit(rc)

