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
32 print("Current version is 0.1-alpha_pre_dinner_build")
35 class DispatchException(Exception):
36 """This exception is raised when something went wrong during dispatching
42 """This class provides basic dispatching functionality
45 def __init__(self
, commands
):
46 self
.commands
= commands
48 def showUsageMessage(self
):
49 """Shows a usage message, listing all available commands
52 print("Available commands are:")
54 keys
= self
.commands
.keys()
60 def dispatch(self
, argv
):
61 """Dispatches a command with the specified arguments
64 argv: The arguments to parse and dispatch.
68 self
.showUsageMessage()
73 for key
, value
in self
.commands
.iteritems():
74 if key
.startswith(command
):
78 raise DispatchException("Unknown command '" + command
+ "'.")
80 # When not specifying a command, throw in the --help switch
84 return func(*argv
[2:])
87 "author" : author
.dispatch
,
88 "branch" : branch
.dispatch
,
89 "commit" : commit
.dispatch
,
90 "diff" : diff
.dispatch
,
91 "index" : index
.dispatch
,
96 if __name__
== '__main__':
98 result
= Dispatcher(commands
).dispatch(sys
.argv
)