Get the GNOME version

#!/usr/bin/env python

import os.path
import subprocess
import re

def _splitLines(string):
    ptn = re.compile('\n')
    return ptn.split(string)

def _ptnextract(string):
	ptn = re.compile('^.+(\d+).(\d+).(\d+).*$')
	(ver, rev1, rev2) = ptn.split(string)[1:4]
	return ver

gnomesessions='/usr/bin/gnome-session'
if os.path.exists(gnomesessions):
    print _ptnextract(subprocess.Popen([gnomesessions,'--version'], stdout=subprocess.PIPE).communicate()[0])

gnomeabout='/usr/bin/gnome-about'
if os.path.exists(gnomeabout):
    print _ptnextract(_splitLines(subprocess.Popen([gnomeabout,'--gnome-version'], stdout=subprocess.PIPE).communicate()[0])[0])

Recommended Posts

Get the GNOME version
How to get the Python version
Get the latest Linux kernel version with Arch Linux
Get the MIME Type
Align the version of chromedriver_binary
Automatically fetch the installed version
Get the number of digits
[Python] Get the previous month
Maya | Get the workspace path
Get and create nodes added and updated in the new version
Get only the Python version (such as 2.7.5) on the CentOS 7 shell
Get the package version to register with PyPI from Git
Test the version of the argparse module
Raise the version of pyenv itself
Get the number of views of Qiita
Change the background of Ubuntu (GNOME)
Get the complete bitflyer tick data
Get the desktop path in Python
Get the site update date seriously
Get the weather with Python requests
Get the weather with Python requests 2
pyenv-change the python version of virtualenv
Get the script path in Python
Get the attributes of an object
Change the Python version of Homebrew
Get the first element of queryset
Get the value from the [Django] Form
Get the number of Youtube subscribers
Get the desktop path in Python
Get the host name in Python
Get the address from the zip code
Python Note: Get the current month
Python version to get unused ports
Get the file path using Pathlib
Get the query string (query string) in Django
If you get a no attribute error in boto3, check the version
Get the client's IP address in Django
How to check the version of Django
Get the top nth values in Pandas
Get the column list & data list of CASTable
About the virtual environment of python version 3.7
[Python] Get the variable name with str
Get the minutes of the Diet via API
Install by specifying the version with pip
Get the path to the systemd unit file
[Python] Try pydash of the Python version of lodash
Get started with the documentation tool Sphinx
How to get colored output to the console
I can't get the element in Selenium!
Migemo version of the: find command,: mfind
Get the value of the middle layer of NN
Get holidays with the Google Calendar API
Get the last day of the specified month
[Python] Get the character code of the file
Get the filename of a directory (glob)
Get the EDINET code list in Python
Get the address from latitude and longitude
[PowerShell] Get the reading of the character string
Get wordpress posts from the past week
[Python] Get the main color from the screenshot
Get the hierarchy name using the OpenMaya iterator