Mercurial > traipse
comparison plugins/xxcherrypy.py @ 10:5df1340bda13 grumpy-goblin
Big patch! Linux GUI, Fetching Dict., Init2, Streaming lining.
author | sirebral |
---|---|
date | Tue, 21 Jul 2009 17:19:53 -0500 |
parents | 33582ce538b5 |
children | d492f137cd3c |
comparison
equal
deleted
inserted
replaced
9:80ab434efc87 | 10:5df1340bda13 |
---|---|
1 import os | 1 import os |
2 import wx | |
2 import orpg.plugindb # VEG | 3 import orpg.plugindb # VEG |
3 import orpg.pluginhandler | 4 import orpg.pluginhandler |
5 from orpg.orpgCore import * | |
6 import urllib | |
4 import thread | 7 import thread |
8 import socket | |
5 import cherrypy._cpserver as server | 9 import cherrypy._cpserver as server |
6 import socket | 10 from xml.dom.minidom import parseString |
7 import wx | |
8 from orpg.orpgCore import * | |
9 | 11 |
10 # VEG (march 21, 2007): Now remembers your last web server on/off setting | 12 # VEG (march 21, 2007): Now remembers your last web server on/off setting |
11 | 13 |
12 class Plugin(orpg.pluginhandler.PluginHandler): | 14 class Plugin(orpg.pluginhandler.PluginHandler): |
13 # Initialization subroutine. | 15 # Initialization subroutine. |
17 def __init__(self, plugindb, parent): | 19 def __init__(self, plugindb, parent): |
18 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent) | 20 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent) |
19 | 21 |
20 # The Following code should be edited to contain the proper information | 22 # The Following code should be edited to contain the proper information |
21 self.name = 'CherryPy Web Server' | 23 self.name = 'CherryPy Web Server' |
22 self.author = 'Dj Gilcrease' | 24 self.author = 'Dj Gilcrease & Sir. Ebral' |
23 self.help = 'This plugin turns OpenRPG into a Web server\n' | 25 self.help = 'This plugin turns OpenRPG into a Web server\n' |
24 self.help += 'allowing you to host your map and mini files localy' | 26 self.help += 'allowing you to host your map and mini files locally.' |
25 | 27 |
26 #You can set variables below here. Always set them to a blank value in this section. Use plugin_enabled | 28 #You can set variables below here. Always set them to a blank value in this section. Use plugin_enabled |
27 #to set their proper values. | 29 #to set their proper values. |
28 self.isServerRunning = 'off' | 30 self.isServerRunning = 'off' |
29 self.host = 0 | 31 self.host = 0 |
31 def plugin_menu(self): | 33 def plugin_menu(self): |
32 self.menu = wx.Menu() | 34 self.menu = wx.Menu() |
33 self.toggle = self.menu.AppendCheckItem(wx.ID_ANY, 'On') | 35 self.toggle = self.menu.AppendCheckItem(wx.ID_ANY, 'On') |
34 self.topframe.Bind(wx.EVT_MENU, self.cherrypy_toggle, self.toggle) | 36 self.topframe.Bind(wx.EVT_MENU, self.cherrypy_toggle, self.toggle) |
35 | 37 |
36 def cherrypy_toggle(self, evt): | 38 def cherrypy_toggle(self, evt): #TAS |
37 if self.toggle.IsChecked() == True: self.on_cherrypy("on") | 39 if self.toggle.IsChecked() == True: self.on_cherrypy("on") |
38 if self.toggle.IsChecked() == False: self.on_cherrypy("off") | 40 if self.toggle.IsChecked() == False: self.on_cherrypy("off") |
39 | 41 |
40 def plugin_enabled(self): | 42 def plugin_enabled(self): |
41 cpport = 0 # Container object so we can call port instead of an assigned ## | 43 self.host = parseString( |
42 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. | 44 urllib.urlopen("http://orpgmeta.appspot.com/myip").read() |
43 self.plugin_addcommand('/cherrypy', self.on_cherrypy, '[on | off | port | status] - This controls the CherryPy Web Server') | 45 ).documentElement.getAttribute("ip") |
44 import urllib | 46 |
45 url = urllib.URLopener() | 47 self.port = int(self.plugindb.GetString("xxcherrypy", "port", 8080)) or 6775 |
46 resp = url.open('http://www.knowledgearcana.com/vgt/ip_scrape.php') | 48 |
47 html = resp.read(19+19) | 49 self.plugin_addcommand('/cherrypy', self.on_cherrypy, |
48 ip = html[19:]; self.host = ip[1:len(ip)-1] | 50 '[on | off | port | status] - This controls the CherryPy Web Server') |
49 cpobj = 0 | 51 |
50 if str(self.plugindb.GetString("xxcherrypy", "auto_start", cpobj)) == "on": # VEG | 52 self.on_cherrypy(self.plugindb.GetString("xxcherrypy", "auto_start", None)) # VEG |
51 self.on_cherrypy("on") # VEG | 53 |
52 del cpobj | |
53 self.cherryhost = 'http://' + self.host + ':' + str(self.port) + '/webfiles/' | 54 self.cherryhost = 'http://' + self.host + ':' + str(self.port) + '/webfiles/' |
54 open_rpg.add_component("cherrypy", self.cherryhost) | 55 open_rpg.add_component("cherrypy", self.cherryhost) |
55 | 56 |
56 def plugin_disabled(self): | 57 def plugin_disabled(self): |
57 #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin | 58 #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin |
67 def on_cherrypy(self, cmdargs): | 68 def on_cherrypy(self, cmdargs): |
68 args = cmdargs.split(None,-1) | 69 args = cmdargs.split(None,-1) |
69 | 70 |
70 if len(args) == 0 or args[0] == 'status': | 71 if len(args) == 0 or args[0] == 'status': |
71 self.chat.InfoPost("CherryPy Web Server is currently: " + self.isServerRunning) | 72 self.chat.InfoPost("CherryPy Web Server is currently: " + self.isServerRunning) |
72 self.chat.InfoPost("CherryPy Web Server address is: http://" + str(self.host) + ':' + str(self.port) + '/webfiles/') | 73 self.chat.InfoPost("CherryPy Web Server address is: " + self.cherryhost) |
73 | 74 |
74 elif args[0] == 'on' and self.isServerRunning == 'off': | 75 elif args[0] == 'on' and self.isServerRunning == 'off': |
75 self.webserver = thread.start_new_thread(self.startServer, (self.port,)) | 76 self.webserver = thread.start_new_thread(self.startServer, (self.port,)) |
76 self.isServerRunning = 'on' | 77 self.isServerRunning = 'on' |
77 self.toggle.Check(True) | 78 self.toggle.Check(True) |
79 | 80 |
80 elif args[0] == 'off' and self.isServerRunning == 'on': | 81 elif args[0] == 'off' and self.isServerRunning == 'on': |
81 server.stop() | 82 server.stop() |
82 self.isServerRunning = 'off' | 83 self.isServerRunning = 'off' |
83 self.toggle.Check(False) | 84 self.toggle.Check(False) |
84 self.chat.InfoPost("CherryPy Web Server is now disabled") | 85 self.chat.InfoPost("CherryPy Web Server is currently: " + self.isServerRunning) |
85 self.plugindb.SetString("xxcherrypy", "auto_start", "off") # VEG | 86 self.plugindb.SetString("xxcherrypy", "auto_start", "off") # VEG |
86 | 87 |
87 elif args[0] == 'port': | 88 elif args[0] == 'port': #TAS |
88 if self.isServerRunning == 'on': | 89 if self.isServerRunning == 'on': |
89 self.chat.InfoPost('Please turn CherryPy off first!') | 90 self.chat.InfoPost('Please turn CherryPy off first!') |
90 return | 91 return |
91 self.port = int(args[1]) | 92 self.port = int(args[1]) |
92 self.plugindb.SetString("xxcherrypy", "port", str(self.port)) # TAS | 93 self.plugindb.SetString("xxcherrypy", "port", str(self.port)) # TAS |
93 self.chat.InfoPost("CherryPy Web Server is currently: " + self.isServerRunning) | 94 self.chat.InfoPost("CherryPy Web Server is currently: " + self.isServerRunning) |
94 self.cherryhost = 'http://' + self.host + ':' + str(self.port) + '/webfiles/' | 95 self.cherryhost = 'http://' + self.host + ':' + str(self.port) + '/webfiles/' |
95 open_rpg.del_component("cherrypy"); open_rpg.add_component("cherrypy", self.cherryhost) | 96 open_rpg.del_component("cherrypy"); open_rpg.add_component("cherrypy", self.cherryhost) |
96 self.chat.InfoPost('CherryPy Web Server address is: ' + self.cherryhost) | 97 self.chat.InfoPost('CherryPy Web Server address is: ' + self.cherryhost) |
97 | 98 |
98 | |
99 def startServer(self, port): | 99 def startServer(self, port): |
100 try: | 100 try: |
101 if self.host == 0: | 101 if self.host == 0: |
102 raise Exception("Invalid IP address.<br />This error means you are behind a router or some other form of network that is giving you a Privet IP only (ie. 192.168.x.x, 10.x.x.x, 172.16 - 32.x.x)") | 102 raise Exception("Invalid IP address.<br />This error means you are behind a router or some other form of network that is giving you a Privet IP only (ie. 192.168.x.x, 10.x.x.x, 172.16 - 32.x.x)") |
103 | 103 |
104 self.chat.InfoPost("CherryPy Web Server is now running on http://" + str(self.host) + ':' + str(self.port) + '/webfiles/') | 104 self.chat.InfoPost("CherryPy Web Server is now running on http://" + str(self.host) + ':' + str(self.port) + '/webfiles/') |
105 server.start(configMap = | 105 server.start(configMap = |
106 {'staticContentList': [['', r''+orpg.dirpath.dir_struct["user"]+'webfiles/'], | 106 {'staticContentList': [['', r''+orpg.dirpath.dir_struct["user"]+'webfiles/'], |
107 ['webfiles', r''+orpg.dirpath.dir_struct["user"]+'webfiles/'], | 107 ['webfiles', r''+orpg.dirpath.dir_struct["user"]+'webfiles/']], |
108 ['Textures', r''+orpg.dirpath.dir_struct["user"]+'Textures/'], | |
109 ['Maps', r''+orpg.dirpath.dir_struct["user"]+'Maps/'], | |
110 ['Miniatures', r''+orpg.dirpath.dir_struct["user"]+'Miniatures']], | |
111 'socketPort': port, | 108 'socketPort': port, |
112 'logToScreen': 0, | 109 'logToScreen': 0, |
113 'logFile':orpg.dirpath.dir_struct["user"]+'webfiles/log.txt', | 110 'logFile':orpg.dirpath.dir_struct["user"]+'webfiles/log.txt', |
114 'sessionStorageType':'ram', | 111 'sessionStorageType':'ram', |
115 'threadPool':10, | 112 'threadPool':10, |