| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
import os, sys, time, re, types |
| 24 |
from os.path import isfile |
| 25 |
from optparse import OptionParser |
| 26 |
from urllib.request import urlopen |
| 27 |
import scriptlib as s |
| 28 |
|
| 29 |
_module_path = os.path.split(os.path.realpath(sys._getframe().f_code.co_filename))[0] |
| 30 |
|
| 31 |
s.cd(_module_path + '/../wxgeometrie') |
| 32 |
|
| 33 |
parser = OptionParser(prog='release.py', usage="usage: %prog [options] release_number") |
| 34 |
parser.add_option("-o", "--output", dest="output", default='..', |
| 35 |
help="store output archive as FILE", metavar="FILE") |
| 36 |
parser.add_option("-m", "--message", dest="message", |
| 37 |
help="set release message to MSG (default: 'Version VERSION')", metavar="MSG") |
| 38 |
parser.add_option("-n", "--dry-run", |
| 39 |
action="store_true", dest="fake", default=False, |
| 40 |
help="simulate only") |
| 41 |
parser.add_option("-a", "--archive-only", |
| 42 |
action="store_true", dest="archive_only", default=False, |
| 43 |
help="Create an archive but DON'T make a release tag in git.\n" |
| 44 |
"This is useful to make release candidates or test release process.") |
| 45 |
parser.add_option("-p", "--publish", |
| 46 |
action="store_true", dest="publish", default=False, |
| 47 |
help=("publish on sourceforge (source package only)\n" |
| 48 |
"and change current version number online.")) |
| 49 |
parser.add_option("-b", "--publish-only", |
| 50 |
action="store_true", dest="publish_only", default=False, |
| 51 |
help="Publish last (already existing) release.") |
| 52 |
parser.add_option("-q", "--quiet", |
| 53 |
action="store_true", dest="quiet", default=False, |
| 54 |
help="don't ask for confirmation") |
| 55 |
|
| 56 |
(options, args) = parser.parse_args() |
| 57 |
|
| 58 |
def publish(filename, version): |
| 59 |
"""Publie le fichier sur sourceforge, et met à jour le fichier distant |
| 60 |
contenant le numéro de la dernière version. |
| 61 |
""" |
| 62 |
SOURCEFORGE_CONFIG = 'tools/.sourceforge' |
| 63 |
if isfile(SOURCEFORGE_CONFIG): |
| 64 |
with open(SOURCEFORGE_CONFIG) as _file: |
| 65 |
key = _file.read(1000) |
| 66 |
else: |
| 67 |
key = input('API-key:') |
| 68 |
print('\nMise en ligne de la version %s (%s)' % (version, filename)) |
| 69 |
remote_dir = '/home/frs/project/geophar/Geophar/version_%s' % version |
| 70 |
s.command('ssh wxgeo,[email protected] create') |
| 71 |
s.command('cat %s | ssh [email protected] "mkdir -p %s;cat > %s/%s"' |
| 72 |
% (filename, remote_dir, remote_dir, filename)) |
| 73 |
|
| 74 |
s.command(('curl -H "Accept: application/json" ' |
| 75 |
'-X PUT -d "default=linux&default=bsd&default=solaris&default=others"' |
| 76 |
'-d "api_key=%s" ' |
| 77 |
'https://sourceforge.net/projects/geophar/files/Geophar/version_%s/%s') |
| 78 |
% (key, version, filename)) |
| 79 |
urlopen('http://wxgeo.free.fr/wordpress/update_geophar_version.php?version=%s' % version) |
| 80 |
|
| 81 |
def version_interne(version): |
| 82 |
version = version.replace("alpha", "-3").replace("beta", "-2").replace("rc", "-1").replace(".", " ").replace("_", " ") |
| 83 |
return [int(n) for n in version.split(' ')] |
| 84 |
|
| 85 |
def test_version(version): |
| 86 |
version = version.replace(' ', '_') |
| 87 |
reg='[0-9]+[.][0-9]+(([.][0-9]+([.][0-9]+)?)|(_(beta|alpha|rc)_[0-9]+))?$' |
| 88 |
if re.match(reg, version): |
| 89 |
return version |
| 90 |
|
| 91 |
s.cd('..') |
| 92 |
sys.path.insert(0, os.getcwd()) |
| 93 |
from wxgeometrie.param import version as version_precedente, NOMPROG2, NOMPROG |
| 94 |
nom_prog = NOMPROG2.lower() |
| 95 |
|
| 96 |
if options.publish_only: |
| 97 |
filename = '%s_%s.tar.gz' % (nom_prog, version_precedente) |
| 98 |
publish(filename, version_precedente) |
| 99 |
print('\nTerminé.') |
| 100 |
sys.exit() |
| 101 |
|
| 102 |
|
| 103 |
s.cd('wxgeometrie') |
| 104 |
|
| 105 |
sys.path.insert(0, os.getcwd()) |
| 106 |
|
| 107 |
|
| 108 |
if options.fake: |
| 109 |
for nom, val in s.__dict__.items(): |
| 110 |
if isinstance(val, types.FunctionType) and nom not in ('version_interne', 'test_version'): |
| 111 |
setattr(s, nom, eval("lambda s, *args, **kw:print('@%s: ' + s)" %nom)) |
| 112 |
|
| 113 |
e. |
| 114 |
y. |
| 115 |
t=time.localtime() |
| 116 |
date = str((t.tm_year, t.tm_mon, t.tm_mday)) |
| 117 |
contenu = [] |
| 118 |
with open('version.py', 'r') as f: |
| 119 |
for line in f: |
| 120 |
if line.startswith('date_version = '): |
| 121 |
contenu.append('date_version = %s\n' % date) |
| 122 |
elif line.startswith('version = '): |
| 123 |
|
| 124 |
rd. |
| 125 |
contenu.append('version = %s\n') |
| 126 |
elif line.startswith('git = '): |
| 127 |
contenu.append('git = ' + repr(s.command('git describe').strip())) |
| 128 |
else: |
| 129 |
contenu.append(line) |
| 130 |
|
| 131 |
|
| 132 |
if options.archive_only: |
| 133 |
last_commit_hash = s.command('git rev-parse --short HEAD').strip() |
| 134 |
date = time.strftime('%d.%m.%Y-%H.%M.%S') |
| 135 |
version = '%s-git-%s-%s' % (version_precedente, last_commit_hash, date) |
| 136 |
else: |
| 137 |
if len(args) != 1: |
| 138 |
parser.error("fournir un (et un seul) argument (numero de version).\nVersion actuelle: " + version_precedente) |
| 139 |
version = args[0] |
| 140 |
: |
| 141 |
while True: |
| 142 |
modifier = False |
| 143 |
print('\n-------------------') |
| 144 |
print("Version précédente: " + version_precedente) |
| 145 |
version = test_version(version) |
| 146 |
if version is None: |
| 147 |
print('Numero de version incorrect: ' + args[0]) |
| 148 |
modifier = True |
| 149 |
elif version_interne(version) <= version_interne(version_precedente): |
| 150 |
print('Les numeros de version doivent etre croissants: ' + args[0]) |
| 151 |
modifier = True |
| 152 |
else: |
| 153 |
print("Nouvelle version: " + version) |
| 154 |
if options.quiet: |
| 155 |
break |
| 156 |
rep = input("Est-ce correct ? [y(es)/n(o)/(q)uit]") |
| 157 |
if not rep: |
| 158 |
continue |
| 159 |
if rep in 'yYoO': |
| 160 |
break |
| 161 |
elif rep in 'qQ': |
| 162 |
sys.exit() |
| 163 |
elif rep in 'nN': |
| 164 |
modifier = True |
| 165 |
if modifier: |
| 166 |
version = input("Entrez un nouveau numero de version:") |
| 167 |
|
| 168 |
print('\nCréation de la version ' + version + '...') |
| 169 |
|
| 170 |
if not (options.fake or options.archive_only): |
| 171 |
y |
| 172 |
with open('version.py', 'w') as f: |
| 173 |
f.write(''.join(contenu).strip() % repr(version)) |
| 174 |
|
| 175 |
t |
| 176 |
date = time.strftime("%d/%m/%Y") |
| 177 |
s.command('echo "%s version %s\nPubliée le %s\n\n">doc/changelog.txt' |
| 178 |
% (NOMPROG, version, date)) |
| 179 |
|
| 180 |
tags = s.command('git tag', quiet=True).strip().split('\n') |
| 181 |
|
| 182 |
|
| 183 |
tags = [tag[1:] for tag in reversed(tags)] |
| 184 |
ente |
| 185 |
for tag in tags: |
| 186 |
if tag.count('.') == 1 and not version.startswith(tag): |
| 187 |
break |
| 188 |
|
| 189 |
s.command('git log v%s..HEAD --no-merges --pretty="* %%s">>doc/changelog.txt' % tag) |
| 190 |
|
| 191 |
|
| 192 |
s.command('git add doc/changelog.txt') |
| 193 |
s.command('git add version.py') |
| 194 |
s.command('git commit -m %s' % repr('Version ' + version)) |
| 195 |
|
| 196 |
archive_tar = "%s_%s.tar" % (nom_prog, version) |
| 197 |
archive_gz = archive_tar + '.gz' |
| 198 |
|
| 199 |
print('\nCréation du paquet...') |
| 200 |
|
| 201 |
t) |
| 202 |
s.cd('..') |
| 203 |
s.rmdir('build_', quiet=True) |
| 204 |
s.rm(archive_gz, quiet=True) |
| 205 |
|
| 206 |
_/ |
| 207 |
s.mkdir('build_') |
| 208 |
s.mkdir('build_/%s' % nom_prog) |
| 209 |
|
| 210 |
if options.archive_only: |
| 211 |
s.command('git archive HEAD -o build_/%s.tar' % nom_prog) |
| 212 |
else: |
| 213 |
e |
| 214 |
tag = 'v' + version |
| 215 |
s.command('git tag -am %s %s' %(repr(options.message or 'Version ' + version), tag)) |
| 216 |
|
| 217 |
it |
| 218 |
s.command('git archive %s -o build_/%s.tar' % (tag, nom_prog)) |
| 219 |
|
| 220 |
|
| 221 |
s.cd('build_') |
| 222 |
s.command('tar -xf %s.tar --directory %s' % (nom_prog, nom_prog)) |
| 223 |
s.rm('%s.tar' % nom_prog) |
| 224 |
s.cd(nom_prog) |
| 225 |
s.rename('README.md', 'README') |
| 226 |
s.rm('MANIFEST.in') |
| 227 |
s.rm('.gitignore') |
| 228 |
s.rename('wxgeometrie/param/personnaliser_.py', 'wxgeometrie/param/personnaliser.py') |
| 229 |
s.cd('..') |
| 230 |
|
| 231 |
z |
| 232 |
s.command('tar -cf %s %s' % (archive_tar, nom_prog)) |
| 233 |
s.command('gzip %s' % archive_tar) |
| 234 |
s.mv(archive_gz, options.output) |
| 235 |
|
| 236 |
print('\nPaquet créé dans %s.\n' % os.path.abspath(options.output)) |
| 237 |
|
| 238 |
. |
| 239 |
if options.publish: |
| 240 |
publish(archive_gz, version) |
| 241 |
|
| 242 |
|
| 243 |
s.cd('..') |
| 244 |
s.rmdir('build_') |