-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrezzme.py
executable file
·265 lines (206 loc) · 10.9 KB
/
rezzme.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/usr/bin/python
# -*- encoding: utf-8 -*-
# Copyright (c) Contributors, http://opensimulator.org/
# See CONTRIBUTORS.TXT for a full list of copyright holders.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the OpenSim Project nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
rezzme.py is a little launcher tool that knows about the GridInfo
protocol. it expects the grid coordinates to be passed as a
command line argument either as a "rezzme:" or as an "opensim:" style
URI:
rezzme://osgrid.org:8002/
you can also provide region/X/Y/Z coordinates:
rezzme://osgrid.org:8002/Wright%20Plaza/128/50/75
and, it also understands avatar names and passwords:
rezzme://mr%20smart:[email protected]:8002/Wright%20Plaza/128/50/75
'''
# early initialization: load config, setup logging
import os
import sys
logHandler = None
protologHandler = None
try:
import logging
import logging.handlers
import RezzMe.config.config
cfg = RezzMe.config.config.config()
# set up logging support
if 'level' in cfg['debug']:
level = eval('logging.%s' % cfg['debug']['level'])
else:
level = logging.CRITICAL
logfile = cfg['debug']['logfile'] if 'logfile' in cfg['debug'] else '~/.rezzme.log'
protologfile = cfg['debug']['protologfile'] if 'protologfile' in cfg['debug'] else '~/.rezzme-proto.log'
logsize = cfg['debug']['logsize'] if 'logsize' in cfg['debug'] else 1000 * 100
if logfile:
logfile = os.path.expanduser(logfile)
protologfile = os.path.expanduser(protologfile)
if logfile.startswith('~/') and sys.platform == 'win32' and 'USERPROFILE' in os.environ:
logfile = '%s/%s' % (os.environ['USERPROFILE'], logfile[2:])
if protologfile.startswith('~/') and sys.platform == 'win32' and 'USERPROFILE' in os.environ:
protologfile = '%s/%s' % (os.environ['USERPROFILE'], protologfile[2:])
logHandler = logging.handlers.RotatingFileHandler(logfile, 'a', logsize)
logHandler.setFormatter(logging.Formatter('%(asctime)s %(levelname)-8s %(message)s',
'%a, %d %b %Y %H:%M:%S'))
protologHandler = logging.handlers.RotatingFileHandler(protologfile, 'a', logsize)
protologHandler.setFormatter(logging.Formatter('%(asctime)s %(levelname)-8s %(message)s',
'%a, %d %b %Y %H:%M:%S'))
logging.getLogger().addHandler(logHandler)
logging.getLogger().setLevel(level)
else:
logging.basicConfig(level = level,
format = '%(asctime)s %(levelname)-8s %(message)s',
datefmt = '%a, %d %b %Y %H:%M:%S')
except BaseException, e:
print >>sys.stderr, 'failed to do early-initialization: %s' % str(e)
sys.exit(1)
# late initialization: the rest
try:
import socket
import PyQt4.QtCore
import PyQt4.QtGui
import RezzMe.connect
import RezzMe.config.desktop
import RezzMe.bookmarks
import RezzMe.exceptions
import RezzMe.gridinfo
import RezzMe.launcher
import RezzMe.parse
import RezzMe.ui.launcher
import RezzMe.ui.tray
import RezzMe.uri
import RezzMe.utils
except ImportError, e:
logging.critical('rezzme: import error: %s', str(e), exc_info = True)
sys.exit(1)
except BaseException, e:
logging.critical('rezzme: the unexpected happened: %s', str(e), exc_info = True)
sys.exit(1)
timeout = 15
onMacOSX = sys.platform == 'darwin'
onLinux = sys.platform == 'linux2'
onWindows = sys.platform == 'win32'
class RezzMeQApplication(PyQt4.QtGui.QApplication):
def __init__(self, argv):
self.Done = False
super(RezzMeQApplication, self).__init__(argv)
if __name__ == '__main__':
# slightly generous banner makes it easier to find start of trace in log file :-)
logging.info(' ')
logging.info('========================================')
logging.info('rezzme.py version %s on %s' %( cfg['package']['version'], sys.platform))
logging.info('started from %s' % sys.argv[0])
logging.info('========================================')
logging.info(' ')
# set the socket timeout
socket.setdefaulttimeout(timeout)
# need an QApplication context to signal errors
app = RezzMeQApplication(sys.argv)
RezzMe.config.desktop.InstallProtocolHandlers(cfg)
args = sys.argv[1:]
tray = None
try:
# on MacOSX rezzme always runs in system tray mode and gets
# the rezzme:// URIs via the GURL GURL AppleEvent from the OS
if onMacOSX:
# on MacOSX we need to be able to receive AppleEvents
import aemreceive.sfba as AppleEvents
# the MacOSXAppleEventHandler derives from QObject so that
# we can issue SIGNAL('rezzme')
class MacOSXAppleEventHandler(PyQt4.QtCore.QObject):
def __init__(self, parent = None):
super(MacOSXAppleEventHandler, self).__init__(parent)
# _urlHandler is the actual handler and emits
# SIGNAL('rezzme') with the actual uri as payload
def _urlHandler(uri):
self.emit(PyQt4.QtCore.SIGNAL('rezzme'), uri)
def _quitHandler():
logging.debug('rezzme.main: onMacOSX: quitHandler called')
self.emit(PyQt4.QtCore.SIGNAL('quitme'))
# tie the GURL GURL AppleEvent to _urlHandler
AppleEvents.installeventhandler(_urlHandler, 'GURLGURL', ('----', 'uri', AppleEvents.kAE.typeUnicodeText))
AppleEvents.installeventhandler(_quitHandler, 'aevtquit')
logging.debug('rezzme.MacOSXAppleEventHandler: installed event handler for "GURLGURL"')
# change log format
if logHandler:
logHandler.setFormatter(logging.Formatter('%(asctime)s [mac] %(levelname)-8s %(message)s',
'%a, %d %b %Y %H:%M:%S'))
# instantiate our AppleEvent handler object
logging.debug('rezzme.main: onMacOSX: installing MacOS AppleEvent handler')
aeHandler = MacOSXAppleEventHandler()
# instantiate system tray
logging.debug('rezzme.main: onMacOSX: instantiating rezzme system tray')
tray = RezzMe.ui.tray.RezzMeTrayWindow(parent = None, app = app, cfg = cfg)
# create a closure to capture app and cfg
def rezzMe(uri, app = app):
logging.debug('rezzme.main: rezzme AppleEvent: uri %s', uri)
RezzMe.connect.Connect(app = app, uri = uri, cfg = cfg)
def quitMe(app = app):
app.Done = True
# connect SIGNAL('rezzme') to rezzMe()
app.connect(aeHandler, PyQt4.QtCore.SIGNAL('rezzme'), rezzMe, PyQt4.QtCore.Qt.QueuedConnection)
app.connect(aeHandler, PyQt4.QtCore.SIGNAL('quitme'), quitMe, PyQt4.QtCore.Qt.QueuedConnection)
logging.debug('rezzme.main: onMacOSX: starting')
# on linux or windows
else:
# no command line arguments supplied: system tray mode
if not args:
if logHandler:
# change log format
logHandler.setFormatter(logging.Formatter('%(asctime)s [systray] %(levelname)-8s %(message)s',
'%a, %d %b %Y %H:%M:%S'))
logging.debug('rezzme.main: invoked without command line arguments, starting rezzme system tray')
# instantiate system tray
tray = RezzMe.ui.tray.RezzMeTrayWindow(parent = None, app = app, cfg = cfg)
# command line arguments supplied: protocol handler mode
else:
if protologHandler:
# change log format
logging.info('rezzme.main: switching to proto handler logfile')
logging.getLogger().removeHandler(logHandler)
logging.getLogger().addHandler(protologHandler)
protologHandler.setFormatter(logging.Formatter('%(asctime)s [proto] %(levelname)-8s %(message)s',
'%a, %d %b %Y %H:%M:%S'))
logging.debug('rezzme.main: invoked with command line arguments: %s', ' '.join(args))
uris = [u for u in args if u.lower().startswith('rezzme://') or u.lower().startswith('rezzmes://')]
if not uris:
raise RezzMe.exceptions.RezzMeException('missing rezzme:// URI')
# interact with user and grid via launcher
logging.debug('rezzme.main: starting launcher GUI')
RezzMe.connect.Connect(app = app, uri = uris[0], cfg = cfg)
# stay in the PyQt4 event loop until system tray is terminated
while not app.Done: app.exec_()
except RezzMe.exceptions.RezzMeException, e:
logging.critical('rezzme.main: caught rezzme exception: %s', e.Message, exc_info = True)
oops = PyQt4.QtGui.QMessageBox.critical(None, 'RezzMe', e.Message)
logging.critical('rezzme.main: exiting with retval 1')
sys.exit(1)
except BaseException, e:
logging.critical('rezzme.main: caught base exception: %s', str(e), exc_info = True)
sys.exit(2)
logging.debug('rezzme.main: exiting normally with retval 0')
if onMacOSX:
AppleEvents.stopeventloop()
sys.exit(0)