Make build.py call tasks/build-examples.js
This commit is contained in:
@@ -1,5 +1,2 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
/build/
|
/build/
|
||||||
/examples/*.html.png
|
|
||||||
/examples/example-list.js
|
|
||||||
/examples/example-list.xml
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,269 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import time
|
|
||||||
from xml.dom.minidom import Document
|
|
||||||
|
|
||||||
try:
|
|
||||||
import xml.etree.ElementTree as ElementTree
|
|
||||||
except ImportError:
|
|
||||||
try:
|
|
||||||
import cElementTree as ElementTree # NOQA
|
|
||||||
except ImportError:
|
|
||||||
try:
|
|
||||||
import elementtree.ElementTree as ElementTree # NOQA
|
|
||||||
except ImportError:
|
|
||||||
import lxml.etree as ElementTree # NOQA
|
|
||||||
|
|
||||||
missing_deps = False
|
|
||||||
try:
|
|
||||||
import json
|
|
||||||
except ImportError:
|
|
||||||
try:
|
|
||||||
import simplejson as json # NOQA
|
|
||||||
except ImportError, E:
|
|
||||||
missing_deps = E
|
|
||||||
|
|
||||||
try:
|
|
||||||
from BeautifulSoup import BeautifulSoup
|
|
||||||
except ImportError, E:
|
|
||||||
missing_deps = E
|
|
||||||
|
|
||||||
feedName = "example-list.xml"
|
|
||||||
feedPath = "http://openlayers.github.io/ol3/master/examples/"
|
|
||||||
|
|
||||||
|
|
||||||
def getListOfExamples(relPath):
|
|
||||||
"""
|
|
||||||
returns list of .html filenames within a given path - excludes
|
|
||||||
index.html
|
|
||||||
"""
|
|
||||||
examples = os.listdir(relPath)
|
|
||||||
examples = [example for example in examples if
|
|
||||||
example.endswith('.html') and example != "index.html"]
|
|
||||||
return examples
|
|
||||||
|
|
||||||
|
|
||||||
def getExampleHtml(path):
|
|
||||||
"""
|
|
||||||
returns html of a specific example
|
|
||||||
"""
|
|
||||||
print '.',
|
|
||||||
f = open(path)
|
|
||||||
html = f.read()
|
|
||||||
f.close()
|
|
||||||
return html
|
|
||||||
|
|
||||||
|
|
||||||
def extractById(soup, tagId, value=None):
|
|
||||||
"""
|
|
||||||
returns full contents of a particular tag id
|
|
||||||
"""
|
|
||||||
beautifulTag = soup.find(id=tagId)
|
|
||||||
if beautifulTag:
|
|
||||||
if beautifulTag.contents:
|
|
||||||
value = str(beautifulTag.renderContents()).strip()
|
|
||||||
value = value.replace('\t', '')
|
|
||||||
value = value.replace('\n', '')
|
|
||||||
return value
|
|
||||||
|
|
||||||
|
|
||||||
def getRelatedClasses(html):
|
|
||||||
"""
|
|
||||||
parses the html, and returns a list of all OpenLayers Classes
|
|
||||||
used within (ie what parts of OL the javascript uses).
|
|
||||||
"""
|
|
||||||
rawstr = r'''(?P<class>ol\..*?)\('''
|
|
||||||
return re.findall(rawstr, html)
|
|
||||||
|
|
||||||
|
|
||||||
def parseHtml(html, ids):
|
|
||||||
"""
|
|
||||||
returns dictionary of items of interest
|
|
||||||
"""
|
|
||||||
soup = BeautifulSoup(html)
|
|
||||||
d = {}
|
|
||||||
for tagId in ids:
|
|
||||||
d[tagId] = extractById(soup, tagId)
|
|
||||||
#classes should eventually be parsed from docs - not automatically created.
|
|
||||||
classes = getRelatedClasses(html)
|
|
||||||
d['classes'] = classes
|
|
||||||
return d
|
|
||||||
|
|
||||||
|
|
||||||
def getGitInfo(exampleDir, exampleName):
|
|
||||||
orig = os.getcwd()
|
|
||||||
os.chdir(exampleDir)
|
|
||||||
h = os.popen("git log -n 1 --pretty=format:'%an|%ai' " + exampleName)
|
|
||||||
os.chdir(orig)
|
|
||||||
log = h.read()
|
|
||||||
h.close()
|
|
||||||
d = {}
|
|
||||||
if log:
|
|
||||||
parts = log.split("|")
|
|
||||||
d["author"] = parts[0]
|
|
||||||
# compensate for spaces in git log time
|
|
||||||
td = parts[1].split(" ")
|
|
||||||
td.insert(1, "T")
|
|
||||||
d["date"] = "".join(td)
|
|
||||||
else:
|
|
||||||
d["author"] = ""
|
|
||||||
d["date"] = ""
|
|
||||||
return d
|
|
||||||
|
|
||||||
|
|
||||||
def createFeed(examples):
|
|
||||||
doc = Document()
|
|
||||||
atomuri = "http://www.w3.org/2005/Atom"
|
|
||||||
feed = doc.createElementNS(atomuri, "feed")
|
|
||||||
feed.setAttribute("xmlns", atomuri)
|
|
||||||
title = doc.createElementNS(atomuri, "title")
|
|
||||||
title.appendChild(doc.createTextNode("OpenLayers Examples"))
|
|
||||||
feed.appendChild(title)
|
|
||||||
link = doc.createElementNS(atomuri, "link")
|
|
||||||
link.setAttribute("rel", "self")
|
|
||||||
link.setAttribute("href", feedPath + feedName)
|
|
||||||
|
|
||||||
modtime = time.strftime("%Y-%m-%dT%I:%M:%SZ", time.gmtime())
|
|
||||||
id = doc.createElementNS(atomuri, "id")
|
|
||||||
id.appendChild(doc.createTextNode(
|
|
||||||
"%s%s#%s" % (feedPath, feedName, modtime)))
|
|
||||||
feed.appendChild(id)
|
|
||||||
|
|
||||||
updated = doc.createElementNS(atomuri, "updated")
|
|
||||||
updated.appendChild(doc.createTextNode(modtime))
|
|
||||||
feed.appendChild(updated)
|
|
||||||
|
|
||||||
examples.sort(key=lambda x: x["modified"])
|
|
||||||
for example in sorted(examples, key=lambda x: x["modified"], reverse=True):
|
|
||||||
entry = doc.createElementNS(atomuri, "entry")
|
|
||||||
|
|
||||||
title = doc.createElementNS(atomuri, "title")
|
|
||||||
title.appendChild(doc.createTextNode(example["title"] or
|
|
||||||
example["example"]))
|
|
||||||
entry.appendChild(title)
|
|
||||||
|
|
||||||
tags = doc.createElementNS(atomuri, "tags")
|
|
||||||
tags.appendChild(doc.createTextNode(example["tags"] or
|
|
||||||
example["example"]))
|
|
||||||
entry.appendChild(tags)
|
|
||||||
|
|
||||||
link = doc.createElementNS(atomuri, "link")
|
|
||||||
link.setAttribute("href", "%s%s" % (feedPath, example["example"]))
|
|
||||||
entry.appendChild(link)
|
|
||||||
|
|
||||||
summary = doc.createElementNS(atomuri, "summary")
|
|
||||||
summary.appendChild(doc.createTextNode(example["shortdesc"] or
|
|
||||||
example["example"]))
|
|
||||||
entry.appendChild(summary)
|
|
||||||
|
|
||||||
updated = doc.createElementNS(atomuri, "updated")
|
|
||||||
updated.appendChild(doc.createTextNode(example["modified"]))
|
|
||||||
entry.appendChild(updated)
|
|
||||||
|
|
||||||
author = doc.createElementNS(atomuri, "author")
|
|
||||||
name = doc.createElementNS(atomuri, "name")
|
|
||||||
name.appendChild(doc.createTextNode(example["author"]))
|
|
||||||
author.appendChild(name)
|
|
||||||
entry.appendChild(author)
|
|
||||||
|
|
||||||
id = doc.createElementNS(atomuri, "id")
|
|
||||||
id.appendChild(doc.createTextNode("%s%s#%s" % (feedPath,
|
|
||||||
example["example"],
|
|
||||||
example["modified"])))
|
|
||||||
entry.appendChild(id)
|
|
||||||
|
|
||||||
feed.appendChild(entry)
|
|
||||||
|
|
||||||
doc.appendChild(feed)
|
|
||||||
return doc
|
|
||||||
|
|
||||||
|
|
||||||
def wordIndex(examples):
|
|
||||||
"""
|
|
||||||
Create an inverted index based on words in title and shortdesc. Keys are
|
|
||||||
lower cased words. Values are dictionaries with example index keys and
|
|
||||||
count values.
|
|
||||||
"""
|
|
||||||
index = {}
|
|
||||||
unword = re.compile("\\W+")
|
|
||||||
keys = ["shortdesc", "title", "tags"]
|
|
||||||
for i in range(len(examples)):
|
|
||||||
for key in keys:
|
|
||||||
text = examples[i][key]
|
|
||||||
if text:
|
|
||||||
words = unword.split(text)
|
|
||||||
for word in words:
|
|
||||||
if word:
|
|
||||||
word = word.lower()
|
|
||||||
if word in index:
|
|
||||||
if i in index[word]:
|
|
||||||
index[word][i] += 1
|
|
||||||
else:
|
|
||||||
index[word][i] = 1
|
|
||||||
else:
|
|
||||||
index[word] = {i: 1}
|
|
||||||
return index
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
|
|
||||||
if missing_deps:
|
|
||||||
print """This script requires json or simplejson and BeautifulSoup.
|
|
||||||
You don't have them. \n(%s)""" % E
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
if len(sys.argv) == 3:
|
|
||||||
inExampleDir = sys.argv[1]
|
|
||||||
outExampleDir = sys.argv[2]
|
|
||||||
else:
|
|
||||||
inExampleDir = "../examples"
|
|
||||||
outExampleDir = "../examples"
|
|
||||||
|
|
||||||
outFile = open(os.path.join(outExampleDir, "example-list.js"), "w")
|
|
||||||
|
|
||||||
print 'Reading examples from %s and writing out to %s' % (inExampleDir,
|
|
||||||
outFile.name)
|
|
||||||
|
|
||||||
exampleList = []
|
|
||||||
docIds = ['title', 'shortdesc', 'tags']
|
|
||||||
|
|
||||||
examples = getListOfExamples(inExampleDir)
|
|
||||||
|
|
||||||
modtime = time.strftime("%Y-%m-%dT%I:%M:%SZ", time.gmtime())
|
|
||||||
|
|
||||||
for example in examples:
|
|
||||||
path = os.path.join(inExampleDir, example)
|
|
||||||
html = getExampleHtml(path)
|
|
||||||
tagvalues = parseHtml(html, docIds)
|
|
||||||
tagvalues['example'] = example
|
|
||||||
# add in author/date info
|
|
||||||
d = getGitInfo(inExampleDir, example)
|
|
||||||
tagvalues["author"] = d["author"] or "anonymous"
|
|
||||||
tagvalues["modified"] = d["date"] or modtime
|
|
||||||
tagvalues['link'] = example
|
|
||||||
|
|
||||||
exampleList.append(tagvalues)
|
|
||||||
|
|
||||||
print
|
|
||||||
|
|
||||||
exampleList.sort(key=lambda x: x['example'].lower())
|
|
||||||
|
|
||||||
index = wordIndex(exampleList)
|
|
||||||
|
|
||||||
json = json.dumps({"examples": exampleList, "index": index})
|
|
||||||
# Give the json a global variable we can use in our js.
|
|
||||||
# This should be replaced or made optional.
|
|
||||||
json = 'var info=' + json + ';'
|
|
||||||
outFile.write(json)
|
|
||||||
outFile.close()
|
|
||||||
|
|
||||||
outFeedPath = os.path.join(outExampleDir, feedName)
|
|
||||||
print "writing feed to %s " % outFeedPath
|
|
||||||
atom = open(outFeedPath, 'w')
|
|
||||||
doc = createFeed(exampleList)
|
|
||||||
atom.write(doc.toxml())
|
|
||||||
atom.close()
|
|
||||||
|
|
||||||
print 'complete'
|
|
||||||
@@ -112,23 +112,24 @@ EXECUTABLES = [variables.CLEANCSS, variables.GIT, variables.GJSLINT,
|
|||||||
variables.JSDOC, variables.JSHINT, variables.PYTHON,
|
variables.JSDOC, variables.JSHINT, variables.PYTHON,
|
||||||
variables.PHANTOMJS]
|
variables.PHANTOMJS]
|
||||||
|
|
||||||
EXAMPLES = [path
|
EXAMPLES_SRC_ALL = [path for path in ifind('examples_src')]
|
||||||
for path in ifind('examples')
|
|
||||||
if path.endswith('.html')
|
|
||||||
if path != 'examples/index.html']
|
|
||||||
|
|
||||||
EXAMPLES_SRC = [path
|
EXAMPLES_SRC_HTML = [path
|
||||||
for path in ifind('examples')
|
for path in EXAMPLES_SRC_ALL
|
||||||
if path.endswith('.js')
|
if path.endswith('.html')
|
||||||
if not path.endswith('.combined.js')
|
if path != 'examples_src/index.html']
|
||||||
if path != 'examples/Jugl.js'
|
|
||||||
if path != 'examples/example-list.js']
|
EXAMPLES_SRC_JS = [example.replace('.html', '.js')
|
||||||
|
for example in EXAMPLES_SRC_HTML]
|
||||||
|
|
||||||
|
EXAMPLES_DEST_ALL = [path.replace('examples_src', 'examples')
|
||||||
|
for path in EXAMPLES_SRC_ALL]
|
||||||
|
|
||||||
EXAMPLES_JSON = ['build/' + example.replace('.html', '.json')
|
EXAMPLES_JSON = ['build/' + example.replace('.html', '.json')
|
||||||
for example in EXAMPLES]
|
for example in EXAMPLES_SRC_HTML]
|
||||||
|
|
||||||
EXAMPLES_COMBINED = ['build/' + example.replace('.html', '.combined.js')
|
EXAMPLES_COMBINED = ['build/' + example.replace('.html', '.combined.js')
|
||||||
for example in EXAMPLES]
|
for example in EXAMPLES_SRC_HTML]
|
||||||
|
|
||||||
GLSL_SRC = [path
|
GLSL_SRC = [path
|
||||||
for path in ifind('src')
|
for path in ifind('src')
|
||||||
@@ -261,17 +262,15 @@ virtual('build-examples', 'examples', 'build/examples/all.combined.js',
|
|||||||
EXAMPLES_COMBINED)
|
EXAMPLES_COMBINED)
|
||||||
|
|
||||||
|
|
||||||
virtual('examples', 'examples/example-list.xml', EXAMPLES_JSON)
|
virtual('examples', EXAMPLES_DEST_ALL)
|
||||||
|
|
||||||
|
|
||||||
@target('examples/example-list.xml', 'examples/example-list.js')
|
@rule(r'\Aexamples/(?P<filepath>.*)\Z')
|
||||||
def examples_examples_list_xml(t):
|
def examples_dest(name, match):
|
||||||
t.touch() # already generated by bin/exampleparser.py
|
def action(t):
|
||||||
|
t.run('node', 'tasks/build-examples.js')
|
||||||
|
dependencies = ['examples_src/%(filepath)s' % match.groupdict()]
|
||||||
@target('examples/example-list.js', 'bin/exampleparser.py', EXAMPLES)
|
return Target(name, action=action, dependencies=dependencies)
|
||||||
def examples_examples_list_js(t):
|
|
||||||
t.run('%(PYTHON)s', 'bin/exampleparser.py', 'examples', 'examples')
|
|
||||||
|
|
||||||
|
|
||||||
@target('build/examples/all.combined.js', 'build/examples/all.js',
|
@target('build/examples/all.combined.js', 'build/examples/all.js',
|
||||||
@@ -282,7 +281,7 @@ def build_examples_all_combined_js(t):
|
|||||||
report_sizes(t)
|
report_sizes(t)
|
||||||
|
|
||||||
|
|
||||||
@target('build/examples/all.js', EXAMPLES_SRC)
|
@target('build/examples/all.js', EXAMPLES_SRC_JS)
|
||||||
def build_examples_all_js(t):
|
def build_examples_all_js(t):
|
||||||
t.output('%(PYTHON)s', 'bin/combine-examples.py', t.dependencies)
|
t.output('%(PYTHON)s', 'bin/combine-examples.py', t.dependencies)
|
||||||
|
|
||||||
@@ -405,7 +404,7 @@ def examples_star_combined_js(name, match):
|
|||||||
return Target(name, action=action, dependencies=dependencies)
|
return Target(name, action=action, dependencies=dependencies)
|
||||||
|
|
||||||
|
|
||||||
@target('serve', 'examples', 'build/test_requires.js', 'build/test_rendering_requires.js',
|
@target('serve', 'build/test_requires.js', 'build/test_rendering_requires.js',
|
||||||
NPM_INSTALL)
|
NPM_INSTALL)
|
||||||
def serve(t):
|
def serve(t):
|
||||||
t.run('node', 'tasks/serve.js')
|
t.run('node', 'tasks/serve.js')
|
||||||
@@ -415,7 +414,7 @@ virtual('lint', 'build/lint-timestamp', 'build/check-requires-timestamp',
|
|||||||
'build/check-whitespace-timestamp', 'jshint')
|
'build/check-whitespace-timestamp', 'jshint')
|
||||||
|
|
||||||
|
|
||||||
@target('build/lint-timestamp', SRC, EXAMPLES_SRC, SPEC, SPEC_RENDERING,
|
@target('build/lint-timestamp', SRC, EXAMPLES_SRC_JS, SPEC, SPEC_RENDERING,
|
||||||
precious=True)
|
precious=True)
|
||||||
def build_lint_src_timestamp(t):
|
def build_lint_src_timestamp(t):
|
||||||
t.run('%(GJSLINT)s',
|
t.run('%(GJSLINT)s',
|
||||||
@@ -427,7 +426,7 @@ def build_lint_src_timestamp(t):
|
|||||||
|
|
||||||
virtual('jshint', 'build/jshint-timestamp')
|
virtual('jshint', 'build/jshint-timestamp')
|
||||||
|
|
||||||
@target('build/jshint-timestamp', SRC, EXAMPLES_SRC, SPEC, SPEC_RENDERING,
|
@target('build/jshint-timestamp', SRC, EXAMPLES_SRC_JS, SPEC, SPEC_RENDERING,
|
||||||
TASKS, NPM_INSTALL, precious=True)
|
TASKS, NPM_INSTALL, precious=True)
|
||||||
def build_jshint_timestamp(t):
|
def build_jshint_timestamp(t):
|
||||||
t.run(variables.JSHINT, '--verbose', t.newer(t.dependencies))
|
t.run(variables.JSHINT, '--verbose', t.newer(t.dependencies))
|
||||||
@@ -457,7 +456,7 @@ def _strip_comments(lines):
|
|||||||
yield lineno, line
|
yield lineno, line
|
||||||
|
|
||||||
|
|
||||||
@target('build/check-requires-timestamp', SRC, EXAMPLES_SRC, SHADER_SRC,
|
@target('build/check-requires-timestamp', SRC, EXAMPLES_SRC_JS, SHADER_SRC,
|
||||||
SPEC, SPEC_RENDERING)
|
SPEC, SPEC_RENDERING)
|
||||||
def build_check_requires_timestamp(t):
|
def build_check_requires_timestamp(t):
|
||||||
unused_count = 0
|
unused_count = 0
|
||||||
@@ -598,7 +597,7 @@ def build_check_requires_timestamp(t):
|
|||||||
t.touch()
|
t.touch()
|
||||||
|
|
||||||
|
|
||||||
@target('build/check-whitespace-timestamp', SRC, EXAMPLES_SRC,
|
@target('build/check-whitespace-timestamp', SRC, EXAMPLES_SRC_JS,
|
||||||
SPEC, SPEC_RENDERING, JSDOC_SRC, precious=True)
|
SPEC, SPEC_RENDERING, JSDOC_SRC, precious=True)
|
||||||
def build_check_whitespace_timestamp(t):
|
def build_check_whitespace_timestamp(t):
|
||||||
CR_RE = re.compile(r'\r')
|
CR_RE = re.compile(r'\r')
|
||||||
@@ -691,23 +690,16 @@ def host_examples(t):
|
|||||||
closure_lib_path = output('node', '-e',
|
closure_lib_path = output('node', '-e',
|
||||||
'process.stdout.write(require("closure-util").getLibraryPath())')
|
'process.stdout.write(require("closure-util").getLibraryPath())')
|
||||||
t.rm_rf(examples_dir)
|
t.rm_rf(examples_dir)
|
||||||
t.makedirs(examples_dir)
|
t.cp_r('examples', examples_dir)
|
||||||
|
for example in EXAMPLES_SRC_JS:
|
||||||
|
split_example_file(example, examples_dir % vars(variables))
|
||||||
|
t.cp('bin/loader_hosted_examples.js', examples_dir + '/loader.js')
|
||||||
t.rm_rf(build_dir)
|
t.rm_rf(build_dir)
|
||||||
t.makedirs(build_dir)
|
t.makedirs(build_dir)
|
||||||
t.rm_rf(css_dir)
|
t.rm_rf(css_dir)
|
||||||
t.makedirs(css_dir)
|
t.makedirs(css_dir)
|
||||||
t.cp(EXAMPLES, examples_dir)
|
|
||||||
for example in [path.replace('.html', '.js') for path in EXAMPLES]:
|
|
||||||
split_example_file(example, examples_dir % vars(variables))
|
|
||||||
for example in [path.replace('.html', '.css') for path in EXAMPLES]:
|
|
||||||
if os.path.isfile(example):
|
|
||||||
t.cp(example, examples_dir)
|
|
||||||
t.cp_r('examples/data', examples_dir + '/data')
|
|
||||||
t.cp('bin/loader_hosted_examples.js', examples_dir + '/loader.js')
|
|
||||||
t.cp('build/ol.js', 'build/ol-debug.js', build_dir)
|
t.cp('build/ol.js', 'build/ol-debug.js', build_dir)
|
||||||
t.cp('build/ol.css', css_dir)
|
t.cp('build/ol.css', css_dir)
|
||||||
t.cp('examples/index.html', 'examples/example-list.js',
|
|
||||||
'examples/example-list.xml', 'examples/Jugl.js', examples_dir)
|
|
||||||
t.rm_rf('build/hosted/%(BRANCH)s/closure-library')
|
t.rm_rf('build/hosted/%(BRANCH)s/closure-library')
|
||||||
t.cp_r(closure_lib_path, 'build/hosted/%(BRANCH)s/closure-library')
|
t.cp_r(closure_lib_path, 'build/hosted/%(BRANCH)s/closure-library')
|
||||||
t.rm_rf('build/hosted/%(BRANCH)s/ol')
|
t.rm_rf('build/hosted/%(BRANCH)s/ol')
|
||||||
@@ -726,8 +718,8 @@ def host_examples(t):
|
|||||||
|
|
||||||
@target('check-examples', 'host-examples', phony=True)
|
@target('check-examples', 'host-examples', phony=True)
|
||||||
def check_examples(t):
|
def check_examples(t):
|
||||||
examples = ['build/hosted/%(BRANCH)s/' + e
|
examples = ['build/hosted/%(BRANCH)s/' + e.replace('examples_src', 'examples')
|
||||||
for e in EXAMPLES
|
for e in EXAMPLES_SRC_HTML
|
||||||
if not open(e.replace('.html', '.js'), 'rU').readline().startswith('// NOCOMPILE')]
|
if not open(e.replace('.html', '.js'), 'rU').readline().startswith('// NOCOMPILE')]
|
||||||
all_examples = [e + '?mode=advanced' for e in examples]
|
all_examples = [e + '?mode=advanced' for e in examples]
|
||||||
# Run the examples checks in a pool of threads
|
# Run the examples checks in a pool of threads
|
||||||
|
|||||||
Reference in New Issue
Block a user