summaryrefslogtreecommitdiffstats
path: root/src/sbin
diff options
context:
space:
mode:
authorHolger Weiß <holger@zedat.fu-berlin.de>2011-06-29 23:40:31 +0200
committerHolger Weiß <holger@zedat.fu-berlin.de>2011-06-29 23:40:31 +0200
commit35a2fb21cea7e6156737ef65e49ee51376a22c74 (patch)
treea14d51d2d925cf634fef1f27aeabdd65e7a8b347 /src/sbin
parent53d46e336d3514ec50f85e5db4ceed16590bf154 (diff)
downloadbcfg2-35a2fb21cea7e6156737ef65e49ee51376a22c74.tar.gz
bcfg2-35a2fb21cea7e6156737ef65e49ee51376a22c74.tar.bz2
bcfg2-35a2fb21cea7e6156737ef65e49ee51376a22c74.zip
bcfg2-reports: Catch getopt exceptions
On getopt errors, print a proper usage message instead of spitting out a traceback.
Diffstat (limited to 'src/sbin')
-rwxr-xr-xsrc/sbin/bcfg2-reports89
1 files changed, 51 insertions, 38 deletions
diff --git a/src/sbin/bcfg2-reports b/src/sbin/bcfg2-reports
index 9a4c6e60d..57c3f50d1 100755
--- a/src/sbin/bcfg2-reports
+++ b/src/sbin/bcfg2-reports
@@ -22,10 +22,46 @@ sys.path.pop()
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % project_name
from Bcfg2.Server.Reports.reports.models import Client
-from getopt import getopt
+import getopt
import datetime
import fileinput
+usage = """Usage: bcfg2-reports [option] ...
+
+Options and arguments (and corresponding environment variables):
+-a : shows all hosts, including expired hosts
+-b NAME : single-host mode - shows bad entries from the
+ current interaction of NAME
+-c : shows only clean hosts
+-d : shows only dirty hosts
+-e NAME : single-host mode - shows extra entries from the
+ current interaction of NAME
+-h : shows help and usage info about bcfg2-reports
+-m NAME : single-host mode - shows modified entries from the
+ current interaction of NAME
+-s NAME : single-host mode - shows bad, modified, and extra
+ entries from the current interaction of NAME
+-t NAME : single-host mode - shows total number of managed and
+ good entries from the current interaction of NAME
+-x NAME : toggles expired/unexpired state of NAME
+--badentry=KIND,NAME : shows only hosts whose current interaction has bad
+ entries in of KIND kind and NAME name; if a single
+ argument ARG1 is given, then KIND,NAME pairs will be
+ read from a file of name ARG1
+--modifiedentry=KIND,NAME : shows only hosts whose current interaction has
+ modified entries in of KIND kind and NAME name; if a
+ single argument ARG1 is given, then KIND,NAME pairs
+ will be read from a file of name ARG1
+--extraentry=KIND,NAME : shows only hosts whose current interaction has extra
+ entries in of KIND kind and NAME name; if a single
+ argument ARG1 is given, then KIND,NAME pairs will be
+ read from a file of name ARG1
+--fields=ARG1,ARG2,... : only displays the fields ARG1,ARG2,...
+ (name,time,state)
+--sort=ARG1,ARG2,... : sorts output on ARG1,ARG2,... (name,time,state)
+--stale : shows hosts which haven't run in the last 24 hours
+"""
+
def timecompare(client1, client2):
"""Compares two clients by their timestamps."""
return cmp(client1.current_interaction.timestamp, \
@@ -145,8 +181,19 @@ result = list()
entrydict = dict()
args = sys.argv[1:]
-opts, pargs = getopt(args, 'ab:cde:hm:s:t:x:',
- ['stale', 'sort=', 'fields=', 'badentry=', 'modifiedentry=', 'extraentry='])
+try:
+ opts, pargs = getopt.getopt(args, 'ab:cde:hm:s:t:x:',
+ ['stale',
+ 'sort=',
+ 'fields=',
+ 'badentry=',
+ 'modifiedentry=',
+ 'extraentry='])
+except getopt.GetoptError:
+ msg = sys.exc_info()[1]
+ print(msg)
+ print(usage)
+ sys.exit(2)
for option in opts:
if len(option) > 0:
@@ -181,41 +228,7 @@ if expire != "":
c_inst.save()
elif '-h' in args:
- print("""Usage: bcfg2-reports [option] ...
-
-Options and arguments (and corresponding environment variables):
--a : shows all hosts, including expired hosts
--b NAME : single-host mode - shows bad entries from the
- current interaction of NAME
--c : shows only clean hosts
--d : shows only dirty hosts
--e NAME : single-host mode - shows extra entries from the
- current interaction of NAME
--h : shows help and usage info about bcfg2-reports
--m NAME : single-host mode - shows modified entries from the
- current interaction of NAME
--s NAME : single-host mode - shows bad, modified, and extra
- entries from the current interaction of NAME
--t NAME : single-host mode - shows total number of managed and
- good entries from the current interaction of NAME
--x NAME : toggles expired/unexpired state of NAME
---badentry=KIND,NAME : shows only hosts whose current interaction has bad
- entries in of KIND kind and NAME name; if a single
- argument ARG1 is given, then KIND,NAME pairs will be
- read from a file of name ARG1
---modifiedentry=KIND,NAME : shows only hosts whose current interaction has
- modified entries in of KIND kind and NAME name; if a
- single argument ARG1 is given, then KIND,NAME pairs
- will be read from a file of name ARG1
---extraentry=KIND,NAME : shows only hosts whose current interaction has extra
- entries in of KIND kind and NAME name; if a single
- argument ARG1 is given, then KIND,NAME pairs will be
- read from a file of name ARG1
---fields=ARG1,ARG2,... : only displays the fields ARG1,ARG2,...
- (name,time,state)
---sort=ARG1,ARG2,... : sorts output on ARG1,ARG2,... (name,time,state)
---stale : shows hosts which haven't run in the last 24 hours
-""")
+ print(usage)
elif singlehost != "":
for c_inst in c_list:
if singlehost == c_inst.name: