Skip to content

Commit 1f4847c

Browse files
committed
- added (incomplete) script makerelease.py to handle svn tagging and tar balls generation
1 parent 35503e5 commit 1f4847c

File tree

2 files changed

+192
-35
lines changed

2 files changed

+192
-35
lines changed

doxybuild.py

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -89,55 +89,42 @@ def do_subst_in_file(targetfile, sourcefile, dict):
8989
print "Can't write target file %s"%targetfile
9090
raise
9191

92-
def run_doxygen(doxygen_path, config_file, working_dir):
92+
def run_doxygen(doxygen_path, config_file, working_dir, is_silent):
9393
config_file = os.path.abspath( config_file )
9494
doxygen_path = doxygen_path
9595
old_cwd = os.getcwd()
9696
try:
9797
os.chdir( working_dir )
9898
cmd = [doxygen_path, config_file]
99-
print ' '.join( cmd )
99+
print 'Running:', ' '.join( cmd )
100100
try:
101101
import subprocess
102102
except:
103103
if os.system( ' '.join( cmd ) ) != 0:
104104
print 'Documentation generation failed'
105105
return False
106106
else:
107-
try:
108-
subprocess.check_call( cmd )
109-
except subprocess.CalledProcessError:
107+
if is_silent:
108+
process = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
109+
else:
110+
process = subprocess.Popen( cmd )
111+
stdout, _ = process.communicate()
112+
if process.returncode:
113+
print 'Documentation generation failed:'
114+
print stdout
110115
return False
111116
return True
112117
finally:
113118
os.chdir( old_cwd )
114119

115-
def main():
116-
usage = """%prog
117-
Generates doxygen documentation in build/doxygen.
118-
Optionaly makes a tarball of the documentation to dist/.
119-
120-
Must be started in the project top directory.
121-
"""
122-
from optparse import OptionParser
123-
parser = OptionParser(usage=usage)
124-
parser.allow_interspersed_args = False
125-
parser.add_option('--with-dot', dest="with_dot", action='store_true', default=False,
126-
help="""Enable usage of DOT to generate collaboration diagram""")
127-
parser.add_option('--dot', dest="dot_path", action='store', default=find_program('dot'),
128-
help="""Path to GraphViz dot tool. Must be full qualified path. [Default: %default]""")
129-
parser.add_option('--doxygen', dest="doxygen_path", action='store', default=find_program('doxygen'),
130-
help="""Path to Doxygen tool. [Default: %default]""")
131-
parser.add_option('--with-html-help', dest="with_html_help", action='store_true', default=False,
132-
help="""Enable generation of Microsoft HTML HELP""")
133-
parser.add_option('--no-uml-look', dest="with_uml_look", action='store_false', default=True,
134-
help="""Generates DOT graph without UML look [Default: False]""")
135-
parser.add_option('--open', dest="open", action='store_true', default=False,
136-
help="""Open the HTML index in the web browser after generation""")
137-
parser.add_option('--tarball', dest="make_tarball", action='store_true', default=False,
138-
help="""Generates a tarball of the documentation in dist/ directory""")
139-
parser.enable_interspersed_args()
140-
options, args = parser.parse_args()
120+
def build_doc( options, make_release=False ):
121+
if make_release:
122+
options.make_tarball = True
123+
options.with_dot = True
124+
options.with_html_help = True
125+
options.with_uml_look = True
126+
options.open = False
127+
options.silent = True
141128

142129
version = open('version','rt').read().strip()
143130
output_dir = '../build/doxygen' # relative to doc/doxyfile location.
@@ -167,10 +154,9 @@ def yesno( bool ):
167154
os.makedirs( full_output_dir )
168155

