summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/hostinfo27
1 files changed, 17 insertions, 10 deletions
diff --git a/bin/hostinfo b/bin/hostinfo
index c7cf8f5..ea785d8 100755
--- a/bin/hostinfo
+++ b/bin/hostinfo
@@ -3,6 +3,7 @@
import sys
import socket
+import getopt
import yaml
import os.path
from dns import resolver,reversename
@@ -14,14 +15,14 @@ if os.path.exists(os.path.join(lib, 'hostinfo')):
from hostinfo import printer
-def print_info(path, key=None):
+def print_info(path, key=None, oneline=False):
stream = file(path, 'r')
data = yaml.load(stream)
- p = printer.Printer(data, False)
+ p = printer.Printer(data, oneline)
p.info(key)
-def find_host(host, key=None):
+def find_host(host, key=None, oneline=False):
path = "/usr/local/share/hostinfo/%s" % host
if not os.path.exists(path):
@@ -41,22 +42,28 @@ def find_host(host, key=None):
if not os.path.exists(path):
return False
- print_info(path, key)
+ print_info(path, key, oneline)
return True
def main():
- if len(sys.argv) < 2:
- print('Usage: %s <host> [info]' % sys.argv[0])
+ self_name = sys.argv.pop(0)
+
+ optlist, args = getopt.getopt(sys.argv, 'o', ['oneline'])
+ flags = [opt for (opt, _) in optlist]
+ oneline = '--oneline' in flags or '-o' in flags
+
+ if len(args) < 1:
+ print('Usage: %s <host> [info]' % self_name)
sys.exit(1)
- if len(sys.argv) == 2:
- if find_host(sys.argv[1]):
+ if len(args) == 1:
+ if find_host(args[0], oneline=oneline):
sys.exit(0)
else:
- if find_host(sys.argv[1], sys.argv[2]):
+ if find_host(args[0], args[1], oneline=oneline):
sys.exit(0)
- print("Host '%s' could not be found!" % sys.argv[1])
+ print("Host '%s' could not be found!" % args[0])
sys.exit(1)