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 shutil.copy(path, tmpdir)
46 subprocess.call(['python', 'buildUncompressed.py',
47 pathjoin(os.getcwd(), "scripts/syj"), pathjoin(tmpdir, "OpenLayers.js")],
48 cwd = 'public/openlayers/openlayers/build')
50 config = ConfigParser.ConfigParser()
51 os.makedirs(pathjoin(__BUILD__, 'public/js'))
52 config.readfp(open('application/configs/medias.ini'))
53 for key, value in config.items('production'):
54 if key.startswith('scripts.'):
55 outpath = pathjoin(__BUILD__, 'public/js/' + key[len('scripts.'):] + '.js')
56 with open(outpath, 'w') as output:
57 for inpath in map(lambda p: pathjoin(tmpdir, p.strip() + '.js'), value.split(',')):
58 with open(inpath) as f:
59 output.write(f.read())
63 def install(source, target):
67 if os.path.isdir(source):
70 buildtarget = pathjoin(__BUILD__, target)
71 parentdir = os.path.normpath(pathjoin(buildtarget, '..'))
72 if not os.path.isdir(parentdir):
73 os.makedirs(parentdir)
74 shutil.copytree(source, buildtarget)
76 elif os.path.exists(source):
78 target = os.path.dirname(source)
79 buildtarget = os.path.normpath(pathjoin(__BUILD__, target))
80 if not os.path.isdir(buildtarget):
81 os.makedirs(buildtarget)
82 shutil.copy(source, buildtarget)
85 for item in glob.glob(source):
89 if os.path.isdir(__BUILD__):
90 shutil.rmtree(__BUILD__, False)
94 for path in glob.glob('public/css/*.css'):
96 compress(pathjoin(__BUILD__, 'public/css', os.path.basename(path)))
98 with open("scripts/syj.install") as f:
100 line = line.split('#')[0].strip()
104 parts = line.split(' ')
112 install(source, target)
116 print "creating syj.tar.gz"
117 targz = tarfile.open("build/syj.tar.gz", "w:gz")
118 for path in glob.glob(pathjoin(__BUILD__, '*')):