3 # Copyright (C) 2009-2010 W. Trevor King <wking@drexel.edu>
5 # This file is part of Bugs Everywhere.
7 # Bugs Everywhere is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation, either version 2 of the License, or (at your
10 # option) any later version.
12 # Bugs Everywhere is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Bugs Everywhere. If not, see <http://www.gnu.org/licenses/>.
26 from libbe.util.subproc import Pipe, invoke
27 from update_copyright import update_authors, update_files
30 INITIAL_COMMIT = '1bf1ec598b436f41ff27094eddf0b28c797e359d'
33 def validate_tag(tag):
35 >>> validate_tag('1.0.0')
36 >>> validate_tag('A.B.C-r7')
37 >>> validate_tag('A.B.C r7')
38 Traceback (most recent call last):
40 Exception: Invalid character ' ' in tag 'A.B.C r7'
42 Traceback (most recent call last):
44 Exception: Invalid character '"' in tag '"'
46 Traceback (most recent call last):
48 Exception: Invalid character ''' in tag '''
51 if char in string.digits:
53 elif char in string.letters:
55 elif char in ['.','-']:
57 raise Exception("Invalid character '%s' in tag '%s'" % (char, tag))
59 def pending_changes():
60 """Use `git diff`s output to detect change.
62 status,stdout,stderr = invoke(['git', 'diff', 'HEAD'])
67 def set_release_version(tag):
68 print "set libbe.version._VERSION = '%s'" % tag
69 invoke(['sed', '-i', "s/^# *_VERSION *=.*/_VERSION = '%s'/" % tag,
70 os.path.join('libbe', 'version.py')])
72 def remove_makefile_libbe_version_dependencies(filename):
73 print "set %s LIBBE_VERSION :=" % filename
74 invoke(['sed', '-i', "s/^LIBBE_VERSION *:=.*/LIBBE_VERSION :=/",
77 def commit(commit_message):
78 print 'commit current status:', commit_message
79 invoke(['git', 'commit', '-a', '-m', commit_message])
82 print 'tag current revision', tag
83 invoke(['git', 'tag', tag])
85 def export(target_dir):
86 if not target_dir.endswith(os.path.sep):
87 target_dir += os.path.sep
88 print 'export current revision to', target_dir
89 p = Pipe([['git', 'archive', '--prefix', target_dir, 'HEAD'],
91 assert p.status == 0, p.statuses
94 print 'generate libbe/_version.py'
95 invoke(['make', os.path.join('libbe', '_version.py')])
97 def make_changelog(filename, tag):
98 """Generate a ChangeLog from the git history.
100 Not the most ChangeLog-esque format, but iterating through commits
101 by hand is just too slow.
103 print 'generate ChangeLog file', filename, 'up to tag', tag
104 invoke(['git', 'log', '--no-merges',
105 '%s..%s' % (INITIAL_COMMIT, tag)],
106 stdout=open(filename, 'w')),
108 def set_vcs_name(be_dir, vcs_name='None'):
109 """Exported directory is not a git repository, so set vcs_name to
110 something that will work.
111 vcs_name: new_vcs_name
113 for directory in os.listdir(be_dir):
114 if not os.path.isdir(os.path.join(be_dir, directory)):
116 filename = os.path.join(be_dir, directory, 'settings')
117 if os.path.exists(filename):
118 print 'set vcs_name in', filename, 'to', vcs_name
119 invoke(['sed', '-i', "s/^vcs_name:.*/vcs_name: %s/" % vcs_name,
122 def create_tarball(tag):
123 release_name='be-%s' % tag
124 export_dir = release_name
127 remove_makefile_libbe_version_dependencies(
128 os.path.join(export_dir, 'Makefile'))
129 print 'copy libbe/_version.py to %s/libbe/_version.py' % export_dir
130 shutil.copy(os.path.join('libbe', '_version.py'),
131 os.path.join(export_dir, 'libbe', '_version.py'))
132 make_changelog(os.path.join(export_dir, 'ChangeLog'), tag)
133 set_vcs_name(os.path.join(export_dir, '.be'))
134 tarball_file = '%s.tar.gz' % release_name
135 print 'create tarball', tarball_file
136 invoke(['tar', '-czf', tarball_file, export_dir])
137 print 'remove', export_dir
138 shutil.rmtree(export_dir)
144 if __name__ == '__main__':
146 usage = """%prog [options] TAG
148 Create a git tag and a release tarball from the current revision.
152 You may wish to test this out in a dummy branch first to make sure it
153 works as expected to avoid the tedium of unwinding the version-bump
156 p = optparse.OptionParser(usage)
157 p.add_option('--test', dest='test', default=False,
158 action='store_true', help='Run internal tests and exit')
159 options,args = p.parse_args()
161 if options.test == True:
165 assert len(args) == 1, '%d (!= 1) arguments: %s' % (len(args), args)
169 if pending_changes() == True:
170 print "Handle pending changes before releasing."
172 set_release_version(_tag)
173 print "Update copyright information..."
176 commit("Bumped to version %s" % _tag)