Changeset 2267:f475f0ece862
- Timestamp:
- 08/27/08 05:53:08 (3 months ago)
- Author:
- dunker@…
- Branch:
- default
- Message:
-
move asyncore.loop into RestClientAsync?
- Location:
- gozerbot
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r2253
|
r2267
|
|
| 1 | | # gozerbot/net/server.py |
| | 1 | # gozerbot/net/client.py |
| 2 | 2 | # |
| 3 | 3 | # |
| … |
… |
|
| 9 | 9 | class Client(RestClientAsync): |
| 10 | 10 | |
| 11 | | def get(self): |
| 12 | | self.sendget() |
| 13 | | |
| 14 | 11 | def auth(self, userhost, perm): |
| 15 | 12 | kwargs = {} |
-
|
r2266
|
r2267
|
|
| 12 | 12 | from gozerbot.datadir import datadir |
| 13 | 13 | from gozerbot.contrib.simplejson import dumps |
| 14 | | import asyncore, time, os |
| | 14 | import asyncore, time, os, random |
| 15 | 15 | |
| 16 | 16 | state = PersistState(datadir + os.sep + 'cloud') |
| 17 | 17 | state.define('nodes', []) |
| 18 | 18 | state.define('names', {}) |
| | 19 | |
| | 20 | CloudMap = {} |
| 19 | 21 | |
| 20 | 22 | class Node(object): |
| … |
… |
|
| 39 | 41 | self.client = Client(self.url + mount, self.name).addcb(cb) |
| 40 | 42 | self.client.get() |
| | 43 | return self.client |
| 41 | 44 | |
| 42 | 45 | def dopost(self, mount, cb, *args, **kwargs): |
| 43 | 46 | self.client = Client(self.url + mount, self.name).addcb(cb) |
| 44 | 47 | self.client.post(**kwargs) |
| | 48 | return self.client |
| 45 | 49 | |
| 46 | 50 | class Cloud(object): |
| … |
… |
|
| 89 | 93 | self.add(name, url) |
| 90 | 94 | self.boot(regname, regport, booturl) |
| 91 | | |
| | 95 | |
| 92 | 96 | def persist(self, name, url): |
| 93 | 97 | self.startup.set('start', name, url) |
| … |
… |
|
| 132 | 136 | for url, node in self.nodes.iteritems(): |
| 133 | 137 | node.doget(mount, *args, **kwargs) |
| 134 | | start_new_thread(asyncore.loop, (), {'use_poll': True }) |
| 135 | 138 | |
| 136 | 139 | def dopost(self, mount, *args, **kwargs): |
| 137 | 140 | for url, node in self.nodes.iteritems(): |
| 138 | 141 | node.dopost(mount, *args, **kwargs) |
| 139 | | start_new_thread(asyncore.loop, (), {'use_poll': True }) |
| 140 | 142 | |
| 141 | 143 | def getnodes(self): |
| … |
… |
|
| 157 | 159 | client = Client(url + '/gozernet/+join').addcb(cb) |
| 158 | 160 | client.post(name=regname, port=regport) |
| | 161 | CloudMap[url + str(random.random())] = client |
| 159 | 162 | |
| 160 | 163 | def joinall(self, regname, regport): |
| … |
… |
|
| 192 | 195 | gnode = self.add(node[0], node[1]) |
| 193 | 196 | gnode.synced = time.time() |
| 194 | | Client('%s/gozernet/nodes/' % url).addcb(cb).get() |
| | 197 | client = Client('%s/gozernet/nodes/' % url).addcb(cb) |
| | 198 | CloudMap[url + str(random.random())] = client |
| | 199 | client.get() |
| 195 | 200 | |
| 196 | 201 | def size(self): |
-
|
r2258
|
r2267
|
|
| 11 | 11 | from httplib import InvalidURL |
| 12 | 12 | from urlparse import urlparse |
| 13 | | import socket, asynchat, urllib, sys, thread, re |
| | 13 | import socket, asynchat, urllib, sys, thread, re, asyncore |
| 14 | 14 | |
| 15 | 15 | restlock = thread.allocate_lock() |
| … |
… |
|
| 234 | 234 | self.start() |
| 235 | 235 | self.push(s) |
| | 236 | asyncore.loop() |
| 236 | 237 | |
| 237 | 238 | def sendpost(self, postdata): |