Mining Bits and Knowledge
Artigos com o marcador usb
Python e UDisks – Parte 5
05/07/11
| This post is also available in English |
Ressuscitando a série de artigos sobre Python e Udisks hoje vou mostrar como obter mais informações dos dispositivos através das propriedades.
Sobre o Atraso
Antes de tudo, peço desculpas pela demora em postar essa continuação, ela foi mais difícil de escrever do que parece. Essa demora se deve à mudança da forma como o DBus se comunica com o UDisks. Como tudo ainda é muito novo e não há um documentação completa e tão pouco tutoriais na internet, minhas buscas pela linha de erro não retornavam nenhum resultado. Abaixo está o código que eu estava utilizando e o erro que o DBus me apresentava:
>>> import dbus
>>>
>>> bus = dbus.SystemBus()
>>> proxy = bus.get_object("org.freedesktop.UDisks", "/org/freedesktop/UDisks")
>>> iface = dbus.Interface(proxy, "org.freedesktop.UDisks")
>>>
>>> devs = iface.EnumerateDevices()
>>> print devs
>>>
>>> device = devs[14]
>>> volume_obj = bus.get_object("org.freedesktop.UDisks", device)
>>> volume = dbus.Interface(volume_obj, "org.freedesktop.UDisks.Device")
>>> volume_obj.Get('','DriveConnectionInterface')
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 4 matched rules; type="method_call", sender=":1.60" (uid=1000 pid=19165 comm="/usr/bin/python2 ./test-me ") interface="(unset)" member="Get" error name="(unset)" requested_reply="0" destination=":1.19" (uid=0 pid=1010 comm="/usr/lib/udisks/udisks-daemon ")
Após dias de pesquisas e tentativas frustradas resolvi fazer algo que muitos evitam: ler código fonte de outros projetos. Depois de algumas pesquisas acabei encontrando o projeto liveusb-creator que utiliza o UDisks e o DBus para detectar dispositivos removíveis. Minha solução estava no arquivo creator.py (mais especificamente no método handle_reply, linhas 445 a 450) disponível aqui.
Python and UDisks – Part 5
05/07/11
| Este post também está disponível em Português |
Resurrecting the blog series about Python and Udisks, today I’m going to talk about how to get some more informations about the devices using properties.
About the Delay
First of all, I apologize for the delay in posting this continuation, it was harder to write than it looks. The delay is due to a change in how DBus communicate with UDisks. Since everything is very new, the documentation isn’t complete and there is no tutorial on the internet. So, my search for the error line did not return any results. Below is the code I was using and the DBus error:
>>> import dbus
>>>
>>> bus = dbus.SystemBus()
>>> proxy = bus.get_object("org.freedesktop.UDisks", "/org/freedesktop/UDisks")
>>> iface = dbus.Interface(proxy, "org.freedesktop.UDisks")
>>>
>>> devs = iface.EnumerateDevices()
>>> print devs
>>>
>>> device = devs[14]
>>> volume_obj = bus.get_object("org.freedesktop.UDisks", device)
>>> volume = dbus.Interface(volume_obj, "org.freedesktop.UDisks.Device")
>>> volume_obj.Get('','DriveConnectionInterface')
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 4 matched rules; type="method_call", sender=":1.60" (uid=1000 pid=19165 comm="/usr/bin/python2 ./test-me ") interface="(unset)" member="Get" error name="(unset)" requested_reply="0" destination=":1.19" (uid=0 pid=1010 comm="/usr/lib/udisks/udisks-daemon ")
After some days of research and failed attempts I decided to do something that many people avoid: read the source code from other projects. After some research I found the liveusb-creator project, which use UDisks and DBus to detect new removable devices. My solution was in the creator.py file (more specifically at the method handle_reply, from lines 445 to 450) available here.
Python e UDisks – Parte 1
14/03/11
| This post is also available in English |
Recentemente recebi diversos contatos de pessoas querendo saber se o USBManager iria suportar ou não o DeviceKit/UDev, uma vez que o HAL foi oficialmente descontinuado, então acabei retomando o desenvolvimento desse aplicativo.
Acabei percebendo algumas diferenças e pouca referência na internet, por isso vou postar algumas informações a respeito do desenvolvimento usando o DBus e o DeviceKit para trabalhar com dispositivos de armazenamento via USB.
Há algum tempo, fiz uma pesquisa sobre Python e o DeviceKit e encontrei esse post: Accessing DeviceKit with DBus and Python. Eu havia feito alguns testes e o código funcionou perfeitamente. Escrevi algumas linhas a mais e guardei para mexer em um outro dia. Depois de muito tempo (e uma atualização de distribuição) resolvi mexer novamente no USBManager e percebi que o trecho de código não funciona mais:
>>> import dbus
>>>
>>> bus = dbus.SystemBus()
>>>
>>> proxy = bus.get_object("org.freedesktop.DeviceKit.Disks", "/org/freedesktop/DeviceKit/Disks")
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 244, in get_object
follow_name_owner_changes=follow_name_owner_changes)
File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 241, in __init__
self._named_service = conn.activate_name_owner(bus_name)
File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 183, in activate_name_owner
self.start_service_by_name(bus_name)
File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 281, in start_service_by_name
'su', (bus_name, flags)))
File "/usr/lib/pymodules/python2.6/dbus/connection.py", line 620, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.DeviceKit.Disks was not provided by any .service files
>>>
Python and UDisks – Part 1
14/03/11
| Este post também está disponível em Português |
Recently I received some requests asking is USBManager will someday support DeviceKit/UDev, since HAL is officially deprecated. After some researches I retook this application development.
During the research I found out some mismatching informations and a lack of examples, so I decided to post some informations about Python development with DeviceKit/UDev and DBus. I’ll cover essentially the USB storage devices issue.
Some months ago, I made a research about Python and DeviceKit and I ran into this blog post: Accessing DeviceKit with DBus and Python. I made some tests and the code worked properly. Then I wrote some more lines and leaved there for some months. Later, after a long time (and a distribution update) I retook the code to work on USBManager and noticed that it doesn’t work anymore:
>>> import dbus
>>>
>>> bus = dbus.SystemBus()
>>>
>>> proxy = bus.get_object("org.freedesktop.DeviceKit.Disks", "/org/freedesktop/DeviceKit/Disks")
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 244, in get_object
follow_name_owner_changes=follow_name_owner_changes)
File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 241, in __init__
self._named_service = conn.activate_name_owner(bus_name)
File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 183, in activate_name_owner
self.start_service_by_name(bus_name)
File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 281, in start_service_by_name
'su', (bus_name, flags)))
File "/usr/lib/pymodules/python2.6/dbus/connection.py", line 620, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.DeviceKit.Disks was not provided by any .service files
>>>





