forked from city41/mate-i3-applet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mate_version.py
50 lines (42 loc) · 1.25 KB
/
mate_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import logging
import re
import subprocess
import sys
from collections import namedtuple
MateVersion = namedtuple("MateVersion", ["major", "minor", "patch"])
pattern = re.compile(
b"(?P<major>\d+)\."
b"(?P<minor>\d+)\."
b"(?P<patch>\d+)"
)
def get_mate_version():
"""
Return namedtuple with major, minor and patch version of Mate
or None if Mate is not installed.
"""
try:
mate_about_output = subprocess.check_output(
("mate-about", "--version")
)
except FileNotFoundError:
logging.error("command mate-about was not found")
return None
match = pattern.search(mate_about_output)
return (MateVersion(
major=int(match.group("major")),
minor=int(match.group("minor")),
patch=int(match.group("patch")),
))
def import_gtk():
import gi
version = get_mate_version()
if version and version.major < 2 and version.minor < 16:
gi.require_version("Gtk", "2.0")
logging.debug("GTK 2.0 loaded")
elif version:
gi.require_version("Gtk", "3.0")
logging.debug("GTK 3.0 loaded")
else:
logging.error("MATE is not installed, stopping execution..")
sys.exit(1)
gi.require_version('MatePanelApplet', '4.0')