pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Python pastebin - collaborative debugging tool View Help


Posted by Canx on Thu 5 Nov 16:33 (modification of post by Canx view diff)
report abuse | download | new post

  1. #!/usr/bin/env python
  2. #
  3. # syncusb.py
  4. # Sincroniza bidireccionalmente un dispositivo extraible al montar y al desmontar.  
  5. # Autor: Canx
  6. # Requisitos: unison, python-gobject-dev
  7. #             python-daemon(http://pypi.python.org/pypi/python-daemon/)
  8.  
  9. # INSTALACION
  10. # 1.- Situar en el home con permisos de ejecucion.
  11. # 2.- Agregar en Sistemas->Preferencias->Aplicaciones de Inicio
  12.  
  13. # CONFIGURACION
  14. # uuid_usb -> identificador del dispositivo del tipo XXXX-XXXX (usar lsusb para averiguarlo)
  15. # origen -> directorio del dispositivo extraible
  16. # destino -> directorio local
  17.  
  18. uuid_usb="5842-B0AA"
  19. origen="/media/disk/Documentos/"
  20. destino="/home/canx/Documentos/"
  21. # FIN CONFIGURACION
  22.  
  23. from subprocess import Popen, PIPE, STDOUT
  24. import os
  25. import gobject
  26. import gio
  27. import daemon
  28. import syslog
  29.  
  30. class SyncPendrive:
  31.         def mount_pre_unmount(self, volume_monitor, drive):
  32.                 syslog.syslog("sincronizando al desmontar...")
  33.                 self.sincronizar(volume_monitor.get_mounts()[0].get_uuid())
  34.  
  35.         def mount_added(self, volume_monitor, drive):
  36.                 syslog.syslog("sincronizando al montar...")
  37.                 self.sincronizar(volume_monitor.get_mounts()[0].get_uuid())
  38.  
  39.         def sincronizar(self, uuid):
  40.                 if uuid == uuid_usb:
  41.                         if os.path.exists(origen) and os.path.exists(destino):                         
  42.                                 output = Popen(["unison", "-batch", "-perms", "0", origen, destino], stdout=PIPE).communicate()[0]
  43.                                 syslog.syslog(output)                          
  44.                                 syslog.syslog("sincronizacion completada!")
  45.                         else:
  46.                                 syslog.syslog("no existe algun directorio!")
  47.                 else:
  48.                         syslog.syslog(uuid + " no es nuestro dispositivo!")
  49.                
  50.         def __init__(self):
  51.                 monitor = gio.volume_monitor_get()
  52.                 monitor.connect("mount-pre-unmount", self.mount_pre_unmount)
  53.                 monitor.connect("mount-added", self.mount_added)
  54.  
  55. with daemon.DaemonContext():
  56.         # TODO: Solo arrancar si existe unison
  57.    
  58.         prueba = SyncPendrive()
  59.         loop = gobject.MainLoop()
  60.         loop.run()

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post