5 import shutil, os, sys, subprocess, tempfile, tarfile, glob, ConfigParser
6 pathjoin = os.path.join
13 master = repo.commits()[0]
14 tag = (filter(lambda tag: tag.commit.id == master.id, repo.tags) or [""])[0]
18 version = subprocess.Popen(['git', 'tag', '-l', '--contains', 'master'], stdout=subprocess.PIPE).communicate()[0][:-1]
20 raise AssertionError, "master is not tagged"
22 fd, fname = tempfile.mkstemp()
23 f = os.fdopen(fd, 'w')
24 versionfile = 'build/application/Version.php'
25 with open('build/application/Version.php') as source:
27 f.write(line.replace('$SYJVERSION$', version))
29 shutil.move(fname, versionfile)
32 tmpout = tempfile.TemporaryFile()
33 subprocess.Popen(['yui-compressor', path], stdout=tmpout).communicate()
35 with open(path, 'w') as output:
36 output.write(tmpout.read())
39 tmpdir = tempfile.mkdtemp()
41 # copy scripts OpenLayers.js
42 for path in glob.glob('public/js/*.js'):
43 if os.path.islink(path):
44 shutil.copy(path, tmpdir)
46 # remove "use strict"; directive
47 with open(path) as inp:
48 dest = pathjoin(tmpdir, os.path.basename(path))
49 with open(dest, "w") as out:
52 if sline != '"use strict"' and sline != '"use strict";':
56 subprocess.call(['python', 'buildUncompressed.py',
57 pathjoin(os.getcwd(), "scripts/syj"), pathjoin(tmpdir, "OpenLayers.js")],
58 cwd = 'public/openlayers/openlayers/build')
60 config = ConfigParser.ConfigParser()
61 os.makedirs(pathjoin(__BUILD__, 'public/js'))
62 config.readfp(open('application/configs/medias.ini'))
63 for key, value in config.items('production'):
64 if key.startswith('scripts.'):
65 outpath = pathjoin(__BUILD__, 'public/js/' + key[len('scripts.'):] + '.js')
66 with open(outpath, 'w') as output:
67 for inpath in map(lambda p: pathjoin(tmpdir, p.strip() + '.js'), value.split(',')):
68 with open(inpath) as f:
69 output.write(f.read())
73 def install(source, target):
77 if os.path.isdir(source):
80 buildtarget = pathjoin(__BUILD__, target)
81 parentdir = os.path.normpath(pathjoin(buildtarget, '..'))
82 if not os.path.isdir(parentdir):
83 os.makedirs(parentdir)
84 shutil.copytree(source, buildtarget)
86 elif os.path.exists(source):
88 target = os.path.dirname(source)
89 buildtarget = os.path.normpath(pathjoin(__BUILD__, target))
90 if not os.path.isdir(buildtarget):
91 os.makedirs(buildtarget)
92 shutil.copy(source, buildtarget)
95 for item in glob.glob(source):
99 if os.path.isdir(__BUILD__):
100 shutil.rmtree(__BUILD__, False)
104 for path in glob.glob('public/css/*.css'):
106 compress(pathjoin(__BUILD__, 'public/css', os.path.basename(path)))
108 with open("scripts/syj.install") as f:
110 line = line.split('#')[0].strip()
114 parts = line.split(' ')
122 install(source, target)
126 print "creating syj.tar.gz"
127 targz = tarfile.open("build/syj.tar.gz", "w:gz")
128 for path in glob.glob(pathjoin(__BUILD__, '*')):