X-Git-Url: https://dev.renevier.net/?p=syj.git;a=blobdiff_plain;f=scripts%2Frelease.py;h=9a1b4d2959fc65726bdf282827dc35bbcc6147e8;hp=a1d30e44312b9f7a7050f727d249000de6b50275;hb=c06c7fd6e6f26d31abb8d7c9a9f9e3f2d5b27d5c;hpb=e4fe84ad088c55597a7772607da73f1d76d8d462 diff --git a/scripts/release.py b/scripts/release.py index a1d30e4..9a1b4d2 100755 --- a/scripts/release.py +++ b/scripts/release.py @@ -1,17 +1,34 @@ #!/usr/bin/python -TARGET="build" +__BUILD__="build" import shutil, os, sys, subprocess, tempfile, tarfile, glob, ConfigParser pathjoin = os.path.join -def createdir(): - if os.path.isdir(TARGET): - shutil.rmtree(TARGET, False) - os.makedirs(TARGET) +def updateversion(): + try: + version = None + import git + repo = git.Repo('.') + master = repo.commits()[0] + tag = (filter(lambda tag: tag.commit.id == master.id, repo.tags) or [""])[0] + if tag: + version = tag.name + except ImportError: + version = subprocess.Popen(['git', 'tag', '-l', '--contains', 'master'], stdout=subprocess.PIPE).communicate()[0][:-1] + if not version: + raise AssertionError, "master is not tagged" + + fd, fname = tempfile.mkstemp() + f = os.fdopen(fd, 'w') + versionfile = 'build/application/Version.php' + with open('build/application/Version.php') as source: + for line in source: + f.write(line.replace('$SYJVERSION$', version)) + f.close() + shutil.move(fname, versionfile) def compress(path): - print ("compressing " + path) tmpout = tempfile.TemporaryFile() subprocess.Popen(['yui-compressor', path], stdout=tmpout).communicate() tmpout.seek(0) @@ -23,19 +40,29 @@ def genscripts(): # copy scripts OpenLayers.js for path in glob.glob('public/js/*.js'): - shutil.copy(path, tmpdir) + if os.path.islink(path): + shutil.copy(path, tmpdir) + else: + # remove "use strict"; directive + with open(path) as inp: + dest = pathjoin(tmpdir, os.path.basename(path)) + with open(dest, "w") as out: + for line in inp: + sline = line.strip() + if sline != '"use strict"' and sline != '"use strict";': + out.write(line) # build OpenLayers.js - subprocess.call(['python', 'buildUncompressed.py', 'syj'], + subprocess.call(['python', 'buildUncompressed.py', + pathjoin(os.getcwd(), "scripts/syj"), pathjoin(tmpdir, "OpenLayers.js")], cwd = 'public/openlayers/openlayers/build') - shutil.copy('public/openlayers/openlayers/build/OpenLayers.js', tmpdir) config = ConfigParser.ConfigParser() - os.makedirs(pathjoin(TARGET, 'public/js')) + os.makedirs(pathjoin(__BUILD__, 'public/js')) config.readfp(open('application/configs/medias.ini')) for key, value in config.items('production'): if key.startswith('scripts.'): - outpath = pathjoin(TARGET, 'public/js/' + key[len('scripts.'):] + '.js') + outpath = pathjoin(__BUILD__, 'public/js/' + key[len('scripts.'):] + '.js') with open(outpath, 'w') as output: for inpath in map(lambda p: pathjoin(tmpdir, p.strip() + '.js'), value.split(',')): with open(inpath) as f: @@ -43,56 +70,63 @@ def genscripts(): compress(outpath) shutil.rmtree(tmpdir) -def genstyles(): - directory = pathjoin(TARGET, 'public/css') - os.makedirs(directory) +def install(source, target): + if not source: + return + + if os.path.isdir(source): + if not target: + target = source + buildtarget = pathjoin(__BUILD__, target) + parentdir = os.path.normpath(pathjoin(buildtarget, '..')) + if not os.path.isdir(parentdir): + os.makedirs(parentdir) + shutil.copytree(source, buildtarget) + + elif os.path.exists(source): + if not target: + target = os.path.dirname(source) + buildtarget = os.path.normpath(pathjoin(__BUILD__, target)) + if not os.path.isdir(buildtarget): + os.makedirs(buildtarget) + shutil.copy(source, buildtarget) + + else: + for item in glob.glob(source): + install(item, target) + +def main(): + if os.path.isdir(__BUILD__): + shutil.rmtree(__BUILD__, False) + + genscripts() + for path in glob.glob('public/css/*.css'): - shutil.copy(path, directory) - compress(pathjoin(TARGET, 'public/css', os.path.basename(path))) - -def genicons(): - directory = pathjoin(TARGET, 'public/icons') - os.makedirs(directory) - for path in glob.glob('public/icons/*'): - shutil.copy(path, directory) - -def genolmisc(): - directory = pathjoin(TARGET, 'public/img') - os.makedirs(directory) - for path in glob.glob('public/js/img/*'): - shutil.copy(path, directory) - -def tarbuild(): - print "creating syj.tar.gz" - targz = tarfile.open("build/syj.tar.gz", "w:gz") - for path in ["application", "library", "public"]: - targz.add(pathjoin(TARGET, path)) - targz.close() + install(path, None) + compress(pathjoin(__BUILD__, 'public/css', os.path.basename(path))) + with open("scripts/syj.install") as f: + for line in f: + line = line.split('#')[0].strip() + if not line: + continue; -def genlibrary(): - directory = pathjoin(TARGET, 'library') - os.makedirs(directory) - for path in glob.glob('library/*.php'): - shutil.copy(path, directory) + parts = line.split(' ') + if len(parts) > 1: + source = parts[0] + target = parts[1] + else: + source = line + target = None - directory = pathjoin(TARGET, 'library/Zend') - os.makedirs(directory) - for path in glob.glob('library/Zend/*'): # will not take .git - if (os.path.isdir(path)): - shutil.copytree(path, pathjoin(directory, os.path.basename(path))) - else: - shutil.copy(path, directory) + install(source, target) -def genmedias(): - genscripts() - genstyles() - genicons() - genolmisc() - genlibrary() - shutil.copytree('application', pathjoin(TARGET, 'application')) - shutil.copy('public/index.php', pathjoin(TARGET, 'public')) - tarbuild() - -createdir() -genmedias() + updateversion() + + print "creating syj.tar.gz" + targz = tarfile.open("build/syj.tar.gz", "w:gz") + for path in glob.glob(pathjoin(__BUILD__, '*')): + targz.add(path) + targz.close() + +main()