diff options
author | Chris Schlaeger <chris@linux.com> | 2014-08-12 21:56:44 +0200 |
---|---|---|
committer | Chris Schlaeger <chris@linux.com> | 2014-08-12 21:56:44 +0200 |
commit | ea346a785dc1b3f7c156f6fc33da634e1f1a627b (patch) | |
tree | af67530553d20b6e82ad60fd79593e9c4abf5565 /misc/openlayers/tools/shrinksafe.py | |
parent | 59741cd535c47f25971bf8c32b25da25ceadc6d5 (diff) | |
download | postrunner-ea346a785dc1b3f7c156f6fc33da634e1f1a627b.zip |
Adding jquery, flot and openlayers to be included with the GEM.v0.0.4
Diffstat (limited to 'misc/openlayers/tools/shrinksafe.py')
-rwxr-xr-x | misc/openlayers/tools/shrinksafe.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/misc/openlayers/tools/shrinksafe.py b/misc/openlayers/tools/shrinksafe.py new file mode 100755 index 0000000..a42e941 --- /dev/null +++ b/misc/openlayers/tools/shrinksafe.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# +# Script to provide a wrapper around the ShrinkSafe "web service" +# <http://shrinksafe.dojotoolkit.org/> +# + +# +# We use this script for two reasons: +# +# * This avoids having to install and configure Java and the standalone +# ShrinkSafe utility. +# +# * The current ShrinkSafe standalone utility was broken when we last +# used it. +# + +import sys + +import urllib +import urllib2 + +URL_SHRINK_SAFE = "http://shrinksafe.dojotoolkit.org/shrinksafe.php" + +# This would normally be dynamically generated: +BOUNDARY_MARKER = "---------------------------72288400411964641492083565382" + +if __name__ == "__main__": + ## Grab the source code + try: + sourceFilename = sys.argv[1] + except: + print "Usage: %s (<source filename>|-)" % sys.argv[0] + raise SystemExit + + if sourceFilename == "-": + sourceCode = sys.stdin.read() + sourceFilename = "stdin.js" + else: + sourceCode = open(sourceFilename).read() + + ## Create the request replicating posting of the form from the web page + request = urllib2.Request(url=URL_SHRINK_SAFE) + request.add_header("Content-Type", + "multipart/form-data; boundary=%s" % BOUNDARY_MARKER) + request.add_data(""" +--%s +Content-Disposition: form-data; name="shrinkfile[]"; filename="%s" +Content-Type: application/x-javascript + +%s +""" % (BOUNDARY_MARKER, sourceFilename, sourceCode)) + + ## Deliver the result + print urllib2.urlopen(request).read(), |