ATAJOS DE WINDOWS. Los diferentes atajos para utilizar en windows y ser más e...
Programando Cross-Platform: cosas a tener en cuenta para no quedarte pelado
1. Programando Cross Platform
Programación Cross-Platform
Cosas a tener en cuenta para no quedarte pelado
Roberto Alsina <ralsina@kde.org>
Manuel de la Peña <manuel@canonical.com>
PyCon Argentina 2011
4. Programando Cross Platform
¿Cuántas plataformas estamos hablando?
• Linux (GNOME/KDE/Unity/ninguno)
• Windows (XP/Vista/7/8)
• Mac
• Mobile (Android/iOS)
• Web (Chrome/Firefox/Safari/Mobile browsers/IE x.x)
PyCon Argentina 2011
5. Programando Cross Platform
¡Nos mudamos a la web!
• La web no es una única plataforma
• Se puede ser web y no ser cross-platform
• Se puede ser web y ser desktop (aplicaciones mixtas)
PyCon Argentina 2011
10. Programando Cross Platform
Filesystems
Cuando se trabaja con diferentes filesystems se ha de tener cuidado con los siguientes
temas:
• Paths: Como han de manajarse los paths. Es os.path suficiente?
• Eventos: Que eventos recibimos del fs cuando se editan los archivos.
• Unicode vs Binary
• User rights.
PyCon Argentina 2011
11. Programando Cross Platform
Filesystems
Problemas de Paths:
• Caracteres illegales * Linux: / null * Mac OS X: :/ null * Windows:
• DOS Fat32: x00-x1F SPACE DEL " * / : < > ? |
• Windows NTFS: " * : < > ? / |
PyCon Argentina 2011
13. Programando Cross Platform
Filesystems
Aggg.... tus paths son demasiado largos.
• Windows:
• Old school: Path maximo es de 255 char
• NTFS: Cada componente del path puede ser de 255
PyCon Argentina 2011
15. Programando Cross Platform
Filesystems
Windows: Vamos a jugar al teto, tú te agachas y yo te la meto:
Nombre illegales:
• AUX
• CLOCK$
• COM[0-9]
• CON
• LPT[1-9]
• NUL
• PRN
PyCon Argentina 2011
16. Programando Cross Platform
Esto incluye todos los nombres ya mencionados incluyendo la extension (AUX.txt). Pero
es windwos... se puede usar si se usa ?WTF?!?!
PyCon Argentina 2011
17. Programando Cross Platform
Eventos
Queremos recibir eventos cuando una archivo es modificado:
• Linux: pyinotify
• Windows: ReadDirecotryChangesW
• Mac OS X: FSEvents
PyCon Argentina 2011
18. Programando Cross Platform
Eventos
Los diferentes FS tienen diferentes APIs:
• Linux: Por directorio
• Windows: Por árbol
• Mac OS X: Por árbol
PyCon Argentina 2011
19. Programando Cross Platform
Eventos
Los diferentes FS tienes diferentes eventos:
• Linux:
pyinotify.IN_OPEN
pyinotify.IN_CLOSE_NOWRITE
pyinotify.IN_CLOSE_WRITE
pyinotify.IN_CREATE
pyinotify.IN_CREATE | pyinotify.IN_ISDIR
• Windows:
1: IN_CREATE
2: IN_DELETE
PyCon Argentina 2011
20. Programando Cross Platform
3: IN_MODIFY
4: IN_MOVED_FROM
5: IN_MOVED_TO
• Mac OS X:
PyCon Argentina 2011
22. Programando Cross Platform
User rights
o.chmod si, pero no!
• Linux: Ok
• Mac OS X: Ok
• Windows: AddAccessAllowedAceEx, AddAccessDeniedAceEx
PyCon Argentina 2011
23. Programando Cross Platform
User rights Windows
security_descriptor = GetFileSecurity(path, DACL_SECURITY_INFORMATION)
dacl = ACL()
for group_sid, attributes in groups:
# set the attributes of the group only if not null
if attributes:
dacl.AddAccessAllowedAceEx(ACL_REVISION,
CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE, attributes,
group_sid)
# the dacl has all the info of the diff groups passed in the parameters
security_descriptor.SetSecurityDescriptorDacl(1, dacl, 0)
SetFileSecurity(path, DACL_SECURITY_INFORMATION, security_descriptor)
PyCon Argentina 2011
24. Programando Cross Platform
IPC
Formas de hacer ipc:
• Linux: Dbus, tcp
• Windows: NamedPipes, tcp, Shared Memory
• Mac Os X: NSDistributedNotificationCenter or NSPortNameServer (mach ports)
Hay que abstraer la comunicación ya que cada uno tienes un estilo de exponer los
mensajes.
PyCon Argentina 2011