Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12702 > unrolled thread
| Started by | mukesh tiwari <mukeshtiwari.iiitm@gmail.com> |
|---|---|
| First post | 2011-09-03 07:40 -0700 |
| Last post | 2011-09-03 18:16 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
Reading pen drive data mukesh tiwari <mukeshtiwari.iiitm@gmail.com> - 2011-09-03 07:40 -0700
Re: Reading pen drive data mukesh tiwari <mukeshtiwari.iiitm@gmail.com> - 2011-09-03 09:21 -0700
Re: Reading pen drive data MRAB <python@mrabarnett.plus.com> - 2011-09-03 18:16 +0100
| From | mukesh tiwari <mukeshtiwari.iiitm@gmail.com> |
|---|---|
| Date | 2011-09-03 07:40 -0700 |
| Subject | Reading pen drive data |
| Message-ID | <3c05935f-3e0b-4b1b-afca-889c63e5b650@r8g2000prd.googlegroups.com> |
Hello all
I am trying to write a python script which can mount a pen drive and
read the data from pen drive. I am using pyudev [
http://packages.python.org/pyudev/api/index.html ] and wrote a small
python code
import pyudev, sys
if __name__ =="__main__":
context = pyudev.Context()
devices = context.list_devices(subsystem ="usb")
for device in devices :
print device
which prints
Device(u'/sys/devices/pci0000:00/0000:00:1a.0/usb3')
Device(u'/sys/devices/pci0000:00/0000:00:1a.0/usb3/3-0:1.0')
Device(u'/sys/devices/pci0000:00/0000:00:1a.1/usb4')
Device(u'/sys/devices/pci0000:00/0000:00:1a.1/usb4/4-0:1.0')
Device(u'/sys/devices/pci0000:00/0000:00:1a.2/usb5')
Device(u'/sys/devices/pci0000:00/0000:00:1a.2/usb5/5-0:1.0')
Device(u'/sys/devices/pci0000:00/0000:00:1a.7/usb1')
Device(u'/sys/devices/pci0000:00/0000:00:1a.7/usb1/1-0:1.0')
Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6')
Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6/6-0:1.0')
Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6/6-2')
Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6/6-2/6-2:1.0')
Device(u'/sys/devices/pci0000:00/0000:00:1d.1/usb7')
Device(u'/sys/devices/pci0000:00/0000:00:1d.1/usb7/7-0:1.0')
Device(u'/sys/devices/pci0000:00/0000:00:1d.2/usb8')
Device(u'/sys/devices/pci0000:00/0000:00:1d.2/usb8/8-0:1.0')
Device(u'/sys/devices/pci0000:00/0000:00:1d.7/usb2')
Device(u'/sys/devices/pci0000:00/0000:00:1d.7/usb2/2-0:1.0')
My problem is, how to know out of these usb which one to read . The
other solution I got is whenever I insert the pen drive , my system
mounts it in /media directory so I can read the /media directory to
check if its empty or not but this does not seems promising to me
because it may be possible that my system is not able to mount the pen
drive so I have to manually do it . Kindly some one please tell me
how to solve this problem.
[toc] | [next] | [standalone]
| From | mukesh tiwari <mukeshtiwari.iiitm@gmail.com> |
|---|---|
| Date | 2011-09-03 09:21 -0700 |
| Message-ID | <4ee9b05c-b1cf-4542-a3af-6a42b669c37f@a10g2000prn.googlegroups.com> |
| In reply to | #12702 |
On Sep 3, 7:40 pm, mukesh tiwari <mukeshtiwari.ii...@gmail.com> wrote:
> Hello all
> I am trying to write a python script which can mount a pen drive and
> read the data from pen drive. I am using pyudev [http://packages.python.org/pyudev/api/index.html] and wrote a small
> python code
>
> import pyudev, sys
> if __name__ =="__main__":
> context = pyudev.Context()
> devices = context.list_devices(subsystem ="usb")
> for device in devices :
> print device
>
> which prints
>
> Device(u'/sys/devices/pci0000:00/0000:00:1a.0/usb3')
> Device(u'/sys/devices/pci0000:00/0000:00:1a.0/usb3/3-0:1.0')
> Device(u'/sys/devices/pci0000:00/0000:00:1a.1/usb4')
> Device(u'/sys/devices/pci0000:00/0000:00:1a.1/usb4/4-0:1.0')
> Device(u'/sys/devices/pci0000:00/0000:00:1a.2/usb5')
> Device(u'/sys/devices/pci0000:00/0000:00:1a.2/usb5/5-0:1.0')
> Device(u'/sys/devices/pci0000:00/0000:00:1a.7/usb1')
> Device(u'/sys/devices/pci0000:00/0000:00:1a.7/usb1/1-0:1.0')
> Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6')
> Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6/6-0:1.0')
> Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6/6-2')
> Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6/6-2/6-2:1.0')
> Device(u'/sys/devices/pci0000:00/0000:00:1d.1/usb7')
> Device(u'/sys/devices/pci0000:00/0000:00:1d.1/usb7/7-0:1.0')
> Device(u'/sys/devices/pci0000:00/0000:00:1d.2/usb8')
> Device(u'/sys/devices/pci0000:00/0000:00:1d.2/usb8/8-0:1.0')
> Device(u'/sys/devices/pci0000:00/0000:00:1d.7/usb2')
> Device(u'/sys/devices/pci0000:00/0000:00:1d.7/usb2/2-0:1.0')
>
> My problem is, how to know out of these usb which one to read . The
> other solution I got is whenever I insert the pen drive , my system
> mounts it in /media directory so I can read the /media directory to
> check if its empty or not but this does not seems promising to me
> because it may be possible that my system is not able to mount the pen
> drive so I have to manually do it . Kindly some one please tell me
> how to solve this problem.
I got this link and its working fine [ http://packages.python.org/pyudev/api/monitor.html
]
>>> context = pyudev.Context()
>>> monitor = pyudev.Monitor.from_netlink(context)
>>> monitor.filter_by(subsystem='input')
>>> for action, device in monitor:
... print('{0}: {1}'.format(action, device))
but when I am trying to execute code [ http://packages.python.org/pyudev/api/toolkit.html
]
import pyudev, sys
context = pyudev.Context()
monitor = pyudev.Monitor.from_netlink(context)
monitor.filter_by(subsystem='usb')
observer = QUDevMonitorObserver(monitor)
def device_connected(device):
print('{0!r} added'.format(device))
observer.deviceAdded.connect(device_connected)
monitor.start()
I am getting
Traceback (most recent call last):
File "Mount.py", line 7, in <module>
observer = QUDevMonitorObserver(monitor)
NameError: name 'QUDevMonitorObserver' is not defined
Could any one please tell me how to avoid this error .
Thank you
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2011-09-03 18:16 +0100 |
| Message-ID | <mailman.739.1315070162.27778.python-list@python.org> |
| In reply to | #12705 |
On 03/09/2011 17:21, mukesh tiwari wrote:
> On Sep 3, 7:40 pm, mukesh tiwari<mukeshtiwari.ii...@gmail.com> wrote:
>> Hello all
>> I am trying to write a python script which can mount a pen drive and
>> read the data from pen drive. I am using pyudev [http://packages.python.org/pyudev/api/index.html] and wrote a small
>> python code
>>
>> import pyudev, sys
>> if __name__ =="__main__":
>> context = pyudev.Context()
>> devices = context.list_devices(subsystem ="usb")
>> for device in devices :
>> print device
>>
>> which prints
>>
>> Device(u'/sys/devices/pci0000:00/0000:00:1a.0/usb3')
>> Device(u'/sys/devices/pci0000:00/0000:00:1a.0/usb3/3-0:1.0')
>> Device(u'/sys/devices/pci0000:00/0000:00:1a.1/usb4')
>> Device(u'/sys/devices/pci0000:00/0000:00:1a.1/usb4/4-0:1.0')
>> Device(u'/sys/devices/pci0000:00/0000:00:1a.2/usb5')
>> Device(u'/sys/devices/pci0000:00/0000:00:1a.2/usb5/5-0:1.0')
>> Device(u'/sys/devices/pci0000:00/0000:00:1a.7/usb1')
>> Device(u'/sys/devices/pci0000:00/0000:00:1a.7/usb1/1-0:1.0')
>> Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6')
>> Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6/6-0:1.0')
>> Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6/6-2')
>> Device(u'/sys/devices/pci0000:00/0000:00:1d.0/usb6/6-2/6-2:1.0')
>> Device(u'/sys/devices/pci0000:00/0000:00:1d.1/usb7')
>> Device(u'/sys/devices/pci0000:00/0000:00:1d.1/usb7/7-0:1.0')
>> Device(u'/sys/devices/pci0000:00/0000:00:1d.2/usb8')
>> Device(u'/sys/devices/pci0000:00/0000:00:1d.2/usb8/8-0:1.0')
>> Device(u'/sys/devices/pci0000:00/0000:00:1d.7/usb2')
>> Device(u'/sys/devices/pci0000:00/0000:00:1d.7/usb2/2-0:1.0')
>>
>> My problem is, how to know out of these usb which one to read . The
>> other solution I got is whenever I insert the pen drive , my system
>> mounts it in /media directory so I can read the /media directory to
>> check if its empty or not but this does not seems promising to me
>> because it may be possible that my system is not able to mount the pen
>> drive so I have to manually do it . Kindly some one please tell me
>> how to solve this problem.
>
> I got this link and its working fine [ http://packages.python.org/pyudev/api/monitor.html
> ]
>>>> context = pyudev.Context()
>>>> monitor = pyudev.Monitor.from_netlink(context)
>>>> monitor.filter_by(subsystem='input')
>>>> for action, device in monitor:
> ... print('{0}: {1}'.format(action, device))
>
> but when I am trying to execute code [ http://packages.python.org/pyudev/api/toolkit.html
> ]
>
> import pyudev, sys
>
> context = pyudev.Context()
> monitor = pyudev.Monitor.from_netlink(context)
> monitor.filter_by(subsystem='usb')
> observer = QUDevMonitorObserver(monitor)
> def device_connected(device):
> print('{0!r} added'.format(device))
> observer.deviceAdded.connect(device_connected)
> monitor.start()
>
> I am getting
> Traceback (most recent call last):
> File "Mount.py", line 7, in<module>
> observer = QUDevMonitorObserver(monitor)
> NameError: name 'QUDevMonitorObserver' is not defined
>
> Could any one please tell me how to avoid this error .
> Thank you
I think you need to import it from pyudev.pyqt4.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web