1
0
Fork 0
forked from 0x2620/oxjs

Ox.load(), and adding moved files

This commit is contained in:
rolux 2011-04-25 11:12:02 +02:00
commit 6cfb6b7647
594 changed files with 1381 additions and 19555 deletions

View file

@ -3,16 +3,28 @@
import json
import os
import re
import shutil
def append_file(file):
split = file.split('/')[1].split('.')
module = '.'.join([split[0], split[1]])
if not module in files:
files[module] = []
files[module].append(file)
def copy_file(source, target):
print 'copying', source, 'to', target
write_file(target, read_file(source))
def read_file(file):
#print 'reading', file
print 'reading', file
f = open(file)
data = f.read()
f.close()
return data
def write_file(file, data):
#print 'writing', file
print 'writing', file
write_path(file)
f = open(file, 'w')
f.write(data)
@ -20,6 +32,8 @@ def write_file(file, data):
return len(data)
def write_link(source, target):
print 'linking', source, 'to', target
write_path(target)
if os.path.exists(target):
os.unlink(target)
os.symlink(source, target)
@ -29,49 +43,73 @@ def write_path(file):
if path and not os.path.exists(path):
os.makedirs(path)
os.chdir(os.path.dirname(__file__))
# doesn't work here
# os.chdir(os.path.dirname(__file__))
source_path = '../../source/'
build_path = '../../build/'
files = {}
# SVG
# css
for path, dirnames, filenames in os.walk(source_path + 'css/'):
for filename in filenames:
source = os.path.join(path, filename)
target = source.replace(source_path, build_path)
copy_file(source, target)
append_file(target.replace(build_path, ''))
path = '../../source/svg/symbols/'
for dirname, dirnames, filenames in os.walk(path):
# js
filename = 'js/Ox.js'
write_link(source_path + filename, build_path + filename)
root = source_path + 'js/'
for path, dirnames, filenames in os.walk(root):
for dirname in dirnames:
if dirname[0] != '_':
if path == root and dirname != 'jquery':
source = os.path.join(path, dirname)
target = source.replace(source_path, build_path)
write_link(source, target)
for filename in filenames:
if filename[0] != '.' and filename[0] != '_':
svg = read_file(path + filename)
new_filename = 'symbol' + filename[0].upper() + filename[1:]
write_file(build_path + 'svg/ox.ui.classic/' + new_filename, svg)
write_file(build_path + 'svg/ox.ui.modern/' + new_filename, svg.replace('#404040', '#FFFFFF').replace('#000000', '#FFFFFF'))
if 'jquery' in path:
is_jquery = re.compile('jquery-[\d\.]+\.js').findall(filename)
is_jquery_min = re.compile('jquery-[\d\.]+\.min\.js').findall(filename)
source = os.path.join(path, 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 = source.replace(source_path, build_path)
copy_file(source, target)
if not is_jquery and not is_jquery_min:
files['Ox.UI'].append(target.replace(build_path, ''))
elif path != root and not '_' in path:
append_file(os.path.join(path, filename).replace(source_path, ''))
# JSON
files = []
for dirname, dirnames, filenames in os.walk(source_path + 'js/'):
# png
for path, dirnames, filenames in os.walk(source_path + 'png/'):
for filename in filenames:
if filename[:1] != '.':
jquery = re.compile('jquery-[\d\.]+\.js').findall(filename)
if jquery or filename in ['Ox.js', 'OxUI.js']:
target = 'jquery.js' if jquery else filename
write_link(os.path.join(dirname, filename), build_path + 'js/' + target)
elif not '_' in dirname and not filename.endswith('.min.js'):
files.append(os.path.join(dirname.replace(source_path , '../source/'), filename))
source = os.path.join(path, filename)
target = source.replace(source_path, build_path)
copy_file(source, target)
append_file(target.replace(build_path, ''))
for dirname, dirnames, filenames in os.walk(source_path + 'css'):
# svg
for path, dirnames, filenames in os.walk(source_path + 'svg/'):
for filename in filenames:
if filename[:1] != '.':
write_link(os.path.join(dirname, filename), build_path + 'css/' + filename)
if filename[0] != '.' and filename[0] != '_':
source = os.path.join(path, filename)
target = source.replace(source_path, build_path)
copy_file(source, target)
append_file(target.replace(build_path, ''))
if 'Ox.UI.classic' in source:
svg = read_file(source).replace('#404040', '#FFFFFF').replace('#000000', '#FFFFFF')
target = target.replace('Ox.UI.classic', 'Ox.UI.modern')
write_file(target, svg)
append_file(target.replace(build_path, ''))
for dirname, dirnames, filenames in os.walk(build_path + 'png'):
for filename in filenames:
if filename[:1] != '.':
files.append(os.path.join(dirname.replace(build_path, ''), filename))
for dirname, dirnames, filenames in os.walk(build_path + 'svg'):
for filename in filenames:
if filename[:1] != '.':
files.append(os.path.join(dirname.replace(build_path, ''), filename))
write_file(build_path + 'json/OxUI.json', json.dumps(files, indent=4, sort_keys=True))
for module in files:
file = build_path + 'json/' + module + '.json'
write_file(file, json.dumps(sorted(files[module]), indent=4, sort_keys=True))