changeset 8:33582ce538b5 grumpy-goblin

CherryPy improvements.
author sirebral
date Sat, 18 Jul 2009 11:40:34 -0500
parents d63ad196cc0d
children 80ab434efc87
files orpg/mapper/background_handler.py orpg/mapper/miniatures_handler.py orpg/orpgCore.py plugins/xxcherrypy.py
diffstat 4 files changed, 43 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/orpg/mapper/background_handler.py	Fri Jul 17 01:56:41 2009 -0500
+++ b/orpg/mapper/background_handler.py	Sat Jul 18 11:40:34 2009 -0500
@@ -32,7 +32,7 @@
 from background import *
 from base_handler import *
 import mimetypes
-
+import os
 from base import *
 
 class background_handler(base_layer_handler):
@@ -79,17 +79,16 @@
             if self.settings.get_setting('LocalorRemote') == 'Remote':
                 thread.start_new_thread(self.canvas.layers['bg'].upload, (postdata, dlg.GetPath(), self.bg_type.GetStringSelection()))
             else:
-                url = self.settings.get_setting('LocalImageBaseURL')
-                print dlg.GetDirectory()
-                print orpg.dirpath.dir_struct["user"]
-                if dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles/Textures' or dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles\Textures': url = self.settings.get_setting('LocalImageBaseURL') + 'Textures/'
-                if dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles/Maps' or dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles\Maps': url = self.settings.get_setting('LocalImageBaseURL') + 'Maps/'
-                if dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles/Miniatures' or dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles\Miniatures': url = self.settings.get_setting('LocalImageBaseURL') + 'Miniatures/'
-                path = url + filename
+                try:
+                    min_url = open_rpg.get_component("cherrypy") + filename
+                except:
+                    return
+                min_url = dlg.GetDirectory().replace(orpg.dirpath.dir_struct["user"]+'webfiles' + os.sep, open_rpg.get_component("cherrypy")) + '/' + filename
+
                 if self.bg_type.GetStringSelection() == 'Texture':
-                    self.canvas.layers['bg'].set_texture(path)
+                    self.canvas.layers['bg'].set_texture(min_url)
                 elif self.bg_type.GetStringSelection() == 'Image':
-                    self.size = self.canvas.layers['bg'].set_image(path,1)
+                    self.size = self.canvas.layers['bg'].set_image(min_url,1)
                 self.update_info()
                 self.canvas.send_map_data()
                 self.canvas.Refresh(False)
--- a/orpg/mapper/miniatures_handler.py	Fri Jul 17 01:56:41 2009 -0500
+++ b/orpg/mapper/miniatures_handler.py	Sat Jul 18 11:40:34 2009 -0500
@@ -38,6 +38,8 @@
 from grid import GRID_RECTANGLE
 from grid import GRID_HEXAGON
 from grid import GRID_ISOMETRIC
+import os
+
 LABEL_TOOL = wx.NewId()
 LAYER_TOOL = wx.NewId()
 MIN_LIST_TOOL = wx.NewId()
@@ -159,10 +161,11 @@
             y = dc.DeviceToLogicalY(0)
             thread.start_new_thread(self.canvas.layers['miniatures'].upload, (postdata, dlg.GetPath()), {'pos':cmpPoint(x,y)})
         else:
-            min_url = self.settings.get_setting('LocalImageBaseURL') + filename
-            if dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles/Textures' or dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles\Textures': min_url = self.settings.get_setting('LocalImageBaseURL') + 'Textures/' + filename
-            if dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles/Maps' or dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles\Maps': min_url = self.settings.get_setting('ImageServerBaseURL') + 'Maps/' + filename
-            if dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles/Miniatures' or dlg.GetDirectory() == orpg.dirpath.dir_struct["user"]+'webfiles\Miniatures': min_url = self.settings.get_setting('LocalImageBaseURL') + 'Miniatures/' + filename
+            try:
+                min_url = open_rpg.get_component("cherrypy") + filename
+            except:
+                return
+            min_url = dlg.GetDirectory().replace(orpg.dirpath.dir_struct["user"]+'webfiles' + os.sep, open_rpg.get_component("cherrypy")) + '/' + filename
             # build url
             if min_url == "" or min_url == "http://":
                 return
--- a/orpg/orpgCore.py	Fri Jul 17 01:56:41 2009 -0500
+++ b/orpg/orpgCore.py	Sat Jul 18 11:40:34 2009 -0500
@@ -69,6 +69,12 @@
         else:
             return None
 
+    def del_component(self, key):
+        if self.__components.has_key(key):
+            del self.__components[key]
+        else:
+            return
+
 def singleton(cls):
     instances = {}
     def getinstance():
