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:
@ -27,7 +28,7 @@ def build_oxjs(geo):
stdout=subprocess.PIPE stdout=subprocess.PIPE
).communicate()[0].strip() ).communicate()[0].strip()
year = time.strftime('%Y', time.gmtime()) 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 # SVGs
path = source_path + 'Ox.UI/themes/classic/svg/' path = source_path + 'Ox.UI/themes/classic/svg/'
@ -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)