2 # vim: set fileencoding=utf-8 :
4 # (C) 2010 Guido Guenther <agx@sigxcpu.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # Simple Zeitgeist Git data source
21 """Post-commit hook to submit the commit to Zeitgeist (http://www.zeitgeist-project.com)
23 copy as post-commit to
25 .git/hooks/post-commit
27 in existing repositories or to
29 /usr/share/git-core/templates
31 so it get's used for new ones.
43 from zeitgeist.client import ZeitgeistClient
44 from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation
49 CLIENT = ZeitgeistClient()
50 except RuntimeError as e:
51 print("Unable to connect to Zeitgeist, won't send events. Reason: '%s'" %e)
55 """Get uri of remote repository and its name"""
57 uri = subprocess.Popen(['git', 'config', '--get', 'remote.origin.url'],
58 stdout=subprocess.PIPE).communicate()[0]
61 uri = uri.strip().decode(sys.getfilesystemencoding())
67 repo = str(uri.rsplit(sep, 1)[1])
68 except IndexError: # no known separator
70 repo = repo.rsplit('.git', 1)[0]
75 interpretation = Interpretation.MODIFY_EVENT.uri
77 # FIXME: I'd be great if zeitgeist would allow for more detail:
79 # * log summary (git log -1 --format=%s HEAD)
80 curdir = os.path.abspath(os.curdir).decode(sys.getfilesystemencoding())
81 uri = "file://%s" % curdir
83 repo, origin = get_repo()
85 repo = str(curdir.rsplit('/', 1)[1])
88 subject = Subject.new_for_values(
90 interpretation = Interpretation.DOCUMENT.TEXT_DOCUMENT.PLAIN_TEXT_DOCUMENT.SOURCE_CODE.uri,
91 manifestation = Manifestation.FILE_DATA_OBJECT.uri,
94 event = Event.new_for_values(
95 timestamp = int(time.time() * 1000),
96 interpretation = interpretation,
97 manifestation = Manifestation.USER_ACTIVITY.uri,
98 actor = "application://gitg.desktop",
100 CLIENT.insert_event(event)
102 if __name__ == '__main__':