home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / python-gnome2 / examples / vfs / sync-xfer.py < prev   
Encoding:
Python Source  |  2004-12-25  |  1.3 KB  |  47 lines

  1. #! /usr/bin/env python
  2. try:
  3.     import gnomevfs
  4. except ImportError:
  5.     import gnome.vfs as gnomevfs
  6.  
  7. import atexit
  8. import termios
  9. import sys
  10. from optparse import OptionParser
  11. import gc
  12.  
  13. def _restore_term_mode(fd, attr):
  14.     termios.tcsetattr(fd, termios.TCSADRAIN, attr)
  15.  
  16. def set_non_canonical(fd):
  17.     old = termios.tcgetattr(fd)
  18.     atexit.register(_restore_term_mode, fd, old)
  19.     new = termios.tcgetattr(fd)
  20.     new[3] = new[3] & ~termios.ICANON
  21.     termios.tcsetattr(fd, termios.TCSADRAIN, new)
  22.  
  23.  
  24. parser = OptionParser(usage="usage: %prog [options] source-uri dest-uri")
  25. options, args = parser.parse_args()
  26.  
  27. if len(args) != 2:
  28.     parser.error("wrong number of arguments")
  29.  
  30. src = gnomevfs.URI(args[0])
  31. dst = gnomevfs.URI(args[1])
  32.  
  33. def progress_info_cb(info, data):
  34.     assert data == 0x1234
  35.     try:
  36.         print "%s: %f %%\r" % (info.target_name,
  37.                                info.bytes_copied/float(info.bytes_total)*100),
  38.     except Exception, ex:
  39.         pass
  40.     return True
  41. set_non_canonical(sys.stdout)
  42. gnomevfs.xfer_uri(source_uri=src, target_uri=dst,
  43.                   xfer_options=gnomevfs.XFER_DEFAULT,
  44.                   error_mode=gnomevfs.XFER_ERROR_MODE_ABORT,
  45.                   overwrite_mode=gnomevfs.XFER_OVERWRITE_MODE_ABORT,
  46.                   progress_callback=progress_info_cb, data=0x1234)
  47.