diff --git a/tools/build/build.py b/tools/build/build.py index f32b72c9..0cc8531b 100755 --- a/tools/build/build.py +++ b/tools/build/build.py @@ -9,9 +9,10 @@ import re import shutil import subprocess import sys +import tarfile import time -def build_oxjs(geo): +def build_oxjs(downloads=False, geo=False): base_path = os.path.dirname(__file__) if base_path: @@ -27,7 +28,7 @@ def build_oxjs(geo): stdout=subprocess.PIPE ).communicate()[0].strip() year = time.strftime('%Y', time.gmtime()) - comment = 'OxJS %s (c) %s 0x2620, dual-licensed GPL/MIT, see https://oxjs.org for details' % (version, year) + comment = ' OxJS %s (c) %s 0x2620, dual-licensed GPL/MIT, see https://oxjs.org for details ' % (version, year) # SVGs path = source_path + 'Ox.UI/themes/classic/svg/' @@ -144,14 +145,14 @@ def build_oxjs(geo): data = { # sum(list, []) is flatten 'documentation': sorted(sum(ox_files, [])) + sorted(filter( - lambda x: re.match('.+\.js$', x), + lambda x: re.search('\.js$', x), ui_files['dev'] ) + map( lambda x: 'Ox.%s/Ox.%s.js' % (x, x), ['Geo', 'Image', 'Unicode'] )), 'examples': filter( - lambda x: not re.match('^\.', x), + lambda x: not re.search('^\.', x), os.listdir(root_path + 'examples/') ), 'readme': map( @@ -163,18 +164,49 @@ def build_oxjs(geo): 'name': x.split('.')[0] }, filter( - lambda x: not re.match('^[\._]', x), + lambda x: not re.search('^[\._]', x), os.listdir(root_path + 'readme/html/') ) - ) + ), + 'version': version } 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): print 'copying', source, 'to', target 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): print 'reading', file f = open(file) @@ -204,5 +236,4 @@ def write_path(file): if __name__ == '__main__': - geo = False if sys.argv[-1] == '-nogeo' else True - build_oxjs(geo) + build_oxjs(downloads='-downloads' in sys.argv, geo=not '-nogeo' in sys.argv)