[yt-svn] commit/yt: MatthewTurk: Fixing mapserver by splitting out the reasonjs locator into its own function

Bitbucket commits-noreply at bitbucket.org
Mon Jul 23 19:57:57 PDT 2012


1 new commit in yt:


https://bitbucket.org/yt_analysis/yt/changeset/d832fd135d52/
changeset:   d832fd135d52
branch:      yt
user:        MatthewTurk
date:        2012-07-24 04:57:47
summary:     Fixing mapserver by splitting out the reasonjs locator into its own function
and then using that.
affected #:  4 files

diff -r 7eb83a0222618770a6f47e616cb3708e2399fc5e -r d832fd135d52eb84c262852bc34d575363ea11e5 yt/gui/reason/html/map_index.html
--- a/yt/gui/reason/html/map_index.html
+++ b/yt/gui/reason/html/map_index.html
@@ -1,9 +1,9 @@
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
-<link rel="stylesheet" href="static/leaflet.css" /><!-- Leaflet JavaScript -->
-<script src="static/leaflet.js"></script>
+<script type="text/javascript" src="/reason-js/leaflet/leaflet.js"></script>
+<link rel="stylesheet" href="/reason-js/leaflet/leaflet.css" /><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script><script type="text/javascript">
   $(document).ready(function() {


diff -r 7eb83a0222618770a6f47e616cb3708e2399fc5e -r d832fd135d52eb84c262852bc34d575363ea11e5 yt/gui/reason/pannable_map.py
--- a/yt/gui/reason/pannable_map.py
+++ b/yt/gui/reason/pannable_map.py
@@ -24,6 +24,8 @@
 """
 import os
 import numpy as na
+import zipfile
+import sys
 
 from yt.visualization.image_writer import apply_colormap
 from yt.visualization.fixed_resolution import FixedResolutionBuffer
@@ -48,6 +50,7 @@
 
 class PannableMapServer(object):
     _widget_name = "pannable_map"
+    reasonjs_file = None
     def __init__(self, data, field, route_prefix = ""):
         self.data = data
         self.pf = data.pf
@@ -56,10 +59,18 @@
         bottle.route("%s/map/:L/:x/:y.png" % route_prefix)(self.map)
         bottle.route("%s/" % route_prefix)(self.index)
         bottle.route("%s/index.html" % route_prefix)(self.index)
-        bottle.route("%s/static/:filename#.+#" % route_prefix)(self.static)
         # This is a double-check, since we do not always mandate this for
         # slices:
         self.data[self.field] = self.data[self.field].astype("float64")
+        if route_prefix == "":
+            # We assume this means we're running standalone
+            from .utils import get_reasonjs_path
+            try:
+                reasonjs_path = get_reasonjs_path()
+            except IOError:
+                sys.exit(1)
+            self.reasonjs_file = zipfile.ZipFile(reasonjs_path, 'r')
+            bottle.route("/reason-js/:path#.+#", "GET")(self.static)
 
     def map(self, L, x, y):
         dd = 1.0 / (2.0**(int(L)))
@@ -90,10 +101,21 @@
         return rv
 
     def index(self):
-        return bottle.static_file("map_index.html", root=self._path("html"))
+        return bottle.static_file("map_index.html",
+                    root=os.path.join(local_dir, "html"))
 
-    def static(self, filename):
-        return bottle.static_file(filename, root=self._path("html/leaflet"))
-
-    def _path(self, fn):
-        return os.path.join(local_dir, fn) 
+    def static(self, path):
+        if self.reasonjs_file is None: raise RuntimeError
+        pp = os.path.join("reason-js", path)
+        try:
+            f = self.reasonjs_file.open(pp)
+        except KeyError:
+            bottle.response.status = 404
+            return
+        if path[-4:].lower() in (".png", ".gif", ".jpg"):
+            bottle.response.headers['Content-Type'] = "image/%s" % (path[-3:].lower())
+        elif path[-4:].lower() == ".css":
+            bottle.response.headers['Content-Type'] = "text/css"
+        elif path[-3:].lower() == ".js":
+            bottle.response.headers['Content-Type'] = "text/javascript"
+        return f.read()


diff -r 7eb83a0222618770a6f47e616cb3708e2399fc5e -r d832fd135d52eb84c262852bc34d575363ea11e5 yt/gui/reason/utils.py
--- a/yt/gui/reason/utils.py
+++ b/yt/gui/reason/utils.py
@@ -28,6 +28,7 @@
 from .bottle_mods import PayloadHandler
 import base64
 import types
+import os
 
 def load_script(filename):
     contents = open(filename).read()
@@ -82,3 +83,27 @@
                         type = "parameter_file",
                         varname = pf_varname, field_list = field_list) )
     return rv
+
+def get_reasonjs_path():
+    fn = "reason-js-20120623.zip"
+    if "YT_DEST" not in os.environ:
+        print
+        print "*** You must set the environment variable YT_DEST ***"
+        print "*** to point to the installation location!        ***"
+        print
+        raise IOError
+    reasonjs_path = os.path.join(os.environ["YT_DEST"], "src", fn)
+    if not os.path.isfile(reasonjs_path):
+        print
+        print "*** You are missing the Reason support files. You ***"
+        print "*** You can get these by either rerunning the     ***"
+        print "*** install script installing, or downloading     ***"
+        print "*** them manually.                                ***"
+        print "***                                               ***"
+        print "*** FOR INSTANCE:                                 ***"
+        print
+        print "cd %s" % os.path.join(os.environ["YT_DEST"], "src")
+        print "wget http://yt-project.org/dependencies/reason-js-20120623.zip"
+        print
+        raise IOError
+    return reasonjs_path


diff -r 7eb83a0222618770a6f47e616cb3708e2399fc5e -r d832fd135d52eb84c262852bc34d575363ea11e5 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -1302,12 +1302,6 @@
     def __call__(self, args):
         # We have to do a couple things.
         # First, we check that YT_DEST is set.
-        if "YT_DEST" not in os.environ:
-            print
-            print "*** You must set the environment variable YT_DEST ***"
-            print "*** to point to the installation location!        ***"
-            print
-            sys.exit(1)
         if args.port == 0:
             # This means, choose one at random.  We do this by binding to a
             # socket and allowing the OS to choose the port for that socket.
@@ -1323,20 +1317,10 @@
             except ValueError:
                 print "Please try a number next time."
                 return 1
-        fn = "reason-js-20120623.zip"
-        reasonjs_path = os.path.join(os.environ["YT_DEST"], "src", fn)
-        if not os.path.isfile(reasonjs_path):
-            print
-            print "*** You are missing the Reason support files. You ***"
-            print "*** You can get these by either rerunning the     ***"
-            print "*** install script installing, or downloading     ***"
-            print "*** them manually.                                ***"
-            print "***                                               ***"
-            print "*** FOR INSTANCE:                                 ***"
-            print
-            print "cd %s" % os.path.join(os.environ["YT_DEST"], "src")
-            print "wget http://yt-project.org/dependencies/reason-js-20120623.zip"
-            print
+        from yt.gui.reason.utils import get_reasonjs_path
+        try:
+            reasonjs_path = get_reasonjs_path()
+        except IOError:
             sys.exit(1)
         from yt.config import ytcfg;ytcfg["yt","__withinreason"]="True"
         import yt.utilities.bottle as bottle

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list