maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Python3: detect we're on Fremantle, Harmattan, SailfishOS (https://talk.maemo.org/showthread.php?t=97230)

marmistrz 2016-08-13 15:11

Python3: detect we're on Fremantle, Harmattan, SailfishOS
 
In C++ w/ Qt we'd use
Code:

int foo() {
#if defined Q_WS_MAEMO5
/* */
#elif defined Q_WS_HARMATTAN
/* */
...
#endif
}

Can we do something like this in python3? I'd like to show a notification, which I can't do in a platform-agnostic way. (no libnotify on Fremantle)

otsaloma 2016-08-13 15:58

Re: Python3: detect we're on Fremantle, Harmattan, SailfishOS
 
Maybe something in platform? Sailfish below, I don't know what others return.

Code:

$ python3
Python 3.4.3 (default, May 12 2016, 02:20:34)
[GCC 4.8.3 20140106 (Mer 4.8.3-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'Linux-3.4.108.20160401.1-armv7l-with-glibc2.4'
>>> platform.uname()
uname_result(system='Linux', node='Sailfish', release='3.4.108.20160401.1', version='#1 SMP PREEMPT Thu May 12 02:21:45 UTC 2016', machine='armv7l', processor='armv7l')

Checking for the existance of a particular file or directory with os.path.isfile/isdir should be quite simple too if you know what to check -- e.g. /usr/lib/qt5/qml/Sailfish.

And in case you're calling executables like notify-send, you can check if they're available with shutil.which.

marmistrz 2016-08-13 16:23

Re: Python3: detect we're on Fremantle, Harmattan, SailfishOS
 
Quote:

Originally Posted by otsaloma (Post 1512468)
Maybe something in platform? Sailfish below, I don't know what others return.

Code:

$ python3
Python 3.4.3 (default, May 12 2016, 02:20:34)
[GCC 4.8.3 20140106 (Mer 4.8.3-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.platform()
'Linux-3.4.108.20160401.1-armv7l-with-glibc2.4'
>>> platform.uname()
uname_result(system='Linux', node='Sailfish', release='3.4.108.20160401.1', version='#1 SMP PREEMPT Thu May 12 02:21:45 UTC 2016', machine='armv7l', processor='armv7l')

Checking for the existance of a particular file or directory with os.path.isfile/isdir should be quite simple too if you know what to check -- e.g. /usr/lib/qt5/qml/Sailfish.

And in case you're calling executables like notify-send, you can check if they're available with shutil.which.

node returns the contents of /etc/hostname (uname -n), so it's not reliable.

That's what I thought about, but it's the last resort. I didn't find anything useful in the platform module.

Basically, I use the Python example from here [1] to show the notification on desktop. Since libnotify is unavailable, I guess I'll use a dbus call on Fremantle.


All times are GMT. The time now is 07:24.

vBulletin® Version 3.8.8