]> dev.renevier.net Git - syj.git/commitdiff
make release.py script simpler
authorarno <arno@renevier.net>
Tue, 22 Mar 2011 22:40:14 +0000 (23:40 +0100)
committerarno <arno@renevier.net>
Wed, 23 Mar 2011 07:40:23 +0000 (08:40 +0100)
scripts/release.py
scripts/syj.install [new file with mode: 0644]

index ca83a2a12ba457c6896d0ca875662c8131c5812a..95452004e31a7609899cb24a793661a5cc9a55fa 100755 (executable)
@@ -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 (file)
index 0000000..3745391
--- /dev/null
@@ -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 .