backend/satellite_tools/reports.py | 41 ++++++++++++++++++++++++-
backend/satellite_tools/reports/data/inventory | 18 ++++++++++
backend/satellite_tools/spacewalk-report | 8 ++++
3 files changed, 64 insertions(+), 3 deletions(-)
New commits:
commit 792cb55228151f56d1846bffffb22ddaa83270ad
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Thu Jul 23 15:19:47 2009 +0200
reporting: change structure of the report definition file to also include column names.
This is also used to check that the report definition matches
with column names returned by the query.
diff --git a/backend/satellite_tools/reports.py b/backend/satellite_tools/reports.py
index b82b7ac..a8afd2c 100644
--- a/backend/satellite_tools/reports.py
+++ b/backend/satellite_tools/reports.py
@@ -1,5 +1,6 @@
import os
+import re
REPORT_DEFINITIONS = "/usr/share/spacewalk/reports/data"
@@ -9,6 +10,44 @@ def available_reports():
class report:
def __init__(self, name):
full_path = os.path.join(REPORT_DEFINITIONS, name)
+ self.sql = None
+ self.columns = None
+ self._load(full_path)
+
+ def _load(self, full_path):
fd = open(full_path, 'r')
- self.sql = fd.read()
+ tag = None
+ value = ''
+ re_comment = re.compile('^\s*#')
+ re_tag_name = re.compile('^(\S+):\s*$')
+
+ for line in fd:
+ result = re_comment.match(line)
+ if result != None:
+ continue
+
+ result = re_tag_name.match(line)
+ if result != None:
+ if tag != None:
+ self._set(tag, value)
+ tag = None
+ value = ''
+ tag = result.group(1)
+ else:
+ value += line
+
+ if tag != None:
+ self._set(tag, value)
+
+ def _set(self, tag, value):
+ if tag == 'columns':
+ self.columns = filter(lambda x: x != '', re.split('\s+', value))
+ elif tag == 'sql':
+ self.sql = value
+ else:
+ raise spacewalk_report_unknown_tag_exception(tag)
+
+
+class spacewalk_report_unknown_tag_exception(Exception):
+ pass
diff --git a/backend/satellite_tools/reports/data/inventory b/backend/satellite_tools/reports/data/inventory
index e3559b5..1921ccb 100755
--- a/backend/satellite_tools/reports/data/inventory
+++ b/backend/satellite_tools/reports/data/inventory
@@ -1,4 +1,20 @@
-
+
+columns:
+
+ server_id
+ profile_name
+ hostname
+ ip_address
+ registered_by
+ registration_time
+ last_checkin_time
+ kernel_version
+ packages_out_of_date
+ errata_out_of_date
+ software_channel
+
+sql:
+
select rhnserver.id as server_id, rhnserver.name as profile_name,
rhnservernetwork.hostname, trim(rhnservernetwork.ipaddr) as ip_address,
( select login from web_contact where rhnserver.creator_id = web_contact.id ) as registered_by,
diff --git a/backend/satellite_tools/spacewalk-report b/backend/satellite_tools/spacewalk-report
index 8b16eed..80f0386 100755
--- a/backend/satellite_tools/spacewalk-report
+++ b/backend/satellite_tools/spacewalk-report
@@ -79,7 +79,13 @@ if __name__ == '__main__':
h = rhnSQL.prepare(report.sql)
h.execute()
- writer.writerow(map(lambda x: x[0].lower(), h.description))
+
+ db_columns = map(lambda x: x[0].lower(), h.description)
+ if db_columns != report.columns:
+ systemExit(-3, \
+ "Columns in report spec and in the database do not match:\nexpected %s\n got %s" % ( report.columns, db_columns ))
+ writer.writerow(report.columns)
+
row = h.fetchone()
while row != None:
writer.writerow(row)