--- a/plugins/xxcherrypy.py	Fri Jul 17 01:56:41 2009 -0500
+++ b/plugins/xxcherrypy.py	Sat Jul 18 11:40:34 2009 -0500
@@ -5,6 +5,7 @@
 import cherrypy._cpserver as server
 import socket
 import wx
+from orpg.orpgCore import *
 
  # VEG (march 21, 2007): Now remembers your last web server on/off setting
 
@@ -32,32 +33,25 @@
         self.toggle = self.menu.AppendCheckItem(wx.ID_ANY, 'On')
         self.topframe.Bind(wx.EVT_MENU, self.cherrypy_toggle, self.toggle)
 
-        ports = wx.Menu()
-        self.portClient = ports.AppendRadioItem(wx.ID_ANY, 'Client:9557')
-        self.portServer = ports.AppendRadioItem(wx.ID_ANY, 'Server:9558')
-        self.topframe.Bind(wx.EVT_MENU, self.port_change, self.portClient)
-        self.topframe.Bind(wx.EVT_MENU, self.port_change, self.portServer)
-        self.menu.AppendMenu(wx.ID_ANY, 'Port', ports)
-
-    def port_change(self, evt):
-        if self.portClient.IsChecked() == True: self.on_cherrypy("port 9557")
-        if self.portServer.IsChecked() == True: self.on_cherrypy("port 9558")
-
     def cherrypy_toggle(self, evt):
         if self.toggle.IsChecked() == True: self.on_cherrypy("on")
         if self.toggle.IsChecked() == False: self.on_cherrypy("off")
 
     def plugin_enabled(self):
-        self.port = 9557
+        cpport = 0 # Container object so we can call port instead of an assigned ##
+        self.port = 6775 if not int(self.plugindb.GetString("xxcherrypy", "port", cpport)) else int(self.plugindb.GetString("xxcherrypy", "port", cpport)); del cpport #Deletes port container.
         self.plugin_addcommand('/cherrypy', self.on_cherrypy, '[on | off | port | status] - This controls the CherryPy Web Server')
-        tmp = socket.gethostbyname_ex(socket.gethostname())
-        for ip in tmp[2]:
-            self.host = ip
-            if ip[:7] == '192.168' or ip[:3] == '10.' or ip == '127.0.0.1' or (ip[:3] == '172' and (int(ip[5:6]) >= 16 and int(ip[5:6]) <=32)) :
-                self.chat.InfoPost("[WARNING] Cherrypy has detected that you may be behind a router. This is your internal IP. For other users to properly connect, you may have to use your external IP, with port forwarding on port 80.<br />This feature is not suported in any way.")
-
-        #if str(self.plugindb.GetString("xxcherrypy", "auto_start", "off")) == "on":  # VEG
-        #    self.on_cherrypy("on")                                                   # VEG
+        import urllib
+        url = urllib.URLopener()
+        resp = url.open('http://www.knowledgearcana.com/vgt/ip_scrape.php')
+        html = resp.read(19+19)
+        ip = html[19:]; self.host = ip[1:len(ip)-1]
+        cpobj = 0
+        if str(self.plugindb.GetString("xxcherrypy", "auto_start", cpobj)) == "on":  # VEG
+            self.on_cherrypy("on")                                                   # VEG
+        del cpobj
+        self.cherryhost = 'http://' + self.host + ':' + str(self.port) + '/webfiles/'
+        open_rpg.add_component("cherrypy", self.cherryhost)
 
     def plugin_disabled(self):
         #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin
@@ -68,7 +62,7 @@
             self.isServerRunning = 'off'
         else:
             pass
-
+        open_rpg.del_component("cherrypy")
 
     def on_cherrypy(self, cmdargs):
         args = cmdargs.split(None,-1)
@@ -92,13 +86,14 @@
 
         elif args[0] == 'port':
             if self.isServerRunning == 'on':
-                self.port = int(args[1])
-                server.stop()
-                self.webserver = thread.start_new_thread(self.startServer, (self.port,))
+                self.chat.InfoPost('Please turn CherryPy off first!')
+                return
             self.port = int(args[1])
+            self.plugindb.SetString("xxcherrypy", "port", str(self.port)) # TAS
             self.chat.InfoPost("CherryPy Web Server is currently: " + self.isServerRunning)
-            self.chat.InfoPost("CherryPy Web Server address is: http://" + str(self.host) + ':' + str(self.port) + '/webfiles/')
-
+            self.cherryhost = 'http://' + self.host + ':' + str(self.port) + '/webfiles/'
+            open_rpg.del_component("cherrypy"); open_rpg.add_component("cherrypy", self.cherryhost)
+            self.chat.InfoPost('CherryPy Web Server address is: ' + self.cherryhost)
 
 
     def startServer(self, port):