diff options
author | Dr Scofield | 2008-10-01 20:18:57 +0000 |
---|---|---|
committer | Dr Scofield | 2008-10-01 20:18:57 +0000 |
commit | e7cd583c1edcea7f600064fac89a94a52a84a553 (patch) | |
tree | 91be8efa11dad887b2e985fcdc0e4b8dbac2c4eb /share/python/matrix | |
parent | remove tests for inventory (diff) | |
download | opensim-SC_OLD-e7cd583c1edcea7f600064fac89a94a52a84a553.zip opensim-SC_OLD-e7cd583c1edcea7f600064fac89a94a52a84a553.tar.gz opensim-SC_OLD-e7cd583c1edcea7f600064fac89a94a52a84a553.tar.bz2 opensim-SC_OLD-e7cd583c1edcea7f600064fac89a94a52a84a553.tar.xz |
removing asterisk: it's now living at http://forge.opensimulator.org/gf/project/asteriskvoice/
Diffstat (limited to 'share/python/matrix')
-rwxr-xr-x | share/python/matrix/matrix.py | 272 |
1 files changed, 0 insertions, 272 deletions
diff --git a/share/python/matrix/matrix.py b/share/python/matrix/matrix.py deleted file mode 100755 index be7ec25..0000000 --- a/share/python/matrix/matrix.py +++ /dev/null | |||
@@ -1,272 +0,0 @@ | |||
1 | #!/usr/bin/python | ||
2 | # -*- encoding: utf-8 -*- | ||
3 | # Copyright (c) Contributors, http://opensimulator.org/ | ||
4 | # See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
5 | # | ||
6 | # Redistribution and use in source and binary forms, with or without | ||
7 | # modification, are permitted provided that the following conditions are met: | ||
8 | # * Redistributions of source code must retain the above copyright | ||
9 | # notice, this list of conditions and the following disclaimer. | ||
10 | # * Redistributions in binary form must reproduce the above copyright | ||
11 | # notice, this list of conditions and the following disclaimer in the | ||
12 | # documentation and/or other materials provided with the distribution. | ||
13 | # * Neither the name of the OpenSim Project nor the | ||
14 | # names of its contributors may be used to endorse or promote products | ||
15 | # derived from this software without specific prior written permission. | ||
16 | # | ||
17 | # THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR | ||
18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
19 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
20 | # DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
21 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
22 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | ||
23 | # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
25 | # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
26 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
27 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | |||
29 | import xml.etree.ElementTree as ET | ||
30 | import re | ||
31 | import urllib | ||
32 | import urllib2 | ||
33 | import ConfigParser | ||
34 | import optparse | ||
35 | import os | ||
36 | import sys | ||
37 | |||
38 | def longHelp(): | ||
39 | print ''' | ||
40 | matrix.py is a little launcher tool that knows about the GridInfo | ||
41 | protocol. it expects the grid coordinates to be passed as a | ||
42 | command line argument either as a "matrix:" or as an "opensim:" style | ||
43 | URI: | ||
44 | |||
45 | matrix://osgrid.org:8002/ | ||
46 | |||
47 | you can also provide region/X/Y/Z coordinates: | ||
48 | |||
49 | matrix://osgrid.org:8002/Wright%20Plaza/128/50/75 | ||
50 | |||
51 | and, it also understands avatar names and passwords: | ||
52 | |||
53 | matrix://mr%20smart:secretpassword@osgrid.org:8002/Wright%20Plaza/128/50/75 | ||
54 | |||
55 | when you run it the first time, it will complain about a missing | ||
56 | .matrixcfg file --- this is needed so that it can remember where your | ||
57 | secondlife client lives on your box. to generate that file, simply run | ||
58 | |||
59 | matrix.py --secondlife path-to-your-secondlife-client-executable | ||
60 | |||
61 | ''' | ||
62 | |||
63 | def ParseOptions(): | ||
64 | '''Parse the command line options and setup options. | ||
65 | ''' | ||
66 | |||
67 | parser = optparse.OptionParser() | ||
68 | parser.add_option('-c', '--config', dest = 'config', help = 'config file', metavar = 'CONFIG') | ||
69 | parser.add_option('-s', '--secondlife', dest = 'client', help = 'location of secondlife client', metavar = 'SL-CLIENT') | ||
70 | parser.add_option('-l', '--longhelp', action='store_true', dest = 'longhelp', help = 'longhelp') | ||
71 | (options, args) = parser.parse_args() | ||
72 | |||
73 | if options.longhelp: | ||
74 | parser.print_help() | ||
75 | longHelp() | ||
76 | sys.exit(0) | ||
77 | |||
78 | return options | ||
79 | |||
80 | def ParseConfig(options): | ||
81 | '''Ensure configuration exists and parse it. | ||
82 | ''' | ||
83 | # | ||
84 | # we are using ~/.matrixcfg to store the location of the | ||
85 | # secondlife client, os.path.normpath and os.path.expanduser | ||
86 | # should make sure that we are fine cross-platform | ||
87 | # | ||
88 | if not options.config: | ||
89 | options.config = '~/.matrixcfg' | ||
90 | |||
91 | cfgPath = os.path.normpath(os.path.expanduser(options.config)) | ||
92 | |||
93 | # | ||
94 | # if ~/.matrixcfg does not exist we are in trouble... | ||
95 | # | ||
96 | if not os.path.exists(cfgPath) and not options.client: | ||
97 | print '''oops, i've no clue where your secondlife client lives around here. | ||
98 | i suggest you run me with the "--secondlife path-of-secondlife-client" argument.''' | ||
99 | sys.exit(1) | ||
100 | |||
101 | # | ||
102 | # ok, either ~/.matrixcfg does exist or we are asked to create it | ||
103 | # | ||
104 | config = ConfigParser.ConfigParser() | ||
105 | if os.path.exists(cfgPath): | ||
106 | config.readfp(open(cfgPath)) | ||
107 | |||
108 | if options.client: | ||
109 | if config.has_option('secondlife', 'client'): | ||
110 | config.remove_option('secondlife', 'client') | ||
111 | if not config.has_section('secondlife'): | ||
112 | config.add_section('secondlife') | ||
113 | config.set('secondlife', 'client', options.client) | ||
114 | |||
115 | cfg = open(cfgPath, mode = 'w+') | ||
116 | config.write(cfg) | ||
117 | cfg.close() | ||
118 | |||
119 | return config.get('secondlife', 'client') | ||
120 | |||
121 | |||
122 | # | ||
123 | # regex: parse a URI | ||
124 | # | ||
125 | reURI = re.compile(r'''^(?P<scheme>[a-zA-Z0-9]+):// # scheme | ||
126 | ((?P<avatar>[^:@]+)(:(?P<password>[^@]+))?@)? # avatar name and password (optional) | ||
127 | (?P<host>[^:/]+)(:(?P<port>\d+))? # host, port (optional) | ||
128 | (?P<path>/.*) # path | ||
129 | $''', re.IGNORECASE | re.VERBOSE) | ||
130 | |||
131 | # | ||
132 | # regex: parse path as location | ||
133 | # | ||
134 | reLOC = re.compile(r'''^/(?P<region>[^/]+)/ # region name | ||
135 | (?P<x>\d+)/ # X position | ||
136 | (?P<y>\d+)/ # Y position | ||
137 | (?P<z>\d+) # Z position | ||
138 | ''', re.IGNORECASE | re.VERBOSE) | ||
139 | |||
140 | def ParseUri(uri): | ||
141 | '''Parse a URI and return its constituent parts. | ||
142 | ''' | ||
143 | |||
144 | match = reURI.match(uri) | ||
145 | if not match or not match.group('scheme') or not match.group('host'): | ||
146 | print 'hmm... cannot parse URI %s, giving up' % uri | ||
147 | sys.exit(1) | ||
148 | |||
149 | scheme = match.group('scheme') | ||
150 | host = match.group('host') | ||
151 | port = match.group('port') | ||
152 | avatar = match.group('avatar') | ||
153 | password = match.group('password') | ||
154 | path = match.group('path') | ||
155 | |||
156 | return (scheme, host, port, avatar, password, path) | ||
157 | |||
158 | def ParsePath(path): | ||
159 | '''Try and parse path as /region/X/Y/Z. | ||
160 | ''' | ||
161 | |||
162 | loc = None | ||
163 | match = reLOC.match(path) | ||
164 | if match: | ||
165 | loc = 'secondlife:///%s/%d/%d/%d' % (match.group('region'), | ||
166 | int(match.group('x')), | ||
167 | int(match.group('y')), | ||
168 | int(match.group('z'))) | ||
169 | return loc | ||
170 | |||
171 | |||
172 | def GetGridInfo(host, port): | ||
173 | '''Invoke /get_grid_info on target grid and obtain additional parameters | ||
174 | ''' | ||
175 | |||
176 | gridname = None | ||
177 | gridnick = None | ||
178 | login = None | ||
179 | welcome = None | ||
180 | economy = None | ||
181 | |||
182 | # | ||
183 | # construct GridInfo URL | ||
184 | # | ||
185 | if port: | ||
186 | gridInfoURI = 'http://%s:%d/get_grid_info' % (host, int(port)) | ||
187 | else: | ||
188 | gridInfoURI = 'http://%s/get_grid_info' % (host) | ||
189 | |||
190 | # | ||
191 | # try to retrieve GridInfo | ||
192 | # | ||
193 | try: | ||
194 | gridInfoXml = ET.parse(urllib2.urlopen(gridInfoURI)) | ||
195 | |||
196 | gridname = gridInfoXml.findtext('/gridname') | ||
197 | gridnick = gridInfoXml.findtext('/gridnick') | ||
198 | login = gridInfoXml.findtext('/login') | ||
199 | welcome = gridInfoXml.findtext('/welcome') | ||
200 | economy = gridInfoXml.findtext('/economy') | ||
201 | authenticator = gridInfoXml.findtext('/authenticator') | ||
202 | |||
203 | except urllib2.URLError: | ||
204 | print 'oops, failed to retrieve grid info, proceeding with guestimates...' | ||
205 | |||
206 | return (gridname, gridnick, login, welcome, economy) | ||
207 | |||
208 | |||
209 | def StartClient(client, nick, login, welcome, economy, avatar, password, location): | ||
210 | clientArgs = [ client ] | ||
211 | clientArgs += ['-loginuri', login] | ||
212 | |||
213 | if welcome: clientArgs += ['-loginpage', welcome] | ||
214 | if economy: clientArgs += ['-helperuri', economy] | ||
215 | |||
216 | if avatar and password: | ||
217 | clientArgs += ['-login'] | ||
218 | clientArgs += urllib.unquote(avatar).split() | ||
219 | clientArgs += [password] | ||
220 | |||
221 | if location: | ||
222 | clientArgs += [location] | ||
223 | |||
224 | # | ||
225 | # all systems go | ||
226 | # | ||
227 | os.execv(client, clientArgs) | ||
228 | |||
229 | |||
230 | if __name__ == '__main__': | ||
231 | # | ||
232 | # parse command line options and deal with help requests | ||
233 | # | ||
234 | options = ParseOptions() | ||
235 | client = ParseConfig(options) | ||
236 | |||
237 | # | ||
238 | # sanity check: URI supplied? | ||
239 | # | ||
240 | if not sys.argv: | ||
241 | print 'missing opensim/matrix URI' | ||
242 | sys.exit(1) | ||
243 | |||
244 | # | ||
245 | # parse URI and extract scheme. host, port?, avatar?, password? | ||
246 | # | ||
247 | uri = sys.argv.pop() | ||
248 | (scheme, host, port, avatar, password, path) = ParseUri(uri) | ||
249 | |||
250 | # | ||
251 | # sanity check: matrix: or opensim: scheme? | ||
252 | # | ||
253 | if scheme != 'matrix' and scheme != 'opensim': | ||
254 | print 'hmm...unknown scheme %s, calling it a day' % scheme | ||
255 | |||
256 | # | ||
257 | # get grid info from OpenSim server | ||
258 | # | ||
259 | (gridname, gridnick, login, welcome, economy) = GetGridInfo(host, port) | ||
260 | |||
261 | # | ||
262 | # fallback: use supplied uri in case GridInfo drew a blank | ||
263 | # | ||
264 | if not login: login = uri | ||
265 | |||
266 | # | ||
267 | # take a closer look at path: if it's a /region/X/Y/Z pattern, use | ||
268 | # it as the "SLURL | ||
269 | # | ||
270 | location = ParsePath(path) | ||
271 | StartClient(client, gridnick, login, welcome, economy, avatar, password, location) | ||
272 | |||