Recent Posts
C++ | 9 sec ago
Bash | 35 sec ago
XML | 1 min ago
OCaml | 1 min ago
None | 1 min ago
C++ | 1 min ago
None | 1 min ago
None | 2 min ago
XML | 2 min ago
XML | 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Canx on the 29th of Oct 2009 10:46:46 AM Download | Raw | Embed | Report
  1. #!/usr/bin/env python
  2. #
  3. # syncusb.py
  4. # Sincroniza bidireccionalmente un dispositivo extraible al montar y al desmontar.  
  5. # Autor: Canx (http://canx.blogspot.com)
  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="7F25-812D"
  19. origen="/media/TRAVELDRIVE/prueba/"
  20. destino="/home/kiwik/prueba/"
  21. # FIN CONFIGURACION
  22.  
  23. import subprocess
  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.                                 subprocess.call("unison -batch -perms 0 " + origen + " " + destino, shell=True)
  43.                                 syslog.syslog("sincronizacion completada!")
  44.                         else:
  45.                                 syslog.syslog("no existe algun directorio!")
  46.                 else:
  47.                         syslog.syslog("no es nuestro dispositivo!")
  48.                
  49.         def __init__(self):
  50.                 monitor = gio.volume_monitor_get()
  51.                 monitor.connect("mount-pre-unmount", self.mount_pre_unmount)
  52.                 monitor.connect("mount-added", self.mount_added)
  53.  
  54. with daemon.DaemonContext():
  55.         prueba = SyncPendrive()
  56.         loop = gobject.MainLoop()
  57.         loop.run()
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: