summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2013-05-17 15:30:52 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2013-05-17 15:39:44 +0200
commit27436f8b8a84fa70bba3a7b7d286fd3eba37fbfe (patch)
treeff12eeb60b4ade2b56cf6b485712ff3c26e81f4a /bin
parent6c33ef52d422cfe2b924d9e1da16266159b5d3b2 (diff)
downloadtools-27436f8b8a84fa70bba3a7b7d286fd3eba37fbfe.tar.gz
tools-27436f8b8a84fa70bba3a7b7d286fd3eba37fbfe.tar.bz2
tools-27436f8b8a84fa70bba3a7b7d286fd3eba37fbfe.zip
bin/hostinfo: add support for --hosts and --short
You could now use --hosts to get a listing of all available hosts with in the current basepath (set by HOSTINFO_PATH or --path or the default value /usr/local/share/hostinfo/). If you use --short you will remove the domain spline.inf.fu-berlin.de from the output and you will get only the hostnames.
Diffstat (limited to 'bin')
-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: