From d36500c8a1bb852d876ac387f31fec55d92d6789 Mon Sep 17 00:00:00 2001 From: arno Date: Tue, 22 Mar 2011 23:40:14 +0100 Subject: [PATCH] make release.py script simpler --- scripts/release.py | 113 ++++++++++++++++++++++---------------------- scripts/syj.install | 11 +++++ 2 files changed, 67 insertions(+), 57 deletions(-) create mode 100644 scripts/syj.install diff --git a/scripts/release.py b/scripts/release.py index ca83a2a..9545200 100755 --- a/scripts/release.py +++ b/scripts/release.py @@ -1,17 +1,11 @@ #!/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 compress(path): - print ("compressing " + path) tmpout = tempfile.TemporaryFile() subprocess.Popen(['yui-compressor', path], stdout=tmpout).communicate() tmpout.seek(0) @@ -31,11 +25,11 @@ def genscripts(): cwd = 'public/openlayers/openlayers/build') 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 +37,61 @@ 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() + 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() diff --git a/scripts/syj.install b/scripts/syj.install new file mode 100644 index 0000000..3745391 --- /dev/null +++ b/scripts/syj.install @@ -0,0 +1,11 @@ +public/js/img public/img +public/icons +library/*.php +library/Zend/* # will not take .git +application +public/*.php +scripts/cron.php +scripts/db_auth.sh +scripts/updategeoip.sh +scripts/updategeonames.sh +scripts/crontab.syj . -- 2.39.2