MCPcopy Create free account
hub / github.com/ActiveState/code / Transfer

Class Transfer

recipes/Python/578907_Python_Awesome_DD/recipe-578907.py:254–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

252## Transfer class
253
254class Transfer(Output):
255 def __init__(
256 self,
257 src=None,
258 dst=None,
259 tsize=None,
260 bsize=40960,
261 count=None,
262 skip=None,
263 quiet=False
264 ):
265 Output.__init__(self)
266 self.src = src
267 self.dst = dst
268 self.bsize = bsize
269 self.tsize = tsize
270 self.count = count # TODO: Impliment
271 self.skip = skip # TODO: Impliment
272 self.quiet = quiet
273 # Lets set our total size for display purposes
274 if self.count:
275 self.src.size = (self.bsize * self.count)
276 # if we have set our total_size via an argument, lets go ahead, and set that
277 try:
278 if self.tsize:
279 self.src.size = self.tsize
280 elif not self.tsize and not os.path.isfile(self.src.target.name):
281 self.src.size = -1
282 except AttributeError:
283 self.src.size = int(self.src.target.headers['content-length'])
284 except:
285 self.src.size = -1
286
287 def start(self):
288 blocks = 0
289 totsze = 0
290
291 try:
292 st = time.time()
293 buff = self.src.read(self.bsize)
294 while buff:
295 if totsze <= self.src.size or self.src.size == -1:
296 self.dst.write(buff)
297 blocks += 1
298 totsze += len(buff)
299 if self.src.size != -1:
300 self.display(self.src.size, totsze, totsze, st)
301 else:
302 self.display(None, totsze, totsze, st)
303 buff = self.src.read(self.bsize)
304 else:
305 buff = None
306 time.sleep(1)
307 self.display(self.src.size, self.src.size, self.src.size, st)
308 print
309 except KeyboardInterrupt:
310 print
311 sys.exit(1)

Callers 1

recipe-578907.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected