浏览代码

Allow overriding of some config variables.

gitstats -c key=value overrides config values.
Heikki Hokkanen 16 年前
父节点
当前提交
df24a48ce4
共有 1 个文件被更改,包括 26 次插入9 次删除
  1. 26
    9
      gitstats

+ 26
- 9
gitstats 查看文件

2
 # Copyright (c) 2007-2010 Heikki Hokkanen <hoxu@users.sf.net> & others (see doc/author.txt)
2
 # Copyright (c) 2007-2010 Heikki Hokkanen <hoxu@users.sf.net> & others (see doc/author.txt)
3
 # GPLv2 / GPLv3
3
 # GPLv2 / GPLv3
4
 import datetime
4
 import datetime
5
+import getopt
5
 import glob
6
 import glob
6
 import os
7
 import os
7
 import pickle
8
 import pickle
14
 import zlib
15
 import zlib
15
 
16
 
16
 GNUPLOT_COMMON = 'set terminal png transparent\nset size 1.0,0.5\n'
17
 GNUPLOT_COMMON = 'set terminal png transparent\nset size 1.0,0.5\n'
17
-MAX_EXT_LENGTH = 10 # maximum file extension length
18
 ON_LINUX = (platform.system() == 'Linux')
18
 ON_LINUX = (platform.system() == 'Linux')
19
 
19
 
20
 exectime_internal = 0.0
20
 exectime_internal = 0.0
27
 if 'GNUPLOT' in os.environ:
27
 if 'GNUPLOT' in os.environ:
28
 	gnuplot_cmd = os.environ['GNUPLOT']
28
 	gnuplot_cmd = os.environ['GNUPLOT']
29
 
29
 
30
+conf = {
31
+	'max_domains': 10,
32
+	'max_ext_length': 10,
33
+	'style': 'gitstats.css'
34
+}
35
+
30
 def getpipeoutput(cmds, quiet = False):
36
 def getpipeoutput(cmds, quiet = False):
31
 	global exectime_external
37
 	global exectime_external
32
 	start = time.time()
38
 	start = time.time()
365
 				ext = ''
371
 				ext = ''
366
 			else:
372
 			else:
367
 				ext = filename[(filename.rfind('.') + 1):]
373
 				ext = filename[(filename.rfind('.') + 1):]
368
-			if len(ext) > MAX_EXT_LENGTH:
374
+			if len(ext) > conf['max_ext_length']:
369
 				ext = ''
375
 				ext = ''
370
 
376
 
371
 			if ext not in self.extensions:
377
 			if ext not in self.extensions:
800
 		f.write('<tr><th>Domains</th><th>Total (%)</th></tr>')
806
 		f.write('<tr><th>Domains</th><th>Total (%)</th></tr>')
801
 		fp = open(path + '/domains.dat', 'w')
807
 		fp = open(path + '/domains.dat', 'w')
802
 		n = 0
808
 		n = 0
803
-		max_domains = 10
804
 		for domain in domains_by_commits:
809
 		for domain in domains_by_commits:
805
-			if n == max_domains:
810
+			if n == conf['max_domains']:
806
 				break
811
 				break
807
 			commits = 0
812
 			commits = 0
808
 			n += 1
813
 			n += 1
1051
 <html xmlns="http://www.w3.org/1999/xhtml">
1056
 <html xmlns="http://www.w3.org/1999/xhtml">
1052
 <head>
1057
 <head>
1053
 	<title>GitStats - %s</title>
1058
 	<title>GitStats - %s</title>
1054
-	<link rel="stylesheet" href="gitstats.css" type="text/css" />
1059
+	<link rel="stylesheet" href="%s" type="text/css" />
1055
 	<meta name="generator" content="GitStats %s" />
1060
 	<meta name="generator" content="GitStats %s" />
1056
 	<script type="text/javascript" src="sortable.js"></script>
1061
 	<script type="text/javascript" src="sortable.js"></script>
1057
 </head>
1062
 </head>
1058
 <body>
1063
 <body>
1059
-""" % (self.title, getversion()))
1064
+""" % (self.title, conf['style'], getversion()))
1060
 
1065
 
1061
 	def printNav(self, f):
1066
 	def printNav(self, f):
1062
 		f.write("""
1067
 		f.write("""
1074
 		
1079
 		
1075
 
1080
 
1076
 class GitStats:
1081
 class GitStats:
1077
-	def run(self, args):
1078
-		if len(args) <  2:
1082
+	def run(self, args_orig):
1083
+		optlist, args = getopt.getopt(args_orig, 'c:')
1084
+		for o,v in optlist:
1085
+			if o == '-c':
1086
+				key, value = v.split('=', 1)
1087
+				if key not in conf:
1088
+					raise 'Error: no such key "%s" in config' % key
1089
+				conf[key] = value
1090
+
1091
+		if len(args) < 2:
1079
 			print """
1092
 			print """
1080
 Usage: gitstats [options] <gitpath> <outputpath>
1093
 Usage: gitstats [options] <gitpath> <outputpath>
1081
 
1094
 
1082
 Options:
1095
 Options:
1083
-"""
1096
+-c key=value     Override configuration value
1097
+
1098
+Default config values:
1099
+%s
1100
+""" % conf
1084
 			sys.exit(0)
1101
 			sys.exit(0)
1085
 
1102
 
1086
 		gitpath = args[0]
1103
 		gitpath = args[0]