summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSiegfried-Angel Gevatter Pujals <siegfried@gevatter.com>2012-09-14 22:21:23 +0200
committerSiegfried-Angel Gevatter Pujals <siegfried@gevatter.com>2012-09-14 22:21:23 +0200
commitad1f6d382f5f813dfe364fe8d3de6ae901ccf5d8 (patch)
tree3147f9434317aed57a982b6e1298096d8ee0fe99 /tools
parentfb930841790b008e9d9d932d50822eda6125d71b (diff)
downloadzeitgeist-ad1f6d382f5f813dfe364fe8d3de6ae901ccf5d8.tar.gz
Start working on upgrade tests...
Diffstat (limited to 'tools')
-rwxr-xr-xtools/development/insert_events_from_json.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/tools/development/insert_events_from_json.py b/tools/development/insert_events_from_json.py
new file mode 100755
index 00000000..2da88a0c
--- /dev/null
+++ b/tools/development/insert_events_from_json.py
@@ -0,0 +1,64 @@
+#! /usr/bin/env python
+# -.- coding: utf-8 -.-
+
+# Zeitgeist - Send all events from a JSON file to Zeitgeist
+#
+# Copyright © 2012 Collabora Ltd.
+# By Siegfried-A. Gevatter <siegfried.gevatter@collabora.co.uk>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 2.1 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# #############################################################################
+# WARNING: Make sure you launch Zeitgeist with ZEITGEIST_DATA_PATH set if
+# you don't want to fill your real database!
+#
+# See ./tools/run_fake_zeitgeist.sh for a convenient way of testing
+# Zeitgeist.
+# #############################################################################
+
+import os
+import sys
+
+from zeitgeist.datamodel import *
+from zeitgeist.client import ZeitgeistDBusInterface
+
+# Import parse_events from testutils.py
+path = os.path.join(os.path.dirname(__file__), '../../test/dbus')
+sys.path.append(path)
+from testutils import parse_events
+
+# Max. number of events to send in a D-Bus call
+LIMIT = 100
+
+def insert_events(events):
+ iface = ZeitgeistDBusInterface()
+ print "Inserting %d events..." % len(events)
+ while len(events):
+ iface.InsertEvents(events[:LIMIT])
+ events = events[LIMIT:]
+ print "."
+ print 'OK.'
+
+def main():
+ if len(sys.argv) != 2:
+ raise SystemExit, 'Usage: %s <json file>' % sys.argv[0]
+
+ events = parse_events(sys.argv[1])
+ insert_events(events)
+
+if __name__ == '__main__':
+ try:
+ main()
+ except KeyboardInterrupt:
+ pass