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
29 from git_stats
import tests
32 """Shows a silly version message
35 print("Current version is 0.1-alpha_pre_dinner_build")
38 class DispatchException(Exception):
39 """This exception is raised when something went wrong during dispatching
45 """This class provides basic dispatching functionality
49 def __init__(self
, commands
):
50 self
.commands
= commands
52 def showUsageMessage(self
):
53 """Shows a usage message, listing all available commands
56 print("Available commands are:")
58 for key
in sorted(self
.commands
):
61 def dispatch(self
, argv
):
62 """Dispatches a command with the specified arguments
65 argv: The arguments to parse and dispatch.
69 self
.showUsageMessage()
74 for key
, value
in self
.commands
.iteritems():
75 if key
.startswith(command
):
79 raise DispatchException("Unknown command '" + command
+ "'.")
81 # When not specifying a command, throw in the --help switch
85 return func(*argv
[1:])
88 "author" : author
.dispatch
,
90 "branch" : branch
.dispatch
,
91 "commit" : commit
.dispatch
,
92 "diff" : diff
.dispatch
,
93 "index" : index
.dispatch
,
94 "matcher":matcher
.dispatch
,
95 "tests" : tests
.dispatch
,
100 """Main routine, dispatches the command specified in args
102 If called with sys.argv, cut off the first element!
105 result
= Dispatcher(commands
).dispatch(args
)
108 if __name__
== '__main__':
110 result
= main(sys
.argv
[1:])