/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/ftp.py

  • Committer: Alexander Belchenko
  • Date: 2007-10-04 05:50:44 UTC
  • mfrom: (2881 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2884.
  • Revision ID: bialix@ukr.net-20071004055044-pb88kgkfayawro8n
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
271
271
        abspath = self._remote_path(relpath)
272
272
        tmp_abspath = '%s.tmp.%.9f.%d.%d' % (abspath, time.time(),
273
273
                        os.getpid(), random.randint(0,0x7FFFFFFF))
 
274
        bytes = None
274
275
        if getattr(fp, 'read', None) is None:
275
 
            fp = StringIO(fp)
 
276
            # hand in a string IO
 
277
            bytes = fp
 
278
            fp = StringIO(bytes)
 
279
        else:
 
280
            # capture the byte count; .read() may be read only so
 
281
            # decorate it.
 
282
            class byte_counter(object):
 
283
                def __init__(self, fp):
 
284
                    self.fp = fp
 
285
                    self.counted_bytes = 0
 
286
                def read(self, count):
 
287
                    result = self.fp.read(count)
 
288
                    self.counted_bytes += len(result)
 
289
                    return result
 
290
            fp = byte_counter(fp)
276
291
        try:
277
292
            mutter("FTP put: %s", abspath)
278
293
            f = self._get_FTP()
279
294
            try:
280
295
                f.storbinary('STOR '+tmp_abspath, fp)
281
296
                self._rename_and_overwrite(tmp_abspath, abspath, f)
 
297
                if bytes is not None:
 
298
                    return len(bytes)
 
299
                else:
 
300
                    return fp.counted_bytes
282
301
            except (ftplib.error_temp,EOFError), e:
283
302
                warning("Failure during ftp PUT. Deleting temporary file.")
284
303
                try: