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 environname
= "GIT_STATS_PATH"
12 # Try to retreive the path from the environment
13 # This is so that we can then import from git_python
14 if os
.environ
.has_key(environname
):
15 dir = os
.environ
[environname
]
16 dir = os
.path
.expanduser(dir)
17 dir = os
.path
.expandvars(dir)
19 # Figure out what we are running from
20 # Then get the directory we are in and use that instead
21 # Ofcourse, this only works if git_python is in the dir we are run from
24 path
= os
.path
.abspath(file)
25 dir = os
.path
.dirname(path
)
27 if not os
.path
.isdir(os
.path
.join(dir, "git_stats")):
28 raise Exception("Cannot find git_stats directory, please set $GIT_STATS_PATH")
30 os
.sys
.path
.insert(0, dir)
32 from git_python
import Git
34 from git_stats
import author
35 from git_stats
import branch
36 from git_stats
import commit
37 from git_stats
import diff
38 from git_stats
import index
40 class DispatchException(Exception):
41 """This exception is raised when something went wrong during dispatching
47 """This class provides basic dispatching functionality
50 def __init__(self
, commands
):
51 self
.commands
= commands
53 def showUsageMessage(self
):
54 print("Available commands are:")
55 for key
in self
.commands
.iterkeys():
58 def dispatch(self
, argv
):
60 self
.showUsageMessage()
65 for key
, value
in self
.commands
.iteritems():
66 if key
.startswith(command
):
70 raise DispatchException("Unknown command '" + command
+ "'.")
72 return func(*argv
[2:])
75 "author" : author
.dispatch
,
76 "branch" : branch
.dispatch
,
77 "commit" : commit
.dispatch
,
78 "diff" : diff
.dispatch
,
79 "index" : index
.dispatch
,
83 if __name__
== '__main__':
85 result
= Dispatcher(commands
).dispatch(sys
.argv
)