]> dev.renevier.net Git - syj.git/blob - scripts/release.py
update OpenLayers and put syj.cfg outside OpenLayers directory
[syj.git] / scripts / release.py
1 #!/usr/bin/python
2
3 TARGET="build"
4
5 import shutil, os, sys, subprocess, tempfile, tarfile, glob, ConfigParser
6 pathjoin = os.path.join
7
8 def createdir():
9     if os.path.isdir(TARGET):
10         shutil.rmtree(TARGET, False)
11     os.makedirs(TARGET)
12
13 def compress(path):
14     print ("compressing " + path)
15     tmpout = tempfile.TemporaryFile()
16     subprocess.Popen(['yui-compressor', path], stdout=tmpout).communicate()
17     tmpout.seek(0)
18     with open(path, 'w') as output:
19         output.write(tmpout.read())
20
21 def genscripts():
22     tmpdir = tempfile.mkdtemp()
23
24     # copy scripts OpenLayers.js
25     for path in glob.glob('public/js/*.js'):
26         shutil.copy(path, tmpdir)
27
28     # build OpenLayers.js
29     subprocess.call(['python', 'buildUncompressed.py',
30                      pathjoin(os.getcwd(), "scripts/syj"), pathjoin(tmpdir, "OpenLayers.js")],
31                      cwd = 'public/openlayers/openlayers/build')
32
33     config = ConfigParser.ConfigParser()
34     os.makedirs(pathjoin(TARGET, 'public/js'))
35     config.readfp(open('application/configs/medias.ini'))
36     for key, value in config.items('production'):
37         if key.startswith('scripts.'):
38             outpath = pathjoin(TARGET, 'public/js/' + key[len('scripts.'):] + '.js')
39             with open(outpath, 'w') as output:
40                 for inpath in map(lambda p: pathjoin(tmpdir, p.strip() + '.js'), value.split(',')):
41                     with open(inpath) as f:
42                         output.write(f.read())
43             compress(outpath)
44     shutil.rmtree(tmpdir)
45
46 def genstyles():
47     directory = pathjoin(TARGET, 'public/css')
48     os.makedirs(directory)
49     for path in glob.glob('public/css/*.css'):
50         shutil.copy(path, directory)
51         compress(pathjoin(TARGET, 'public/css', os.path.basename(path)))
52
53 def genicons():
54     directory = pathjoin(TARGET, 'public/icons')
55     os.makedirs(directory)
56     for path in glob.glob('public/icons/*'):
57         shutil.copy(path, directory)
58
59 def genolmisc():
60     directory = pathjoin(TARGET, 'public/img')
61     os.makedirs(directory)
62     for path in glob.glob('public/js/img/*'):
63         shutil.copy(path, directory)
64
65 def tarbuild():
66     print "creating syj.tar.gz"
67     targz = tarfile.open("build/syj.tar.gz", "w:gz")
68     for path in ["application", "library", "public"]:
69         targz.add(pathjoin(TARGET, path))
70     targz.close()
71
72
73 def genlibrary():
74     directory = pathjoin(TARGET, 'library')
75     os.makedirs(directory)
76     for path in glob.glob('library/*.php'):
77         shutil.copy(path, directory)
78
79     directory = pathjoin(TARGET, 'library/Zend')
80     os.makedirs(directory)
81     for path in glob.glob('library/Zend/*'): # will not take .git
82         if (os.path.isdir(path)):
83             shutil.copytree(path, pathjoin(directory, os.path.basename(path)))
84         else:
85             shutil.copy(path, directory)
86
87 def genmedias():
88     genscripts()
89     genstyles()
90     genicons()
91     genolmisc()
92     genlibrary()
93     shutil.copytree('application', pathjoin(TARGET, 'application'))
94     shutil.copy('public/index.php', pathjoin(TARGET, 'public'))
95     tarbuild()
96
97 createdir()
98 genmedias()