169156
do_subst_in_file( 'doc/doxyfile', 'doc/doxyfile.in', subst_keys )
170-
ok = run_doxygen( options.doxygen_path, 'doc/doxyfile', 'doc' )
171-
print open(os.path.join('doc', warning_log_path), 'rb').read()
172-
if not ok:
173-
print 'Doxygen generation failed'
157+
ok = run_doxygen( options.doxygen_path, 'doc/doxyfile', 'doc', is_silent=options.silent )
158+
if not options.silent:
159+
print open(os.path.join('doc', warning_log_path), 'rb').read()
174160
index_path = os.path.abspath(os.path.join(subst_keys['%HTML_OUTPUT%'], 'index.html'))
175161
print 'Generated documentation can be found in:'
176162
print index_path
@@ -187,5 +173,35 @@ def yesno( bool ):
187173
tarball_basedir = os.path.join( full_output_dir, html_output_dirname )
188174
make_tarball( tarball_path, tarball_sources, tarball_basedir, html_output_dirname )
189175

176+
def main():
177+
usage = """%prog
178+
Generates doxygen documentation in build/doxygen.
179+
Optionaly makes a tarball of the documentation to dist/.
180+
181+
Must be started in the project top directory.
182+
"""
183+
from optparse import OptionParser
184+
parser = OptionParser(usage=usage)
185+
parser.allow_interspersed_args = False
186+
parser.add_option('--with-dot', dest="with_dot", action='store_true', default=False,
187+
help="""Enable usage of DOT to generate collaboration diagram""")
188+
parser.add_option('--dot', dest="dot_path", action='store', default=find_program('dot'),
189+
help="""Path to GraphViz dot tool. Must be full qualified path. [Default: %default]""")
190+
parser.add_option('--doxygen', dest="doxygen_path", action='store', default=find_program('doxygen'),
191+
help="""Path to Doxygen tool. [Default: %default]""")
192+
parser.add_option('--with-html-help', dest="with_html_help", action='store_true', default=False,
193+
help="""Enable generation of Microsoft HTML HELP""")
194+
parser.add_option('--no-uml-look', dest="with_uml_look", action='store_false', default=True,
195+
help="""Generates DOT graph without UML look [Default: False]""")
196+
parser.add_option('--open', dest="open", action='store_true', default=False,
197+
help="""Open the HTML index in the web browser after generation""")
198+
parser.add_option('--tarball', dest="make_tarball", action='store_true', default=False,
199+
help="""Generates a tarball of the documentation in dist/ directory""")
200+
parser.add_option('-s', '--silent', dest="silent", action='store_true', default=False,
201+
help="""Hides doxygen output""")
202+
parser.enable_interspersed_args()
203+
options, args = parser.parse_args()
204+
build_doc( options )
205+
190206
if __name__ == '__main__':
191207
main()

