]> dev.renevier.net Git - syj.git/blobdiff - scripts/release.py
build process raise an exception when install file contains an invalide filename
[syj.git] / scripts / release.py
index 95452004e31a7609899cb24a793661a5cc9a55fa..3b5c9ea5ae99cb3e017185d897ff457737019e47 100755 (executable)
@@ -5,9 +5,35 @@ __BUILD__="build"
 import shutil, os, sys, subprocess, tempfile, tarfile, glob, ConfigParser
 pathjoin = os.path.join
 
+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):
     tmpout = tempfile.TemporaryFile()
-    subprocess.Popen(['yui-compressor', path], stdout=tmpout).communicate()
+    try:
+        subprocess.Popen(['yui-compressor', path], stdout=tmpout).communicate()
+    except OSError:
+        subprocess.Popen(['yuicompressor', path], stdout=tmpout).communicate()
     tmpout.seek(0)
     with open(path, 'w') as output:
         output.write(tmpout.read())
@@ -17,7 +43,17 @@ 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',
@@ -59,8 +95,12 @@ def install(source, target):
         shutil.copy(source, buildtarget)
 
     else:
+        hascontent = False
         for item in glob.glob(source):
+            hascontent = True
             install(item, target)
+        if not hascontent: # not a directory or a file or a list of files
+            raise Exception(("%s does not exist" % source))
 
 def main():
     if os.path.isdir(__BUILD__):
@@ -88,6 +128,8 @@ def main():
 
             install(source, target)
 
+    updateversion()
+
     print "creating syj.tar.gz"
     targz = tarfile.open("build/syj.tar.gz", "w:gz")
     for path in glob.glob(pathjoin(__BUILD__, '*')):