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 os
.sys
.path
.insert(0, dir)
22 from git_stats
import author
23 from git_stats
import branch
24 from git_stats
import commit
25 from git_stats
import diff
26 from git_stats
import index
28 class DispatchException(Exception):
29 """This exception is raised when something went wrong during dispatching
35 """This class provides basic dispatching functionality
38 def __init__(self
, commands
):
39 self
.commands
= commands
41 def showUsageMessage(self
):
42 print("Available commands are:")
43 for key
in self
.commands
.iterkeys():
46 def dispatch(self
, argv
):
48 self
.showUsageMessage()
53 for key
, value
in self
.commands
.iteritems():
54 if key
.startswith(command
):
58 raise DispatchException("Unknown command '" + command
+ "'.")
60 # When not specifying a command, throw in the --help switch
64 return func(*argv
[2:])
67 "author" : author
.dispatch
,
68 "branch" : branch
.dispatch
,
69 "commit" : commit
.dispatch
,
70 "diff" : diff
.dispatch
,
71 "index" : index
.dispatch
,
75 if __name__
== '__main__':
77 result
= Dispatcher(commands
).dispatch(sys
.argv
)