maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Get ismi from dbus and python (https://talk.maemo.org/showthread.php?t=66344)

colchaodemola 2010-11-29 12:14

Get ismi from dbus and python
 
Hi guys , how can i convert the following statement to python + dbus ?

dbus-send --system --type=method_call --print-reply --dest=com.nokia.phone.SIM /com/nokia/phone/SIM Phone.Sim.get_imsi

noobmonkey 2010-11-29 12:29

Re: Get ismi from dbus and python
 
Check the current Healthcheck code ;) - it was done in python and uses dbus as well as terminal commands :)

(It will be replaced with a c++ version shortly though!)

But here's an example of using dbus from within python

Code:

def funcDevOri():
        print "** Start Function - Device Orientation **"
        bus = dbus.SystemBus()           
        accel = bus.get_object('com.nokia.mce','/com/nokia/mce/request','com.nokia.mce.request')

        orientation , stand , face , x , y , z = accel.get_device_orientation()
        return orientation


Or.....
(This is the one you want, as it gets the IMEI, so not too far from what you need!!)
Code:

def funcIMEI():
        print "** Start Function - Device IMEI **"
        b = os.popen('run-standalone.sh dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.SIM /com/nokia/phone/SIM/security Phone.Sim.Security.get_imei').read()
        b = str(b)
        b = b.strip()
        b = str(b)[-27:]
        b = b.strip()
        b = str(b)[:-12]
        return b

or

Code:

def FMTxPropertiesInterfaceConnect():
        bus = dbus.SystemBus()
        dbus_object = bus.get_object('com.nokia.FMTx', '/com/nokia/fmtx/default', False)
        dbus_interface = dbus.Interface(dbus_object, dbus_interface='org.freedesktop.DBus.Properties')
        return dbus_interface


colchaodemola 2010-12-01 23:34

Re: Get ismi from dbus and python
 
Quote:

Originally Posted by noobmonkey (Post 885514)
Check the current Healthcheck code ;) - it was done in python and uses dbus as well as terminal commands :)

(It will be replaced with a c++ version shortly though!)

But here's an example of using dbus from within python

Code:

def funcDevOri():
        print "** Start Function - Device Orientation **"
        bus = dbus.SystemBus()           
        accel = bus.get_object('com.nokia.mce','/com/nokia/mce/request','com.nokia.mce.request')

        orientation , stand , face , x , y , z = accel.get_device_orientation()
        return orientation


Or.....
(This is the one you want, as it gets the IMEI, so not too far from what you need!!)
Code:

def funcIMEI():
        print "** Start Function - Device IMEI **"
        b = os.popen('run-standalone.sh dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.SIM /com/nokia/phone/SIM/security Phone.Sim.Security.get_imei').read()
        b = str(b)
        b = b.strip()
        b = str(b)[-27:]
        b = b.strip()
        b = str(b)[:-12]
        return b

or

Code:

def FMTxPropertiesInterfaceConnect():
        bus = dbus.SystemBus()
        dbus_object = bus.get_object('com.nokia.FMTx', '/com/nokia/fmtx/default', False)
        dbus_interface = dbus.Interface(dbus_object, dbus_interface='org.freedesktop.DBus.Properties')
        return dbus_interface



isn't there a way to conver this statement to a python+dbus call...
Calling dbus-send sometimes blocks and i get zombie proccesses.

dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.SIM /com/nokia/phone/SIM/security Phone.Sim.Security.get_imei

noobmonkey 2010-12-02 08:53

Re: Get ismi from dbus and python
 
Hi colchaodemola,

not sure what you mean?
There are 3 different ways to do it above and the middle one will output the imei exactly as yuo want it in python?

colchaodemola 2010-12-02 09:58

Re: Get ismi from dbus and python
 
Hi noobmonkey, it is better i explain with examples:
i can turn this dbus-send call

dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"message"

IN

import dbus
bus = dbus.SystemBus()
iface = dbus.Interface(bus.get_object('org.freedesktop.Not ifications',
'/org/freedesktop/Notifications'),
'org.freedesktop.Notifications')
iface.SystemNoteInfoprint('message')


but how can i convert bus-send --system --print-reply --type=method_call --dest=com.nokia.phone.SIM /com/nokia/phone/SIM/security Phone.Sim.Security.get_imei' in to that second way ?

noobmonkey 2010-12-02 10:08

Re: Get ismi from dbus and python
 
Quote:

Originally Posted by colchaodemola (Post 887422)
Hi noobmonkey, it is better i explain with examples:
i can turn this dbus-send call

dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"message"

IN

import dbus
bus = dbus.SystemBus()
iface = dbus.Interface(bus.get_object('org.freedesktop.Not ifications',
'/org/freedesktop/Notifications'),
'org.freedesktop.Notifications')
iface.SystemNoteInfoprint('message')


but how can i convert bus-send --system --print-reply --type=method_call --dest=com.nokia.phone.SIM /com/nokia/phone/SIM/security Phone.Sim.Security.get_imei' in to that second way ?

import dbus
bus = dbus.SystemBus()
iface = dbus.Interface(bus.get_object('com.nokia.phone.SIM ',
'/com/nokia/phone/SIM/security Phone.Sim.Security.get_imei'),
iface.SystemNoteInfoprint('get_imei')

i think, not sure though, will take alook tonight :)

salatiel 2010-12-06 10:16

Re: Get ismi from dbus and python
 
import dbus

bus = dbus.SystemBus()
imsiObj = bus.get_object('com.nokia.phone.SIM', '/com/nokia/phone/SIM')
imsiiface = dbus.Interface(imsiObj, 'Phone.Sim')
print imsiiface.get_imsi()[0]


All times are GMT. The time now is 02:13.

vBulletin® Version 3.8.8