~email-tehk/zeitgeist-datasources/totem-fix

« back to all changes in this revision

Viewing changes to bzr/__init__.py

  • Committer: Markus Korn
  • Date: 2009-11-26 08:54:37 UTC
  • Revision ID: thekorn@gmx.de-20091126085437-dtftsoi66ub7405n
Copied over an initial version of a bzr commit hook

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -.- coding: utf-8 -.-
 
2
 
 
3
# Zeitgeist
 
4
#
 
5
# Copyright © 2009 Markus Korn <thekorn@gmx.de>
 
6
#
 
7
# This program is free software: you can redistribute it and/or modify
 
8
# it under the terms of the GNU Lesser General Public License as published by
 
9
# the Free Software Foundation, either version 3 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# This program is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU Lesser General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU Lesser General Public License
 
18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
"""Post-commit hook to submit the commit to Zeitgeist (http://www.zeitgeist-project.com)
 
21
 
 
22
Requires bzr 0.15 or higher.
 
23
 
 
24
Copyright (C) 2009, Markus Korn <thekorn@gmx.de>
 
25
Published under the GNU GPLv2 or later
 
26
 
 
27
Installation:
 
28
Copy this directory to ~/.bazaar/plugins/zeitgeist/*
 
29
"""
 
30
 
 
31
import time
 
32
import logging
 
33
from bzrlib import branch
 
34
 
 
35
logging.basicConfig(filename="/dev/null")
 
36
 
 
37
install_hook = True
 
38
try:
 
39
    from zeitgeist import dbusutils
 
40
    IFACE = dbusutils.get_engine_interface()
 
41
except: # FIXME: adjust this to ImportError, whatever exception is raised
 
42
        # as the fix for LP: #397432
 
43
    install_hook = False
 
44
 
 
45
 
 
46
def post_commit(local, master, old_revno, old_revid, new_revno, new_revid):
 
47
    revision = master.repository.get_revision(new_revid)
 
48
    if new_revno == 1:
 
49
        use = u"CreateEvent"
 
50
    else:
 
51
        use = u"ModifyEvent"
 
52
    item = {
 
53
        "timestamp": int(time.time()),
 
54
        "uri": unicode(master.base),
 
55
        "text": unicode(revision.message),
 
56
        "source": "Bzr Branch",
 
57
        "content": u"Branch",
 
58
        "use": u"http://gnome.org/zeitgeist/schema/1.0/core#%s" %use,
 
59
        "mimetype": u"application/x-bzr-branch",
 
60
        "tags": u"",
 
61
        "icon": u"",
 
62
        "app": u"/usr/share/applications/olive-gtk.desktop",
 
63
        "origin": u"",  # we are not sure about the origin of this item,
 
64
                        # let's make it NULL, it has to be a string
 
65
    }
 
66
    items = [dbusutils.plainify_dict(item),]
 
67
    IFACE.InsertEvents(items)
 
68
 
 
69
if install_hook:
 
70
    branch.Branch.hooks.install_named_hook("post_commit", post_commit,
 
71
                                           "Zeitgeist dataprovider for bzr")