oxjs/tools/build/build.py

109 lines
4.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
#vim: et:ts=4:sw=4:sts=4
2011-08-09 17:00:39 +00:00
import base64
import json
2010-09-05 14:24:22 +00:00
import os
2011-04-22 22:03:10 +00:00
import re
2011-04-25 09:12:02 +00:00
import shutil
def copy_file(source, target):
print 'copying', source, 'to', target
write_file(target, read_file(source))
def read_file(file):
2011-04-25 09:12:02 +00:00
print 'reading', file
f = open(file)
data = f.read()
f.close()
return data
def write_file(file, data):
2011-04-25 09:12:02 +00:00
print 'writing', file
write_path(file)
f = open(file, 'w')
f.write(data)
f.close()
return len(data)
2011-04-22 22:03:10 +00:00
def write_link(source, target):
2011-04-25 09:12:02 +00:00
print 'linking', source, 'to', target
write_path(target)
2011-04-22 22:03:10 +00:00
if os.path.exists(target):
os.unlink(target)
os.symlink(source, target)
def write_path(file):
path = os.path.split(file)[0]
if path and not os.path.exists(path):
os.makedirs(path)
2011-04-25 11:19:01 +00:00
base_path = os.path.dirname(__file__)
if base_path:
os.chdir(base_path)
2011-04-22 22:03:10 +00:00
source_path = '../../source/'
build_path = '../../build/'
files = ['Ox.UI/css/Ox.UI.css']
# SVGs
path = source_path + 'Ox.UI/themes/classic/svg/'
for filename in os.listdir(path):
svg = read_file(path + filename)
2011-09-03 02:12:44 +00:00
svg = svg.replace('#000000', '#XXXXXX').replace('#404040', '#C0C0C0').replace('#FFFFFF', '#000000').replace('#XXXXXX', '#FFFFFF')
write_file(path.replace('/classic/', '/modern/') + filename, svg)
2011-04-23 11:04:37 +00:00
2011-08-09 17:00:39 +00:00
imageURLs = {}
imageDataURLs = {}
for theme in ['classic', 'modern']:
path = source_path + 'Ox.UI/themes/' + theme + '/svg/'
for filename in os.listdir(path):
if not filename[0] in '._':
key = theme + '/' + filename[:-4]
imageURLs[key] = os.path.join(path, filename).replace(source_path, '')
data = re.sub('\n\s+', '', read_file(path + filename))
imageDataURLs[key] = 'data:image/svg+xml;base64,' + base64.b64encode(data)
write_file(build_path + 'Ox.UI/json/Ox.UI.imageURLs.json', json.dumps(imageURLs, indent=4, sort_keys=True))
write_file(build_path + 'Ox.UI/json/Ox.UI.imageDataURLs.json', json.dumps(imageDataURLs, indent=4, sort_keys=True))
# symlinks
for path, dirnames, filenames in os.walk(source_path):
for filename in filenames:
if not '_' in path and not filename[0] in '._':
parts = os.path.join(path.replace(source_path, ''), filename).split('/')
for i, part in enumerate(parts):
if i < len(parts) - 1:
parts[i] = '..'
source = '/'.join(parts).replace(filename, os.path.join(path, filename))[3:]
is_jquery = re.compile('^jquery-[\d\.]+\.js$').findall(filename)
is_jquery_min = re.compile('^jquery-[\d\.]+\.min\.js$').findall(filename)
is_jquery_plugin = re.compile('^jquery\..*?\.js$').findall(filename)
if is_jquery:
target = os.path.join(path.replace(source_path, build_path), 'jquery.js')
elif is_jquery_min:
target = os.path.join(path.replace(source_path, build_path), 'jquery.min.js')
else:
target = os.path.join(path.replace(source_path, build_path), filename)
if is_jquery_plugin:
files.append(target.replace(build_path, ''))
write_link(source, target)
# Ox.UI
js = ''
section = ''
root = source_path + 'Ox.UI/'
for path, dirnames, filenames in os.walk(root):
2010-09-05 14:24:22 +00:00
for filename in filenames:
# theme css files get included by main css
if path != root and not '_' in path and not filename[0] in '._' and filename[-4:] != '.css' and filename[-4:] != '.svg' and filename[:7] != 'browser':
files.append(os.path.join(path.replace(source_path, ''), filename))
if filename[-3:] == '.js':
folder = os.path.split(path)[-1]
if section != folder:
section = folder
js += '/*\n' + '=' * 80 + '\n' + section + '\n' + '=' * 80 + '\n*/\n\n'
js += '/*\n' + '-' * 80 + '\n' + filename[:-3] + '\n' + '-' * 80 + '\n*/\n\n'
js += read_file(os.path.join(path, filename)) + '\n\n'
2010-09-05 14:24:22 +00:00
write_file(build_path + 'Ox.UI/js/Ox.UI.js', js)
files = json.dumps(sorted(files), indent=4, sort_keys=True)
2011-08-09 17:00:39 +00:00
write_file(build_path + 'Ox.UI/json/Ox.UI.files.json', files)