Project:
MantisBT
Code Location:
git://github.com/mantisbt/mantisbt-tools.gitmaster
/
Outline
docbook-manual-repo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python # Integrates with docbook-manual.py to build manuals for all tagged # versions and development branches in the Git repo import os, sys from os import path import getopt import re # Absolute path to docbook-manual.py manualscript = path.dirname(path.abspath(__file__)) + '/docbook-manual.py' # Regular expressions of refs to ignore ignorelist = map(re.compile, [ 'HEAD', '->', '-1\.0\.[\w\d]+', '-1\.1\.[\w\d]+' ]) # Script options options = "hr:fda" long_options = [ "help", "ref=", "force", "delete", "all", "pdf", "html", "release" ] def usage(): print '''Usage: docbook-manual-repo /path/to/mantisbt/repo /path/to/install [<lang> ...] Options: -h | --help Print this usage message -r | --ref Select what refs to build -f | --force Ignore timestamps and force building -d | --delete Delete install directories before building --html Build HTML manual --pdf Build PDF manual --release Build single file types used for release tarballs -a | --all Build all manual types''' #end usage() def ignore( ref ): '''Decide which refs to ignore based on regexen listed in 'ignorelist'. ''' ignore = False for regex in ignorelist: if len(regex.findall(ref)) > 0: ignore = True return ignore #end ignore() def main(): try: opts, args = getopt.gnu_getopt(sys.argv[1:], options, long_options) except getopt.GetoptError, err: print str(err) usage() sys.exit(2) refs = None force = False pass_opts = "" for opt, val in opts: if opt in ("-h", "--help"): usage() sys.exit(0) elif opt in ("-r", "--ref"): refs = val.split(",") elif opt in ("-f", "--force"): force = True elif opt in ("-d", "--delete"): pass_opts += " -d" elif opt in ("-a", "--all"): pass_opts += " -a" elif opt == "--html": pass_opts += " --html" elif opt == "--pdf": pass_opts += " --pdf" elif opt == "--release": pass_opst += " --release" if len(args) < 2: usage() sys.exit(1) repo = args[0] installroot = args[1] languages = [] if len(sys.argv) > 2: languages = args[2:] # Update repo from default remote os.chdir(repo) os.system('git fetch') os.system('git remote prune origin') if refs is None: # List refs from remote branches and tags branches = os.popen('git branch -r').read().split() tags = os.popen('git tag -l').read().split() # Filter refs using ignore() refs = [ref for ref in branches + tags if not ignore(ref)] # Regex to strip 'origin/' from ref names refnameregex = re.compile('(?:[a-zA-Z0-9-.]+/)?(.*)') # For each ref, checkout and call docbook-manual.py, tracking last build timestamp # to prevent building a manual if there have been no commits since last build for ref in refs: manualpath = installroot.rstrip('/') + '/' + refnameregex.search( ref ).group(1) os.system('git checkout -f %s'%(ref)) lastchange = os.popen('git log --pretty="format:%ct" -n1').read() buildfile = path.join(manualpath, '.build') lastbuild = 0 if path.exists(buildfile): f = open(buildfile, 'r') lastbuild = f.read() f.close() if lastchange > lastbuild or force: buildcommand = '%s %s %s %s %s'%(manualscript, pass_opts, path.abspath('docbook'), manualpath, ' '.join(languages)) print "Calling: " + buildcommand if(os.system(buildcommand)): print 'here' f = open(buildfile, 'w') f.write(lastchange) f.close() #end main if __name__ == '__main__': main()
