diff options
author | Manish Sinha <manishsinha@ubuntu.com> | 2012-03-24 18:31:04 +0530 |
---|---|---|
committer | Manish Sinha <manishsinha@ubuntu.com> | 2012-03-24 18:31:04 +0530 |
commit | 41a66b2d29fe84b955b952b31d2086a90f2c92cc (patch) | |
tree | be06578041972a9b378cc89cdf7ca116454e9ac2 /bzr | |
parent | b17f657892d1327e2de2ae62a73bea51fe74a0b9 (diff) |
Fixed the subjects
* Actor is bzr.desktop just so that we are able to fetch the events
* Apart from folder subject, added subject for each file involved in the event
* Used Gio.File to get the mimetype of the file subject
* Subject Interpretation is not being set as it is decided by the mimetype
* File subjects are set only for commit messages as for push and pull, remote URI are
used from which mimetype cannot be found out by Gio.File
* In case of Commit the text is "Revision: 23, Message: commit message"
* In case of Push, commit message is like "Pushed branch from 12 to 14"
* In case of Pull, commit message is like "Updated branch from 12 to 14"
------------- This line and the following will be ignored --------------
modified:
bzr/hooks.py
Diffstat (limited to 'bzr')
-rw-r--r-- | bzr/hooks.py | 86 |
1 files changed, 73 insertions, 13 deletions
diff --git a/bzr/hooks.py b/bzr/hooks.py index 5bd8d35..98ab126 100644 --- a/bzr/hooks.py +++ b/bzr/hooks.py @@ -17,11 +17,16 @@ # 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/>. +import os.path + +from gi.repository import Gio + from bzrlib import ( branch, errors, trace, urlutils, + workingtree, ) _client = None @@ -50,22 +55,74 @@ def get_client(): return _client -def subject_for_branch(branch): +def subjects_for_branch(branch, new_revno, old_revno, is_push, message): + """ + Generates the event's subject for commit, push and pull events + + branch - the bzrlib.branch.Branch instance + new_revno - the new revision number generated after a commit, + after a push or a pull + old_revno - the old revno which is was present before the commit, + push or pull event + is_push - True then push, is False then pull, is None then commit + message - the Commit message + """ + from zeitgeist.datamodel import Subject, Interpretation, Manifestation location = urlutils.unescape_for_display(branch.base, "utf-8").decode("utf-8") - return Subject.new_for_values( + + if is_push is None: + # Commit + text = u"Revision: %s, Message: %s" %(new_revno, message) + elif is_push is True: + # Push + text = "Pushed branch from %s to %s" %(old_revno, new_revno) + elif is_push is False: + # Pull + text = "Updated branch from %s to %s" %(old_revno, new_revno) + + folder_subj = Subject.new_for_values( uri=unicode(branch.base), interpretation=unicode(Interpretation.FOLDER), manifestation=unicode(Manifestation.FILE_DATA_OBJECT), - text=u"Bazaar branch at %s" % location, + text=text, origin=unicode(branch.base), mimetype="application/x-bzr", ) - - + + all_subjs = [folder_subj, ] + + # List down the files only in case of Commit as in case of + # push or pull, remote URI is used using which constructing + # file URI is not possible + if is_push is None: + prev_tree = branch.repository.revision_tree(branch.get_rev_id(old_revno)) + next_tree = branch.repository.revision_tree(branch.get_rev_id(new_revno)) + + for (file_id, path, content_change, versioned, parent_id, name, kind, + executable) in next_tree.iter_changes(prev_tree): + + name = path[0] if path[0] is not None else path[1] + uri = os.path.join(unicode(branch.base), name) + + # fi.get_content_type returns the file mimetype + f=Gio.File.new_for_uri(uri) + fi=f.query_info("*", Gio.FileQueryInfoFlags.NONE, None) + + subj = Subject.new_for_values( + uri=uri, + manifestation=unicode(Manifestation.FILE_DATA_OBJECT), + text=text, + origin=unicode(branch.base), + mimetype=fi.get_content_type(), + ) + all_subjs.append(subj) + + return all_subjs + def get_actor(): # FIXME: Allow overriding this by e.g. qbzr and bzr-gtk - return u"application://bzr-notify.desktop" + return u"application://bzr.desktop" def post_commit(local, master, old_revno, old_revid, new_revno, new_revid): @@ -82,14 +139,15 @@ def post_commit(local, master, old_revno, old_revid, new_revno, new_revid): _text += str(new_revno) + "\n" _text += revision.message.rstrip() - subject = subject_for_branch(master) - subject.set_text(_text) + subjects = subjects_for_branch(master, new_revno, old_revno, + None, revision.message.rstrip()) + #subjects.set_text(_text) event = Event.new_for_values( timestamp=int(revision.timestamp*1000), interpretation=unicode(interpretation), manifestation=unicode(Manifestation.USER_ACTIVITY), actor=get_actor(), - subjects=[subject,], + subjects=subjects, ) client.insert_event(event) @@ -109,12 +167,13 @@ def post_pull(pull_result): pull_result.new_revid) _text = _("Pulled to revision %s:\n %s") % (pull_result.new_revno, revision.get_summary()) - subject = subject_for_branch(pull_result.master_branch) + subjects = subjects_for_branch(pull_result.master_branch, + pull_result.new_revno, pull_result.old_revno, False, None) event = Event.new_for_values( interpretation=unicode(Interpretation.RECEIVE_EVENT), manifestation=unicode(Manifestation.WORLD_ACTIVITY), actor=get_actor(), - subjects=[subject,] + subjects=subjects ) client.insert_event(event) @@ -132,12 +191,13 @@ def post_push(push_result): push_result.new_revid) _text = _("Pushed to revision %s:\n %s") % (push_result.new_revno, revision.get_summary()) - subject = subject_for_branch(push_result.master_branch) + subjects = subjects_for_branch(push_result.master_branch, + push_result.new_revno, push_result.old_revno, True, None) event = Event.new_for_values( interpretation=unicode(Interpretation.SEND_EVENT), manifestation=unicode(Manifestation.USER_ACTIVITY), actor=get_actor(), - subjects=[subject,] + subjects=subjects ) client.insert_event(event) |