gitstats: Moved things around a lot, and made commitTouches fixup nonrelative paths
[git-stats.git] / src / git_stats / stats.py
blob4f60a35a930ff89f5a7395d5122b7c139b414cce
1 #!/usr/bin/env python
3 """This module contains commands related to statistics on git repositories.
5 Each command here is merely a wrapper around other, more complicated, commands.
6 """
8 from git_python import Repo
9 from git_python import Git
11 import author
12 import branch
13 import commit
14 import index
16 class DispatchException(Exception):
17 """This exception is raised when something went wrong during dispatching
18 """
20 pass
22 class Dispatcher():
23 """This class provides basic dispatching functionality
24 """
26 def __init__(self, commands):
27 self.commands = commands
29 def showUsageMessage(self):
30 print("Available commands are:")
31 for key in self.commands.iterkeys():
32 print(key)
34 def dispatch(self, argv):
35 if not len(argv) > 1:
36 self.showUsageMessage()
37 return 1
39 command = argv[1]
41 for key, value in self.commands.iteritems():
42 if key.startswith(command):
43 func = value
44 break
45 else:
46 raise DispatchException("Unknown command '" + command + "'.")
48 return func(argv[2:])
50 commands = {
51 "author" : author.dispatch,
52 "branch" : branch.dispatch,
53 "commit" : commit.dispatch,
54 "index" : index.dispatch,
58 if __name__ == '__main__':
59 import os
60 import sys
61 os.chdir("../..")
62 result = Dispatcher(commands).dispatch(sys.argv)
63 sys.exit(result)