mozautomation: add function to insert pushes from raw data; r?nalexander
This will allow us to obtain pushlog data from not the JSON API.
--- a/pylib/mozautomation/mozautomation/changetracker.py
+++ b/pylib/mozautomation/mozautomation/changetracker.py
@@ -132,16 +132,37 @@ class ChangeTracker(object):
head = buffer(binascii.unhexlify(push['changesets'][-1]))
params = [(buffer(binascii.unhexlify(c)), head, push_id,
tree_id) for c in push['changesets']]
self._db.executemany('INSERT INTO changeset_pushes VALUES '
'(?, ?, ?, ?)', params)
+ def add_pushes(self, tree, pushes):
+ """Insert an iterable of pushes for a tree.
+
+ ``pushes`` is an iterable of tuples of (pushid, who, when, nodes).
+ """
+ tree_id = self.tree_id(tree)
+
+ with self._db:
+ for push_id, who, when, nodes in pushes:
+ for node in nodes:
+ assert len(node) == 20
+
+ self._db.execute('INSERT INTO pushes (push_id, tree_id, time, '
+ 'user) VALUES (?, ?, ?, ?)', [push_id, tree_id,
+ when, who])
+ if nodes:
+ head = buffer(nodes[-1])
+ params = [(buffer(c), head, push_id, tree_id) for c in nodes]
+ self._db.executemany('INSERT INTO changeset_pushes VALUES '
+ '(?, ?, ?, ?)', params)
+
def pushes_for_changeset(self, changeset):
for row in self._db.execute('SELECT trees.name, pushes.push_id, '
'pushes.time, pushes.user, changeset_pushes.head_changeset '
'FROM trees, pushes, changeset_pushes '
'WHERE pushes.push_id = changeset_pushes.push_id AND '
'pushes.tree_id = changeset_pushes.tree_id AND '
'trees.id = pushes.tree_id AND changeset_pushes.changeset=? '
'ORDER BY pushes.time ASC', [buffer(changeset)]):