5 import shutil, os, sys, subprocess, tempfile, tarfile, glob, ConfigParser
6 pathjoin = os.path.join
9 if os.path.isdir(TARGET):
10 shutil.rmtree(TARGET, False)
14 print ("compressing " + path)
15 tmpout = tempfile.TemporaryFile()
16 subprocess.Popen(['yui-compressor', path], stdout=tmpout).communicate()
18 with open(path, 'w') as output:
19 output.write(tmpout.read())
22 tmpdir = tempfile.mkdtemp()
24 # copy scripts OpenLayers.js
25 for path in glob.glob('public/js/*.js'):
26 shutil.copy(path, tmpdir)
29 subprocess.call(['python', 'buildUncompressed.py',
30 pathjoin(os.getcwd(), "scripts/syj"), pathjoin(tmpdir, "OpenLayers.js")],
31 cwd = 'public/openlayers/openlayers/build')
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())
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)))
54 directory = pathjoin(TARGET, 'public/icons')
55 os.makedirs(directory)
56 for path in glob.glob('public/icons/*'):
57 shutil.copy(path, directory)
60 directory = pathjoin(TARGET, 'public/img')
61 os.makedirs(directory)
62 for path in glob.glob('public/js/img/*'):
63 shutil.copy(path, directory)
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))
74 directory = pathjoin(TARGET, 'library')
75 os.makedirs(directory)
76 for path in glob.glob('library/*.php'):
77 shutil.copy(path, directory)
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)))
85 shutil.copy(path, directory)
93 shutil.copytree('application', pathjoin(TARGET, 'application'))
94 shutil.copy('public/index.php', pathjoin(TARGET, 'public'))