#!/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