LoginSignup
0
0

More than 5 years have passed since last update.

GNOMEバージョンを取得する

Posted at
#!/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])
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0