2011-04-23 14:54:05 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#vim: et:ts=4:sw=4:sts=4
|
2011-04-19 09:09:51 +00:00
|
|
|
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))
|
2011-04-19 09:09:51 +00:00
|
|
|
|
|
|
|
def read_file(file):
|
2011-04-25 09:12:02 +00:00
|
|
|
print 'reading', file
|
2011-04-19 09:09:51 +00:00
|
|
|
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
|
2011-04-19 09:09:51 +00:00
|
|
|
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)
|
|
|
|
|
2011-04-19 09:09:51 +00:00
|
|
|
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-23 14:54:05 +00:00
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
source_path = '../../source/'
|
2011-04-19 09:09:51 +00:00
|
|
|
build_path = '../../build/'
|
2011-04-27 19:24:33 +00:00
|
|
|
files = ['Ox.UI/css/Ox.UI.css']
|
2011-04-19 09:09:51 +00:00
|
|
|
|
2011-04-27 19:24:33 +00:00
|
|
|
# SVGs
|
|
|
|
path = source_path + 'Ox.UI/themes/classic/svg/'
|
|
|
|
for filename in os.listdir(path):
|
|
|
|
svg = read_file(path + filename)
|
|
|
|
svg = svg.replace('#404040', '#FFFFFF').replace('#000000', '#FFFFFF')
|
|
|
|
write_file(path.replace('/classic/', '/modern/') + filename, svg)
|
2011-04-23 11:04:37 +00:00
|
|
|
|
2011-04-27 19:24:33 +00:00
|
|
|
# symlinks
|
|
|
|
for path, dirnames, filenames in os.walk(source_path):
|
2011-04-19 09:09:51 +00:00
|
|
|
for filename in filenames:
|
2011-04-27 19:24:33 +00:00
|
|
|
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)
|
2011-04-19 09:09:51 +00:00
|
|
|
|
2011-04-27 19:24:33 +00:00
|
|
|
# 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:
|
2011-04-27 19:24:33 +00:00
|
|
|
# theme css files get included by main css
|
|
|
|
if path != root and not '_' in path and not filename[0] in '._' and filename[-4:] != '.css':
|
|
|
|
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
|
|
|
|
2011-04-27 19:24:33 +00:00
|
|
|
write_file(build_path + 'Ox.UI/js/Ox.UI.js', js)
|
|
|
|
files = json.dumps(sorted(files), indent=4, sort_keys=True)
|
|
|
|
write_file(build_path + 'Ox.UI/json/Ox.UI.json', files)
|