reporting/spacewalk-report | 28 ++++++++++++++++++++++------
reporting/spacewalk-report.sgml | 13 +++++++++++++
2 files changed, 35 insertions(+), 6 deletions(-)
New commits:
commit 90effb434a28b6d1affe09378fb911fc00209747
Author: Tomas Kasparek <tkasparek(a)redhat.com>
Date: Mon Jun 24 16:34:06 2013 +0200
972759 - add support for sql like predicates into spacewalk-report
diff --git a/reporting/spacewalk-report b/reporting/spacewalk-report
index c22bbc9..d486756 100755
--- a/reporting/spacewalk-report
+++ b/reporting/spacewalk-report
@@ -62,6 +62,9 @@ def processCommandline():
Option('--where-<column-id>', action='store',
metavar='VALUE',
dest='_where_trap',
help='limit the output to records where column-id has value VALUE'),
+ Option('--like<column-id>', action='store',
metavar='VALUE',
+ dest='_like_trap',
+ help='limit the output to records where column-id has value like VALUE (string
only)'),
]
optionParser = OptionParser( \
@@ -69,10 +72,17 @@ def processCommandline():
option_list=optionsTable)
where = {}
+ where_like = []
+ like = False
i = 1
while i < len(sys.argv):
- if sys.argv[i].startswith('--where-'):
- o = sys.argv[i][len('--where-'):]
+ if sys.argv[i].startswith('--where-') or
sys.argv[i].startswith('--like-'):
+ if sys.argv[i].startswith('--where-'):
+ o = sys.argv[i][len('--where-'):]
+ like = False
+ elif sys.argv[i].startswith('--like-'):
+ o = sys.argv[i][len('--like-'):]
+ like = True
try:
(k, v) = o.split('=', 1)
del sys.argv[i]
@@ -96,6 +106,8 @@ def processCommandline():
where[k].append(v)
else:
where[k] = [ v ]
+ if like:
+ where_like.append(k)
i += 1
@@ -103,10 +115,10 @@ def processCommandline():
sys.argv[1:] = args
- return options, where
+ return options, where, where_like
if __name__ == '__main__':
- (options, where) = processCommandline()
+ (options, where, where_like) = processCommandline()
try:
if len(sys.argv) > 2:
@@ -164,10 +176,14 @@ if __name__ == '__main__':
the_dict_where["p%d" % pi] = x
pi += 1
+ if k in where_like:
+ clause = 'like'
+ else:
+ clause = 'in'
if k == 'group':
- the_sql_where.append('"%s" in ( %s )' % (k.upper(), val))
+ the_sql_where.append('"%s" %s ( %s )' % (k.upper(), clause,
preval))
else:
- the_sql_where.append('%s in ( %s )' % (k, val))
+ the_sql_where.append('%s %s ( %s )' % (k, clause, val))
rhnSQL.initDB()
diff --git a/reporting/spacewalk-report.sgml b/reporting/spacewalk-report.sgml
index 7244efa..418255b 100644
--- a/reporting/spacewalk-report.sgml
+++ b/reporting/spacewalk-report.sgml
@@ -107,6 +107,19 @@ Generate reports from Spacewalk server in csv format
have to meet the condition.</para>
</listitem>
</varlistentry>
+ <varlistentry>
+
<term>--like-<replaceable>column-id</replaceable>=<replaceable>VALUE</replaceable></term>
+ <listitem>
+ <para>Limit the output to records where column-id has value
+ like VALUE. This applies for string values only. It can be used
+ multiple times -- for the same column it will select records
+ where the column has any of the VALUEs. When different columns
+ are specified, all of them have to meet the condition. Regular
+ expressions for like clause are described by SQL standard. Most
+ common wildcards are _ for any single character and % for multiple
+ occurances of any character.</para>
+ </listitem>
+ </varlistentry>
</variablelist>
</RefSect1>
Show replies by date