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 bug
24 from git_stats
import branch
25 from git_stats
import commit
26 from git_stats
import diff
27 from git_stats
import index
28 from git_stats
import matcher
34 print("Current version is 0.1-alpha_pre_dinner_build")
37 class DispatchException(Exception):
38 """This exception is raised when something went wrong during dispatching
44 """This class provides basic dispatching functionality
48 def __init__(self
, commands
):
49 self
.commands
= commands
51 def showUsageMessage(self
):
52 """Shows a usage message, listing all available commands
55 print("Available commands are:")
57 keys
= self
.commands
.keys()
63 def dispatch(self
, argv
):
64 """Dispatches a command with the specified arguments
67 argv: The arguments to parse and dispatch.
71 self
.showUsageMessage()
76 for key
, value
in self
.commands
.iteritems():
77 if key
.startswith(command
):
81 raise DispatchException("Unknown command '" + command
+ "'.")
83 # When not specifying a command, throw in the --help switch
87 return func(*argv
[1:])
90 "author" : author
.dispatch
,
92 "branch" : branch
.dispatch
,
93 "commit" : commit
.dispatch
,
94 "diff" : diff
.dispatch
,
95 "index" : index
.dispatch
,
96 "matcher":matcher
.dispatch
,
101 """Main routine, dispatches the command specified in args
103 If called with sys.argv, cut off the first element!
106 result
= Dispatcher(commands
).dispatch(args
)
109 if __name__
== '__main__':
111 result
= main(sys
.argv
[1:])