aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--quarg/main.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/quarg/main.py b/quarg/main.py
index 82474b8..8b9987b 100644
--- a/quarg/main.py
+++ b/quarg/main.py
@@ -18,6 +18,7 @@ cli = argparse.ArgumentParser()
cli.add_argument('keyword', nargs='*', help='match messages containing this keyword')
cli.add_argument('-d', action='store_true', dest='debug', help='print debug and SQL query information')
cli.add_argument('-e', action='store_true', dest='expr', help='interpret keywords as LIKE expression')
+cli.add_argument('-l', dest='limit', metavar='NUM', type=int, help='limit the number of matches')
matchers = cli.add_argument_group('matching message context')
matchers.add_argument('-b', action='append', dest='buffer', help='match this buffer')
matchers.add_argument('-B', action=actions.ParseBufferType, dest='buftype', help='match buffers of this type')
@@ -94,7 +95,7 @@ def collect_predicates(args):
else:
yield fun(value)
-def run_query(session, predicates):
+def run_query(session, predicates, limit):
start = timer()
query = session.query(Backlog).join(Sender).join(Buffer).join(Network).join(QuasselUser)
@@ -102,7 +103,11 @@ def run_query(session, predicates):
for predicate in predicates:
query = query.filter(predicate)
- rows = query.order_by(Backlog.time).all()
+ query = query.order_by(Backlog.time)
+ if limit:
+ query = query.limit(limit)
+
+ rows = query.all()
end = timer()
@@ -125,7 +130,7 @@ def main():
if not predicates:
errx('Nothing to match.')
- rows, time = run_query(session, predicates)
+ rows, time = run_query(session, predicates, args.limit)
for row in rows:
print(format_from(row))