makerelease.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
"""Tag the sandbox for release, make source and doc tarballs.
2+
3+
Requires Python 2.6
4+
5+
Example of invocation (use to test the script):
6+
python makerelease.py --force --retag 0.5.0 0.6.0-dev
7+
8+
Example of invocation when doing a release:
9+
python makerelease.py 0.5.0 0.6.0-dev
10+
"""
11+
import os.path
12+
import subprocess
13+
import sys
14+
import doxybuild
15+
import subprocess
16+
import xml.etree.ElementTree as ElementTree
17+
18+
SVN_ROOT = 'https://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/'
19+
SVN_TAG_ROOT = SVN_ROOT + 'tags/jsoncpp'
20+
21+
def set_version( version ):
22+
with open('version','wb') as f:
23+
f.write( version.strip() )
24+
25+
class SVNError(Exception):
26+
pass
27+
28+
def svn_command( command, *args ):
29+
cmd = ['svn', '--non-interactive', command] + list(args)
30+
print 'Running:', ' '.join( cmd )
31+
process = subprocess.Popen( cmd,
32+
stdout=subprocess.PIPE,
33+
stderr=subprocess.STDOUT )
34+
stdout = process.communicate()[0]
35+
if process.returncode:
36+
error = SVNError( 'SVN command failed:\n' + stdout )
37+
error.returncode = process.returncode
38+
raise error
39+
return stdout
40+
41+
def check_no_pending_commit():
42+
"""Checks that there is no pending commit in the sandbox."""
43+
stdout = svn_command( 'status', '--xml' )
44+
etree = ElementTree.fromstring( stdout )
45+
msg = []
46+
for entry in etree.getiterator( 'entry' ):
47+
path = entry.get('path')
48+
status = entry.find('wc-status').get('item')
49+
if status != 'unversioned':
50+
msg.append( 'File "%s" has pending change (status="%s")' % (path, status) )
51+
if msg:
52+
msg.insert(0, 'Pending change to commit found in sandbox. Commit them first!' )
53+
return '\n'.join( msg )
54+
55+
def svn_join_url( base_url, suffix ):
56+
if not base_url.endswith('/'):
57+
base_url += '/'
58+
if suffix.startswith('/'):
59+
suffix = suffix[1:]
60+
return base_url + suffix
61+
62+
def svn_check_if_tag_exist( tag_url ):
63+
"""Checks if a tag exist.
64+
Returns: True if the tag exist, False otherwise.
65+
"""
66+
try:
67+
list_stdout = svn_command( 'list', tag_url )
68+
except SVNError, e:
69+
if e.returncode != 1 or not str(e).find('tag_url'):
70+
raise e
71+
# otherwise ignore error, meaning tag does not exist
72+
return False
73+
return True
74+
75+
def svn_tag_sandbox( tag_url, message ):
76+
"""Makes a tag based on the sandbox revisions.
77+
"""
78+
svn_command( 'copy', '-m', message, '.', tag_url )
79+
80+
def svn_remove_tag( tag_url, message ):
81+
"""Removes an existing tag.
82+
"""
83+
svn_command( 'delete', '-m', message, tag_url )
84+
85+
def main():
86+
usage = """%prog release_version next_dev_version
87+
Update 'version' file to release_version and commit.
88+
Generates the document tarball.
89+
Tags the sandbox revision with release_version.
90+
Update 'version' file to next_dev_version and commit.
91+
92+
Performs an svn export of tag release version, and build a source tarball.
93+
94+
Must be started in the project top directory.
95+
"""
96+
from optparse import OptionParser
97+
parser = OptionParser(usage=usage)
98+
parser.allow_interspersed_args = False
99+
parser.add_option('--dot', dest="dot_path", action='store', default=doxybuild.find_program('dot'),
100+
help="""Path to GraphViz dot tool. Must be full qualified path. [Default: %default]""")
101+
parser.add_option('--doxygen', dest="doxygen_path", action='store', default=doxybuild.find_program('doxygen'),
102+
help="""Path to Doxygen tool. [Default: %default]""")
103+
parser.add_option('--force', dest="ignore_pending_commit", action='store_true', default=False,
104+
help="""Ignore pending commit. [Default: %default]""")
105+
parser.add_option('--retag', dest="retag_release", action='store_true', default=False,
106+
help="""Overwrite release existing tag if it exist. [Default: %default]""")
107+
parser.enable_interspersed_args()
108+
options, args = parser.parse_args()
109+
110+
if len(args) < 1:
111+
parser.error( 'release_version missing on command-line.' )
112+
release_version = args[0]
113+
114+
if options.ignore_pending_commit:
115+
msg = ''
116+
else:
117+
msg = check_no_pending_commit()
118+
if not msg:
119+
print 'Setting version to', release_version
120+
set_version( release_version )
121+
tag_url = svn_join_url( SVN_TAG_ROOT, release_version )
122+
if svn_check_if_tag_exist( tag_url ):
123+
if options.retag_release:
124+
svn_remove_tag( tag_url, 'Overwriting previous tag' )
125+
else:
126+
print 'Aborting, tag %s already exist. Use --retag to overwrite it!' % tag_url
127+
sys.exit( 1 )
128+
svn_tag_sandbox( tag_url, 'Release ' + release_version )
129+
print 'Generated doxygen document...'
130+
doxybuild.build_doc( options, make_release=True )
131+
#@todo:
132+
# svn export
133+
# source tarball
134+
# decompress source tarball
135+
# ?compile & run & check
136+
# ?upload documentation
137+
else:
138+
sys.stderr.write( msg + '\n' )
139+
140+
if __name__ == '__main__':
141+
main()

0 commit comments

Comments
 (0)