summaryrefslogtreecommitdiffstats
path: root/bin/hostinfo
diff options
context:
space:
mode:
Diffstat (limited to 'bin/hostinfo')
-rwxr-xr-xbin/hostinfo30
1 files changed, 27 insertions, 3 deletions
diff --git a/bin/hostinfo b/bin/hostinfo
index 8876c54..43fd5b4 100755
--- a/bin/hostinfo
+++ b/bin/hostinfo
@@ -44,6 +44,21 @@ def print_keys(path):
data = _get_data(path)
_print_keys(data)
+def print_hosts(path, short):
+ metadata = os.path.join(path, 'metadata', 'hosts')
+ if os.path.exists(metadata):
+ hosts = yaml.load(file(metadata, 'r'))
+ if 'hosts' in hosts:
+ for host in hosts['hosts']:
+ if short:
+ print(host.replace('.spline.inf.fu-berlin.de',''))
+ else:
+ print(host)
+ return True
+
+ sys.stderr.write("'%s' not found!\n" % metadata)
+ return False
+
def find_host(basepath, host):
path = os.path.join(basepath, host)
if os.path.exists(path):
@@ -77,11 +92,13 @@ def main():
if 'HOSTINFO_PATH' in os.environ:
basepath = os.environ['HOSTINFO_PATH']
- file = oneline = keys = verbose = nospaces = help = False
+ file = oneline = keys = verbose = nospaces = help = \
+ hosts = short = False
try:
- optlist, args = getopt.gnu_getopt(sys.argv, 'ofkvnh?p:',
+ optlist, args = getopt.gnu_getopt(sys.argv, 'ofkvnh?p:ls',
['oneline', 'file', 'keys', 'verbose',
- 'nospaces', 'help', 'path='])
+ 'nospaces', 'help', 'path=', 'hosts',
+ 'short'])
opts = {}
for key, value in optlist:
opts[key] = value
@@ -92,6 +109,8 @@ def main():
verbose = any([o in opts for o in ['--verbose', '-v']])
nospaces = any([o in opts for o in ['--nospaces', '-n']])
help = any([o in opts for o in ['--help', '-h', '-?']])
+ hosts = any([o in opts for o in ['--hosts', '-l']])
+ short = any([o in opts for o in ['--short', '-s']])
if any([o in opts for o in ['--path', '-p']]):
basepath = [opts[o] for o in ['--path', '-p'] if o in opts][0]
@@ -100,6 +119,11 @@ def main():
print
args = []
+ if hosts:
+ if not print_hosts(basepath, short):
+ sys.exit(1)
+ sys.exit(0)
+
if help or len(args) < 1:
print_help(self_name)
if not help: