[svn r37838] Privatize attributes of rsync.py
--HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									66cf52a6e2
								
							
						
					
					
						commit
						026c2fa0bc
					
				|  | @ -18,11 +18,11 @@ class RSync(object): | ||||||
|     def __init__(self, callback=None, **options): |     def __init__(self, callback=None, **options): | ||||||
|         for name in options: |         for name in options: | ||||||
|             assert name in ('delete') |             assert name in ('delete') | ||||||
|         self.options = options |         self._options = options | ||||||
|         self.callback = callback |         self._callback = callback | ||||||
|         self.channels = {} |         self._channels = {} | ||||||
|         self.receivequeue = Queue() |         self._receivequeue = Queue() | ||||||
|         self.links = [] |         self._links = [] | ||||||
| 
 | 
 | ||||||
|     def filter(self, path): |     def filter(self, path): | ||||||
|         return True |         return True | ||||||
|  | @ -32,32 +32,32 @@ class RSync(object): | ||||||
|             and a remote destination directory.  |             and a remote destination directory.  | ||||||
|         """ |         """ | ||||||
|         def itemcallback(req): |         def itemcallback(req): | ||||||
|             self.receivequeue.put((channel, req)) |             self._receivequeue.put((channel, req)) | ||||||
|         channel = gateway.remote_exec(REMOTE_SOURCE) |         channel = gateway.remote_exec(REMOTE_SOURCE) | ||||||
|         channel.setcallback(itemcallback, endmarker = None) |         channel.setcallback(itemcallback, endmarker = None) | ||||||
|         channel.send((str(destdir), self.options)) |         channel.send((str(destdir), self._options)) | ||||||
|         self.channels[channel] = finishedcallback |         self._channels[channel] = finishedcallback | ||||||
| 
 | 
 | ||||||
|     def send(self, sourcedir): |     def send(self, sourcedir): | ||||||
|         """ Sends a sourcedir to all added targets.  |         """ Sends a sourcedir to all added targets.  | ||||||
|         """ |         """ | ||||||
|         self.sourcedir = str(sourcedir) |         self._sourcedir = str(sourcedir) | ||||||
|         # normalize a trailing '/' away |         # normalize a trailing '/' away | ||||||
|         self.sourcedir = os.path.dirname(os.path.join(self.sourcedir, 'x')) |         self._sourcedir = os.path.dirname(os.path.join(self._sourcedir, 'x')) | ||||||
|         # send directory structure and file timestamps/sizes |         # send directory structure and file timestamps/sizes | ||||||
|         self._send_directory_structure(self.sourcedir) |         self._send_directory_structure(self._sourcedir) | ||||||
| 
 | 
 | ||||||
|         # paths and to_send are only used for doing |         # paths and to_send are only used for doing | ||||||
|         # progress-related callbacks |         # progress-related callbacks | ||||||
|         self.paths = {} |         self._paths = {} | ||||||
|         self.to_send = {} |         self._to_send = {} | ||||||
| 
 | 
 | ||||||
|         # send modified file to clients |         # send modified file to clients | ||||||
|         while self.channels: |         while self._channels: | ||||||
|             channel, req = self.receivequeue.get() |             channel, req = self._receivequeue.get() | ||||||
|             if req is None: |             if req is None: | ||||||
|                 # end-of-channel |                 # end-of-channel | ||||||
|                 if channel in self.channels: |                 if channel in self._channels: | ||||||
|                     # too early!  we must have got an error |                     # too early!  we must have got an error | ||||||
|                     channel.waitclose() |                     channel.waitclose() | ||||||
|                     # or else we raise one |                     # or else we raise one | ||||||
|  | @ -66,25 +66,25 @@ class RSync(object): | ||||||
|             else: |             else: | ||||||
|                 command, data = req |                 command, data = req | ||||||
|                 if command == "links": |                 if command == "links": | ||||||
|                     for link in self.links: |                     for link in self._links: | ||||||
|                         channel.send(link) |                         channel.send(link) | ||||||
|                     # completion marker, this host is done |                     # completion marker, this host is done | ||||||
|                     channel.send(42) |                     channel.send(42) | ||||||
|                 elif command == "done": |                 elif command == "done": | ||||||
|                     finishedcallback = self.channels.pop(channel) |                     finishedcallback = self._channels.pop(channel) | ||||||
|                     if finishedcallback: |                     if finishedcallback: | ||||||
|                         finishedcallback() |                         finishedcallback() | ||||||
|                 elif command == "ack": |                 elif command == "ack": | ||||||
|                     if self.callback: |                     if self._callback: | ||||||
|                         self.callback("ack", self.paths[data], channel) |                         self._callback("ack", self._paths[data], channel) | ||||||
|                 elif command == "list_done": |                 elif command == "list_done": | ||||||
|                     # sum up all to send |                     # sum up all to send | ||||||
|                     if self.callback: |                     if self._callback: | ||||||
|                         s = sum([self.paths[i] for i in self.to_send[channel]]) |                         s = sum([self._paths[i] for i in self._to_send[channel]]) | ||||||
|                         self.callback("list", s, channel) |                         self._callback("list", s, channel) | ||||||
|                 elif command == "send": |                 elif command == "send": | ||||||
|                     modified_rel_path, checksum = data |                     modified_rel_path, checksum = data | ||||||
|                     modifiedpath = os.path.join(self.sourcedir, *modified_rel_path) |                     modifiedpath = os.path.join(self._sourcedir, *modified_rel_path) | ||||||
|                     try: |                     try: | ||||||
|                         f = open(modifiedpath, 'rb') |                         f = open(modifiedpath, 'rb') | ||||||
|                         data = f.read() |                         data = f.read() | ||||||
|  | @ -94,12 +94,12 @@ class RSync(object): | ||||||
|                     # provide info to progress callback function |                     # provide info to progress callback function | ||||||
|                     modified_rel_path = "/".join(modified_rel_path) |                     modified_rel_path = "/".join(modified_rel_path) | ||||||
|                     if data is not None: |                     if data is not None: | ||||||
|                         self.paths[modified_rel_path] = len(data) |                         self._paths[modified_rel_path] = len(data) | ||||||
|                     else: |                     else: | ||||||
|                         self.paths[modified_rel_path] = 0 |                         self._paths[modified_rel_path] = 0 | ||||||
|                     if channel not in self.to_send: |                     if channel not in self._to_send: | ||||||
|                         self.to_send[channel] = [] |                         self._to_send[channel] = [] | ||||||
|                     self.to_send[channel].append(modified_rel_path) |                     self._to_send[channel].append(modified_rel_path) | ||||||
| 
 | 
 | ||||||
|                     if data is not None: |                     if data is not None: | ||||||
|                         f.close() |                         f.close() | ||||||
|  | @ -118,11 +118,11 @@ class RSync(object): | ||||||
|                     assert "Unknown command %s" % command |                     assert "Unknown command %s" % command | ||||||
| 
 | 
 | ||||||
|     def _broadcast(self, msg): |     def _broadcast(self, msg): | ||||||
|         for channel in self.channels: |         for channel in self._channels: | ||||||
|             channel.send(msg) |             channel.send(msg) | ||||||
|      |      | ||||||
|     def _send_link(self, basename, linkpoint): |     def _send_link(self, basename, linkpoint): | ||||||
|         self.links.append(("link", basename, linkpoint)) |         self._links.append(("link", basename, linkpoint)) | ||||||
| 
 | 
 | ||||||
|     def _send_directory_structure(self, path): |     def _send_directory_structure(self, path): | ||||||
|         try: |         try: | ||||||
|  | @ -147,13 +147,13 @@ class RSync(object): | ||||||
|                 self._send_directory_structure(p) |                 self._send_directory_structure(p) | ||||||
|         elif stat.S_ISLNK(st.st_mode): |         elif stat.S_ISLNK(st.st_mode): | ||||||
|             linkpoint = os.readlink(path) |             linkpoint = os.readlink(path) | ||||||
|             basename = path[len(self.sourcedir) + 1:] |             basename = path[len(self._sourcedir) + 1:] | ||||||
|             if not linkpoint.startswith(os.sep): |             if not linkpoint.startswith(os.sep): | ||||||
|                 # relative link, just send it |                 # relative link, just send it | ||||||
|                 # XXX: do sth with ../ links |                 # XXX: do sth with ../ links | ||||||
|                 self._send_link(basename, linkpoint) |                 self._send_link(basename, linkpoint) | ||||||
|             elif linkpoint.startswith(self.sourcedir): |             elif linkpoint.startswith(self._sourcedir): | ||||||
|                 self._send_link(basename, linkpoint[len(self.sourcedir) + 1:]) |                 self._send_link(basename, linkpoint[len(self._sourcedir) + 1:]) | ||||||
|             else: |             else: | ||||||
|                 self._send_link(basename, linkpoint) |                 self._send_link(basename, linkpoint) | ||||||
|             self._broadcast(None) |             self._broadcast(None) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue