3 """This module contains commands related to statistics on git repositories.
5 Each command here is merely a wrapper around other, more complicated, commands.
10 # Figure out what we are running from
11 # Then get the directory we are in and use that instead
12 # Ofcourse, this only works if git_python is in the dir we are run from
15 path
= os
.path
.abspath(file)
16 dir = os
.path
.dirname(path
)
18 split
= os
.path
.split(dir)
21 if not split
[1] == "git_stats":
22 raise Exception("Please run this script inside the git_stats directory")
24 os
.sys
.path
.insert(0, dir)
26 from git_python
import Git
28 from git_stats
import author
29 from git_stats
import branch
30 from git_stats
import commit
31 from git_stats
import diff
32 from git_stats
import index
34 class DispatchException(Exception):
35 """This exception is raised when something went wrong during dispatching
41 """This class provides basic dispatching functionality
44 def __init__(self
, commands
):
45 self
.commands
= commands
47 def showUsageMessage(self
):
48 print("Available commands are:")
49 for key
in self
.commands
.iterkeys():
52 def dispatch(self
, argv
):
54 self
.showUsageMessage()
59 for key
, value
in self
.commands
.iteritems():
60 if key
.startswith(command
):
64 raise DispatchException("Unknown command '" + command
+ "'.")
66 return func(*argv
[2:])
69 "author" : author
.dispatch
,
70 "branch" : branch
.dispatch
,
71 "commit" : commit
.dispatch
,
72 "diff" : diff
.dispatch
,
73 "index" : index
.dispatch
,
77 if __name__
== '__main__':
79 result
= Dispatcher(commands
).dispatch(sys
.argv
)