build.py python 2/3 compatible
This commit is contained in:
parent
2ba2903dbc
commit
1ef2f4e0d3
1 changed files with 27 additions and 23 deletions
|
@ -17,14 +17,14 @@ def get_version():
|
||||||
if os.path.exists('../../.git'):
|
if os.path.exists('../../.git'):
|
||||||
revision = subprocess.Popen(
|
revision = subprocess.Popen(
|
||||||
['git', 'rev-list', 'HEAD', '--count'], stdout=subprocess.PIPE
|
['git', 'rev-list', 'HEAD', '--count'], stdout=subprocess.PIPE
|
||||||
).communicate()[0].strip()
|
).communicate()[0].strip().decode('utf-8')
|
||||||
print(revision)
|
print(revision)
|
||||||
revision = int(revision) - 94
|
revision = int(revision) - 94
|
||||||
print(revision)
|
print(revision)
|
||||||
else:
|
else:
|
||||||
revision = subprocess.Popen(
|
revision = subprocess.Popen(
|
||||||
['bzr', 'revno'], stdout=subprocess.PIPE
|
['bzr', 'revno'], stdout=subprocess.PIPE
|
||||||
).communicate()[0].strip()
|
).communicate()[0].strip().decode('utf-8')
|
||||||
return '0.1.%s' % revision
|
return '0.1.%s' % revision
|
||||||
|
|
||||||
def build_oxjs(downloads=False, geo=False):
|
def build_oxjs(downloads=False, geo=False):
|
||||||
|
@ -62,7 +62,7 @@ def build_oxjs(downloads=False, geo=False):
|
||||||
theme_data[theme]['themeClass'] = 'OxTheme' + theme[0].upper() + theme[1:]
|
theme_data[theme]['themeClass'] = 'OxTheme' + theme[0].upper() + theme[1:]
|
||||||
|
|
||||||
# Ox.UI CSS
|
# Ox.UI CSS
|
||||||
css = read_file(source_path + 'UI/css/UI.css')
|
css = read_text(source_path + 'UI/css/UI.css')
|
||||||
css = css.replace('$import', '\n'.join([
|
css = css.replace('$import', '\n'.join([
|
||||||
'@import url("../themes/%s/css/theme.css?%s");' % (theme, version) for theme in themes
|
'@import url("../themes/%s/css/theme.css?%s");' % (theme, version) for theme in themes
|
||||||
]))
|
]))
|
||||||
|
@ -70,7 +70,7 @@ def build_oxjs(downloads=False, geo=False):
|
||||||
write_file('%sUI/css/UI.css' % min_path, css)
|
write_file('%sUI/css/UI.css' % min_path, css)
|
||||||
|
|
||||||
# Ox.UI Theme CSS
|
# Ox.UI Theme CSS
|
||||||
css = read_file(source_path + 'UI/css/theme.css')
|
css = read_text(source_path + 'UI/css/theme.css')
|
||||||
for theme in themes:
|
for theme in themes:
|
||||||
theme_css = parse_css(css, theme_data[theme])
|
theme_css = parse_css(css, theme_data[theme])
|
||||||
theme_css = theme_css.replace('.png)', '.png?%s)' % version)
|
theme_css = theme_css.replace('.png)', '.png?%s)' % version)
|
||||||
|
@ -81,7 +81,7 @@ def build_oxjs(downloads=False, geo=False):
|
||||||
ui_images = {}
|
ui_images = {}
|
||||||
path = source_path + 'UI/svg/'
|
path = source_path + 'UI/svg/'
|
||||||
for filename in [filename for filename in os.listdir(path) if not filename[0] in '._']:
|
for filename in [filename for filename in os.listdir(path) if not filename[0] in '._']:
|
||||||
svg = read_file(path + filename)
|
svg = read_text(path + filename)
|
||||||
svg = re.sub('\n\s*', '', svg)
|
svg = re.sub('\n\s*', '', svg)
|
||||||
svg = re.sub('<!--.+?-->', '', svg)
|
svg = re.sub('<!--.+?-->', '', svg)
|
||||||
# temporary fix for Chrome SVG bug, remove later!
|
# temporary fix for Chrome SVG bug, remove later!
|
||||||
|
@ -118,7 +118,8 @@ def build_oxjs(downloads=False, geo=False):
|
||||||
ui_files['min'].append(target.replace(min_path, ''))
|
ui_files['min'].append(target.replace(min_path, ''))
|
||||||
if not '/Ox/js/' in source and not '/UI/js/' in source and not is_jquery:
|
if not '/Ox/js/' in source and not '/UI/js/' in source and not is_jquery:
|
||||||
if re.match('^Ox\..+\.js$', filename) or is_jsonc:
|
if re.match('^Ox\..+\.js$', filename) or is_jsonc:
|
||||||
js = read_file(source)
|
js = read_text(source)
|
||||||
|
print('minifiy and write', filename, target)
|
||||||
write_file(target, ox.js.minify(js, '' if is_jsonc else comment))
|
write_file(target, ox.js.minify(js, '' if is_jsonc else comment))
|
||||||
else:
|
else:
|
||||||
copy_file(source, target)
|
copy_file(source, target)
|
||||||
|
@ -181,7 +182,7 @@ def build_oxjs(downloads=False, geo=False):
|
||||||
and not filename.endswith('~'):
|
and not filename.endswith('~'):
|
||||||
filenames.append(filename)
|
filenames.append(filename)
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
js += read_file(source_path + js_dir + filename) + '\n'
|
js += read_text(source_path + js_dir + filename) + '\n'
|
||||||
if not js_dir + filename in sum(ox_files, []):
|
if not js_dir + filename in sum(ox_files, []):
|
||||||
ox_files[-1].append(js_dir + filename)
|
ox_files[-1].append(js_dir + filename)
|
||||||
js = re.sub(
|
js = re.sub(
|
||||||
|
@ -222,9 +223,10 @@ def build_oxjs(downloads=False, geo=False):
|
||||||
if not '/js/' in path:
|
if not '/js/' in path:
|
||||||
ui_files['min'].append(os.path.join(path.replace(source_path, ''), filename))
|
ui_files['min'].append(os.path.join(path.replace(source_path, ''), filename))
|
||||||
if filename.endswith('.js'):
|
if filename.endswith('.js'):
|
||||||
js += read_file(os.path.join(path, filename)) + '\n'
|
js += read_text(os.path.join(path, filename)) + '\n'
|
||||||
filename = min_path + 'UI/js/UI.js'
|
filename = min_path + 'UI/js/UI.js'
|
||||||
write_file(filename, ox.js.minify(js, comment))
|
write_file(filename, ox.js.minify(js, comment))
|
||||||
|
|
||||||
ui_files['min'].append(filename.replace(min_path, ''))
|
ui_files['min'].append(filename.replace(min_path, ''))
|
||||||
write_file(min_path + 'UI/json/UI.json', json.dumps({
|
write_file(min_path + 'UI/json/UI.json', json.dumps({
|
||||||
'files': sorted(ui_files['min']),
|
'files': sorted(ui_files['min']),
|
||||||
|
@ -239,27 +241,24 @@ def build_oxjs(downloads=False, geo=False):
|
||||||
# index
|
# index
|
||||||
data = {
|
data = {
|
||||||
# sum(list, []) is flatten
|
# sum(list, []) is flatten
|
||||||
'documentation': sorted(sum(ox_files, [])) + sorted(filter(
|
'documentation': sorted(sum(ox_files, [])) + sorted(list(filter(
|
||||||
lambda x: re.search('\.js$', x),
|
lambda x: re.search('\.js$', x),
|
||||||
ui_files['dev']
|
ui_files['dev']
|
||||||
) + map(
|
)) + ['%s/%s.js' % (x, x) for x in ['Geo', 'Image', 'Unicode']]),
|
||||||
lambda x: '%s/%s.js' % (x, x),
|
|
||||||
['Geo', 'Image', 'Unicode']
|
|
||||||
)),
|
|
||||||
'examples': sorted(sum(map(
|
'examples': sorted(sum(map(
|
||||||
lambda x: filter(
|
lambda x: list(filter(
|
||||||
lambda x: not re.search('/[._]', x),
|
lambda x: not re.search('/[._]', x),
|
||||||
map(
|
map(
|
||||||
lambda y: x + '/' + y,
|
lambda y: x + '/' + y,
|
||||||
os.listdir(root_path + 'examples/' + x)
|
os.listdir(root_path + 'examples/' + x)
|
||||||
)
|
)
|
||||||
),
|
)),
|
||||||
filter(
|
list(filter(
|
||||||
lambda x: not re.search('^[._]', x),
|
lambda x: not re.search('^[._]', x),
|
||||||
os.listdir(root_path + 'examples/')
|
os.listdir(root_path + 'examples/')
|
||||||
)
|
))
|
||||||
), [])),
|
), [])),
|
||||||
'readme': map(
|
'readme': list(map(
|
||||||
lambda x: {
|
lambda x: {
|
||||||
'date': time.strftime(
|
'date': time.strftime(
|
||||||
'%Y-%m-%dT%H:%M:%SZ',
|
'%Y-%m-%dT%H:%M:%SZ',
|
||||||
|
@ -272,7 +271,7 @@ def build_oxjs(downloads=False, geo=False):
|
||||||
lambda x: not re.search('^[._]', x) and re.search('\.html$', x),
|
lambda x: not re.search('^[._]', x) and re.search('\.html$', x),
|
||||||
os.listdir(root_path + 'readme/')
|
os.listdir(root_path + 'readme/')
|
||||||
)
|
)
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
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))
|
||||||
|
|
||||||
|
@ -332,7 +331,7 @@ def format_hex(rgb):
|
||||||
return '#%s' % ''.join([hex(c)[-2:].replace('x', '0').upper() for c in rgb])
|
return '#%s' % ''.join([hex(c)[-2:].replace('x', '0').upper() for c in rgb])
|
||||||
|
|
||||||
def get_title(file):
|
def get_title(file):
|
||||||
match = re.search('<h1>(.+)</h1>', read_file(file))
|
match = re.search('<h1>(.+)</h1>', read_text(file))
|
||||||
return match.groups()[0] if match else 'Untitled'
|
return match.groups()[0] if match else 'Untitled'
|
||||||
|
|
||||||
def parse_css(css, values):
|
def parse_css(css, values):
|
||||||
|
@ -356,18 +355,23 @@ def parse_css(css, values):
|
||||||
|
|
||||||
def read_file(file):
|
def read_file(file):
|
||||||
print('reading', file)
|
print('reading', file)
|
||||||
f = open(file)
|
f = open(file, 'rb')
|
||||||
data = f.read()
|
data = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def read_text(file):
|
||||||
|
return read_file(file).decode('utf-8')
|
||||||
|
|
||||||
def read_jsonc(file):
|
def read_jsonc(file):
|
||||||
return ox.jsonc.loads(read_file(file))
|
return ox.jsonc.loads(read_text(file))
|
||||||
|
|
||||||
def write_file(file, data):
|
def write_file(file, data):
|
||||||
print('writing', file)
|
print('writing', file)
|
||||||
write_path(file)
|
write_path(file)
|
||||||
f = open(file, 'w')
|
if not isinstance(data, bytes):
|
||||||
|
data = data.encode('utf-8')
|
||||||
|
f = open(file, 'wb')
|
||||||
f.write(data)
|
f.write(data)
|
||||||
f.close()
|
f.close()
|
||||||
return len(data)
|
return len(data)
|
||||||
|
|
Loading…
Reference in a new issue