Permalink
Newer
Older
100755 165 lines (125 sloc) 3.86 KB
1
#!/usr/bin/env python
2
3
import os, sys
4
from os import path
5
6
import getopt
7
import re
8
import shutil
9
import tempfile
10
11
# Absolute path to buildrelease.py
12
buildscript = path.dirname(path.abspath(__file__)) + '/buildrelease.py'
13
14
# Regular expressions of refs to ignore
15
ignorelist = map(re.compile, [
16
'HEAD',
17
'-1\.0\.[\w\d]+',
18
])
19
20
# Script options
21
options = "hfr:bacds:"
22
long_options = [ "help", "fresh", "ref=", "branches", "auto-suffix", "clean", "docbook", "suffix=" ]
23
24
def usage():
25
print '''Usage: buildrelease-repo [options] /path/for/tarballs [/path/to/repo]
26
Options: -h | --help Show this usage message
27
28
-f | --fresh Create a fresh clone at repository path, or temporary path
29
-r | --ref <ref>[,<ref>...] Build a release for named refs <ref>
30
-b | --branches Build a release for all branches
31
-a | --auto-suffix Automatically append the Git hash to the version suffix
32
33
-c | --clean Remove build directories when completed
34
-d | --docbook Build the docbook manuals
35
-s | --suffix <suffix> Include version suffix in config files'''
36
#end usage()
37
38
def ignore( ref ):
39
'''Decide which refs to ignore based on regexen listed in 'ignorelist'.
40
'''
41
42
ignore = False
43
for regex in ignorelist:
44
if len(regex.findall(ref)) > 0:
45
ignore = True
46
return ignore
47
#end ignore()
48
49
def main():
50
try:
51
opts, args = getopt.gnu_getopt(sys.argv[1:], options, long_options)
52
except getopt.GetoptError, err:
53
print str(err)
54
usage()
55
sys.exit(2)
56
57
pass_opts = ""
58
refs = []
59
all_branches = False
60
version_suffix = ""
61
auto_suffix = False
62
fresh_clone = False
63
delete_clone = False
64
65
for opt, val in opts:
66
if opt in ("-h", "--help"):
67
usage()
68
sys.exit(0)
69
70
elif opt in ("-f", "--fresh"):
71
fresh_clone = True
72
73
elif opt in ("-r", "--ref"):
74
refs.extend(val.split(","))
75
76
elif opt in ("-b", "--branches"):
77
all_branches = True
78
79
elif opt in ("-c", "--clean"):
80
pass_opts += " -c"
81
82
elif opt in ("-d", "--docbook"):
83
pass_opts += " -d"
84
85
elif opt in ("-a", "--auto-suffix"):
88
elif opt in ("-s", "--suffix"):
89
version_suffix = val
90
91
if len(args) < 1:
92
usage()
93
sys.exit(1)
94
95
release_path = args[0]
96
repo_path = "."
97
98
if len(args) > 1:
99
repo_path = args[1]
100
101
# Create a new repo clone
102
if fresh_clone:
103
if repo_path == ".":
104
repo_path = tempfile.mkdtemp(prefix="mantisbt-", suffix=".git")
105
delete_clone = True
106
os.system('git clone git://mantisbt.org/mantisbt.git %s' % (repo_path))
107
108
# Change to the repo path
109
os.chdir(repo_path)
110
111
# Update the repository
112
os.system('git fetch')
113
114
# Consolidate refs/branches
115
if all_branches:
116
os.system('git remote prune origin')
117
refs.extend(os.popen('git branch -r').read().split())
118
119
if len(refs) < 1:
120
refs.extend(os.popen('git log --pretty="format:%h" -n1').read())
121
122
refs = [ref for ref in refs if not ignore(ref)]
123
124
# Info
125
print "Will build the following releases:"
126
for ref in refs:
127
print " %s"%ref
128
print "\n"
129
130
# Regex to strip 'origin/' from ref names
131
refnameregex = re.compile('(?:[a-zA-Z0-9-.]+/)?(.*)')
132
133
for ref in refs:
134
os.system("git checkout -f %s"%(ref))
135
136
# Handle suffix/auto-suffix generation
137
hash = os.popen('git log --pretty="format:%h" -n1').read()
138
if hash != ref:
139
ref = refnameregex.search( ref ).group(1)
140
hash = "%s-%s"%(ref,hash)
141
142
suffix = ""
143
if auto_suffix and version_suffix:
144
suffix = "--suffix %s-%s"%(version_suffix, hash)
145
elif auto_suffix:
146
suffix = "--suffix %s"%hash
147
elif version_suffix:
148
suffix = "--suffix %s"%version_suffix
149
150
# Start building
151
os.system("%s %s %s %s %s"%(buildscript, pass_opts, suffix, release_path, repo_path))
152
153
# Cleanup temporary repo if needed
154
if delete_clone:
155
print "\nRemoving temporary clone."
156
shutil.rmtree(repo_path)
157
158
# Done
159
print "\nAll builds completed."
160
161
#end main()
162
163
if __name__ == "__main__":
164
main()