5 import shutil, os, sys, subprocess, tempfile, tarfile, glob, ConfigParser
6 pathjoin = os.path.join
12 master = repo.commits()[0]
13 tag = (filter(lambda tag: tag.commit.id == master.id, repo.tags) or [""])[0]
17 version = subprocess.Popen(['git', 'tag', '-l', '--contains', 'master'], stdout=subprocess.PIPE).communicate()[0][:-1]
19 raise AssertionError, "master is not tagged"
21 fd, fname = tempfile.mkstemp()
22 f = os.fdopen(fd, 'w')
23 versionfile = 'build/application/Version.php'
24 with open('build/application/Version.php') as source:
26 f.write(line.replace('$SYJVERSION$', version))
28 shutil.move(fname, versionfile)
31 tmpout = tempfile.TemporaryFile()
32 subprocess.Popen(['yui-compressor', path], stdout=tmpout).communicate()
34 with open(path, 'w') as output:
35 output.write(tmpout.read())
38 tmpdir = tempfile.mkdtemp()
40 # copy scripts OpenLayers.js
41 for path in glob.glob('public/js/*.js'):
42 shutil.copy(path, tmpdir)
45 subprocess.call(['python', 'buildUncompressed.py',
46 pathjoin(os.getcwd(), "scripts/syj"), pathjoin(tmpdir, "OpenLayers.js")],
47 cwd = 'public/openlayers/openlayers/build')
49 config = ConfigParser.ConfigParser()
50 os.makedirs(pathjoin(__BUILD__, 'public/js'))
51 config.readfp(open('application/configs/medias.ini'))
52 for key, value in config.items('production'):
53 if key.startswith('scripts.'):
54 outpath = pathjoin(__BUILD__, 'public/js/' + key[len('scripts.'):] + '.js')
55 with open(outpath, 'w') as output:
56 for inpath in map(lambda p: pathjoin(tmpdir, p.strip() + '.js'), value.split(',')):
57 with open(inpath) as f:
58 output.write(f.read())
62 def install(source, target):
66 if os.path.isdir(source):
69 buildtarget = pathjoin(__BUILD__, target)
70 parentdir = os.path.normpath(pathjoin(buildtarget, '..'))
71 if not os.path.isdir(parentdir):
72 os.makedirs(parentdir)
73 shutil.copytree(source, buildtarget)
75 elif os.path.exists(source):
77 target = os.path.dirname(source)
78 buildtarget = os.path.normpath(pathjoin(__BUILD__, target))
79 if not os.path.isdir(buildtarget):
80 os.makedirs(buildtarget)
81 shutil.copy(source, buildtarget)
84 for item in glob.glob(source):
88 if os.path.isdir(__BUILD__):
89 shutil.rmtree(__BUILD__, False)
93 for path in glob.glob('public/css/*.css'):
95 compress(pathjoin(__BUILD__, 'public/css', os.path.basename(path)))
97 with open("scripts/syj.install") as f:
99 line = line.split('#')[0].strip()
103 parts = line.split(' ')
111 install(source, target)
115 print "creating syj.tar.gz"
116 targz = tarfile.open("build/syj.tar.gz", "w:gz")
117 for path in glob.glob(pathjoin(__BUILD__, '*')):