make build.py write tar.gz files

This commit is contained in:
rolux 2012-04-05 22:42:35 +02:00
parent 8c3ef648ab
commit adb51d67a1

View file

@ -9,9 +9,10 @@ import re
import shutil import shutil
import subprocess import subprocess
import sys import sys
import tarfile
import time import time
def build_oxjs(geo): def build_oxjs(downloads=False, geo=False):
base_path = os.path.dirname(__file__) base_path = os.path.dirname(__file__)
if base_path: if base_path:
@ -144,14 +145,14 @@ def build_oxjs(geo):
data = { data = {
# sum(list, []) is flatten # sum(list, []) is flatten
'documentation': sorted(sum(ox_files, [])) + sorted(filter( 'documentation': sorted(sum(ox_files, [])) + sorted(filter(
lambda x: re.match('.+\.js$', x), lambda x: re.search('\.js$', x),
ui_files['dev'] ui_files['dev']
) + map( ) + map(
lambda x: 'Ox.%s/Ox.%s.js' % (x, x), lambda x: 'Ox.%s/Ox.%s.js' % (x, x),
['Geo', 'Image', 'Unicode'] ['Geo', 'Image', 'Unicode']
)), )),
'examples': filter( 'examples': filter(
lambda x: not re.match('^\.', x), lambda x: not re.search('^\.', x),
os.listdir(root_path + 'examples/') os.listdir(root_path + 'examples/')
), ),
'readme': map( 'readme': map(
@ -163,18 +164,49 @@ def build_oxjs(geo):
'name': x.split('.')[0] 'name': x.split('.')[0]
}, },
filter( filter(
lambda x: not re.match('^[\._]', x), lambda x: not re.search('^[\._]', x),
os.listdir(root_path + 'readme/html/') os.listdir(root_path + 'readme/html/')
) )
) ),
'version': version
} }
write_file(root_path + 'index.json', json.dumps(data, indent=4, sort_keys=True)) write_file(root_path + 'index.json', json.dumps(data, indent=4, sort_keys=True))
# downloads
if downloads:
# source
download_path = root_path + 'downloads/'
source_file = 'OxJS.%s.source.tar.gz' % version
source_tar = tarfile.open(download_path + source_file, 'w:gz')
source_tar.add(root_path, arcname='OxJS', filter=filter_source)
source_tar.close()
write_link(source_file, root_path + 'downloads/OxJS.latest.source.tar.gz')
# build
build_file = 'OxJS.%s.build.tar.gz' % version
build_tar = tarfile.open(download_path + build_file, 'w:gz')
build_tar.add(root_path, arcname='OxJS', filter=filter_build)
build_tar.close()
write_link(build_file, root_path + 'downloads/OxJS.latest.build.tar.gz')
def copy_file(source, target): def copy_file(source, target):
print 'copying', source, 'to', target print 'copying', source, 'to', target
write_file(target, read_file(source)) write_file(target, read_file(source))
def filter_build(tarinfo):
if tarinfo.name == 'OxJS':
return tarinfo
if re.search('^OxJS/build', tarinfo.name):
return tarinfo
return None
def filter_source(tarinfo):
if re.search('^OxJS/(demos|downloads/|tools/geo/png/icons/)', tarinfo.name):
return None
if re.search('/[\._]', tarinfo.name):
return None
return tarinfo
def read_file(file): def read_file(file):
print 'reading', file print 'reading', file
f = open(file) f = open(file)
@ -204,5 +236,4 @@ def write_path(file):
if __name__ == '__main__': if __name__ == '__main__':
geo = False if sys.argv[-1] == '-nogeo' else True build_oxjs(downloads='-downloads' in sys.argv, geo=not '-nogeo' in sys.argv)
build_oxjs(geo)