Add gzip support for data in static page exports.
This commit is contained in:
parent
b3bdeabaf3
commit
79959e76dc
@ -1,4 +1,5 @@
|
||||
import os
|
||||
import gzip
|
||||
import shutil
|
||||
import django
|
||||
|
||||
@ -8,6 +9,7 @@ from django.test import RequestFactory
|
||||
from django.core.urlresolvers import resolve
|
||||
|
||||
from stackviz.parser import tempest_subunit
|
||||
from stackviz import settings
|
||||
|
||||
|
||||
EXPORT_PATHS = [
|
||||
@ -30,17 +32,31 @@ def fake_render_view(path):
|
||||
return response
|
||||
|
||||
|
||||
def export_single_page(path, dest_dir):
|
||||
def export_single_page(path, dest_dir, use_gzip=False):
|
||||
dest_file = path
|
||||
if dest_file.startswith('/'):
|
||||
dest_file = dest_file[1:]
|
||||
|
||||
with open(os.path.join(dest_dir, dest_file), 'w') as f:
|
||||
open_func = open
|
||||
if use_gzip:
|
||||
open_func = gzip.open
|
||||
dest_file += ".gz"
|
||||
|
||||
with open_func(os.path.join(dest_dir, dest_file), 'wb') as f:
|
||||
content = fake_render_view(path).content
|
||||
|
||||
f.write(content)
|
||||
|
||||
|
||||
def init_django(args):
|
||||
# remove leading / from static URL to give them correct filesystem paths
|
||||
settings.STATIC_URL = settings.STATIC_URL[1:]
|
||||
settings.USE_GZIP = args.gzip
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "stackviz.settings")
|
||||
django.setup()
|
||||
|
||||
|
||||
def main():
|
||||
parser = ArgumentParser(description="Generates a self-contained, static "
|
||||
"StackViz site at the given path.")
|
||||
@ -49,6 +65,9 @@ def main():
|
||||
"doesn't already exist.")
|
||||
parser.add_argument("--ignore-bower",
|
||||
help="Ignore missing Bower components.")
|
||||
parser.add_argument("--gzip",
|
||||
help="Enable gzip compression for data files.",
|
||||
action="store_true")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@ -65,6 +84,8 @@ def main():
|
||||
|
||||
os.mkdir(args.path)
|
||||
|
||||
init_django(args)
|
||||
|
||||
print "Copying static files ..."
|
||||
shutil.copytree(os.path.join('stackviz', 'static'),
|
||||
os.path.join(args.path, 'static'))
|
||||
@ -79,20 +100,13 @@ def main():
|
||||
export_single_page('/tempest_results_%d.html' % run_id, args.path)
|
||||
|
||||
print "Exporting data for tempest run #%d" % run_id
|
||||
export_single_page('/tempest_api_tree_%d.json' % run_id, args.path)
|
||||
export_single_page('/tempest_api_raw_%d.json' % run_id, args.path)
|
||||
|
||||
# TODO
|
||||
# export_single_page('tempest_api_details_%d.json' % run_id, args.path)
|
||||
export_single_page('/tempest_api_tree_%d.json' % run_id,
|
||||
args.path, args.gzip)
|
||||
export_single_page('/tempest_api_raw_%d.json' % run_id,
|
||||
args.path, args.gzip)
|
||||
export_single_page('/tempest_api_details_%d.json' % run_id,
|
||||
args.path, args.gzip)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# remove leading / from static URL to give them correct filesystem paths
|
||||
import stackviz.settings as settings
|
||||
settings.STATIC_URL = settings.STATIC_URL[1:]
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "stackviz.settings")
|
||||
|
||||
django.setup()
|
||||
|
||||
main()
|
||||
|
@ -1,7 +1,8 @@
|
||||
from stackviz.parser.tempest_subunit import get_repositories
|
||||
|
||||
from stackviz.settings import USE_GZIP
|
||||
|
||||
def inject_extra_context(request):
|
||||
return {
|
||||
'tempest_latest_run': get_repositories()[0].latest_id()
|
||||
'tempest_latest_run': get_repositories()[0].latest_id(),
|
||||
'use_gzip': USE_GZIP
|
||||
}
|
||||
|
@ -91,3 +91,8 @@ TEST_REPOSITORIES = [
|
||||
'/opt/stack/tempest/',
|
||||
BASE_DIR
|
||||
]
|
||||
|
||||
# If true, AJAX calls should attempt to load `*.json.gz` files rather than plain
|
||||
# `*.json` files. This should only ever be toggled `True` for static site
|
||||
# exports and is not currently supported on live servers.
|
||||
USE_GZIP = False
|
||||
|
@ -149,7 +149,14 @@ window.addEventListener('load', function() {
|
||||
var selectedItem = null;
|
||||
var selectedValue = null;
|
||||
|
||||
loadTimeline("tempest_api_raw_{{run_id}}.json", {
|
||||
var url = "tempest_api_raw_{{run_id}}.json";
|
||||
if ("{{use_gzip}}" === "True") {
|
||||
url += ".gz";
|
||||
}
|
||||
|
||||
console.log("url is", url);
|
||||
|
||||
loadTimeline(url, {
|
||||
container: $("#timeline-container")[0],
|
||||
onClick: function(d) {
|
||||
var self = d3.select(this);
|
||||
|
Loading…
x
Reference in New Issue
Block a user