backend/satellite_tools/reports.py | 3 ++ backend/satellite_tools/spacewalk-report | 32 ++++++++++++++++++------------- 2 files changed, 22 insertions(+), 13 deletions(-)
New commits: commit 0b64232669032fbe2c2682661c2a60f42dab341c Author: Jan Pazdziora jpazdziora@redhat.com Date: Thu Jul 23 14:45:55 2009 +0200
reporting: when report name is not specified on the command line, show list of available reports.
diff --git a/backend/satellite_tools/reports.py b/backend/satellite_tools/reports.py index d0e7ae6..b82b7ac 100644 --- a/backend/satellite_tools/reports.py +++ b/backend/satellite_tools/reports.py @@ -3,6 +3,9 @@ import os
REPORT_DEFINITIONS = "/usr/share/spacewalk/reports/data"
+def available_reports(): + return os.listdir(REPORT_DEFINITIONS) + class report: def __init__(self, name): full_path = os.path.join(REPORT_DEFINITIONS, name) diff --git a/backend/satellite_tools/spacewalk-report b/backend/satellite_tools/spacewalk-report index 216d52a..8b16eed 100755 --- a/backend/satellite_tools/spacewalk-report +++ b/backend/satellite_tools/spacewalk-report @@ -57,7 +57,9 @@ def processCommandline(): + ' default is default_db from /etc/rhn/rhn.conf'), ]
- optionParser = OptionParser(option_list=optionsTable) + optionParser = OptionParser( \ + usage="usage: %s [options] [report_name [report_options]]" % sys.argv[0], \ + option_list=optionsTable) optionParser.disable_interspersed_args() options, args = optionParser.parse_args()
@@ -68,19 +70,23 @@ if __name__ == '__main__': options = processCommandline()
try: - initCFG('server') - rhnSQL.initDB(options.db) - - report = reports.report(sys.argv[1]) - writer = csv.writer(sys.stdout) - - h = rhnSQL.prepare(report.sql) - h.execute() - writer.writerow(map(lambda x: x[0].lower(), h.description)) - row = h.fetchone() - while row != None: - writer.writerow(row) + if len(sys.argv) > 1: + initCFG('server') + rhnSQL.initDB(options.db) + + report = reports.report(sys.argv[1]) + writer = csv.writer(sys.stdout) + + h = rhnSQL.prepare(report.sql) + h.execute() + writer.writerow(map(lambda x: x[0].lower(), h.description)) row = h.fetchone() + while row != None: + writer.writerow(row) + row = h.fetchone() + else: + for r in reports.available_reports(): + print r
except KeyboardInterrupt: systemExit(-1, "\nUser interrupted process.")
spacewalk-commits@lists.fedorahosted.org