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()
34 subprocess.Popen(['yui-compressor', path], stdout=tmpout).communicate()
36 subprocess.Popen(['yuicompressor', path], stdout=tmpout).communicate()
38 with open(path, 'w') as output:
39 output.write(tmpout.read())
42 tmpdir = tempfile.mkdtemp()
44 # copy scripts OpenLayers.js
45 for path in glob.glob('public/js/*.js'):
46 if os.path.islink(path):
47 shutil.copy(path, tmpdir)
49 # remove "use strict"; directive
50 with open(path) as inp:
51 dest = pathjoin(tmpdir, os.path.basename(path))
52 with open(dest, "w") as out:
55 if sline != '"use strict"' and sline != '"use strict";':
59 subprocess.call(['python', 'buildUncompressed.py',
60 pathjoin(os.getcwd(), "scripts/syj"), pathjoin(tmpdir, "OpenLayers.js")],
61 cwd = 'public/openlayers/openlayers/build')
63 config = ConfigParser.ConfigParser()
64 os.makedirs(pathjoin(__BUILD__, 'public/js'))
65 config.readfp(open('application/configs/medias.ini'))
66 for key, value in config.items('production'):
67 if key.startswith('scripts.'):
68 outpath = pathjoin(__BUILD__, 'public/js/' + key[len('scripts.'):] + '.js')
69 with open(outpath, 'w') as output:
70 for inpath in map(lambda p: pathjoin(tmpdir, p.strip() + '.js'), value.split(',')):
71 with open(inpath) as f:
72 output.write(f.read())
76 def install(source, target):
80 if os.path.isdir(source):
83 buildtarget = pathjoin(__BUILD__, target)
84 parentdir = os.path.normpath(pathjoin(buildtarget, '..'))
85 if not os.path.isdir(parentdir):
86 os.makedirs(parentdir)
87 shutil.copytree(source, buildtarget)
89 elif os.path.exists(source):
91 target = os.path.dirname(source)
92 buildtarget = os.path.normpath(pathjoin(__BUILD__, target))
93 if not os.path.isdir(buildtarget):
94 os.makedirs(buildtarget)
95 shutil.copy(source, buildtarget)
99 for item in glob.glob(source):
101 install(item, target)
102 if not hascontent: # not a directory or a file or a list of files
103 raise Exception(("%s does not exist" % source))
106 if os.path.isdir(__BUILD__):
107 shutil.rmtree(__BUILD__, False)
111 for path in glob.glob('public/css/*.css'):
113 compress(pathjoin(__BUILD__, 'public/css', os.path.basename(path)))
115 with open("scripts/syj.install") as f:
117 line = line.split('#')[0].strip()
121 parts = line.split(' ')
129 install(source, target)
133 print "creating syj.tar.gz"
134 targz = tarfile.open("build/syj.tar.gz", "w:gz")
135 for path in glob.glob(pathjoin(__BUILD__, '*')):