|
|
|
@ -49,19 +49,45 @@ class VariableOsX11Resolution(Variable):
|
|
|
|
|
return "%sx%s" % (searchRes.group(1), searchRes.group(2))
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
def getResByXrandr(self):
|
|
|
|
|
"""Get resolution by xrandr utility"""
|
|
|
|
|
try:
|
|
|
|
|
processXrandr = process('xrandr')
|
|
|
|
|
if processXrandr.failed():
|
|
|
|
|
return ""
|
|
|
|
|
except (FilesError, OSError):
|
|
|
|
|
return ""
|
|
|
|
|
lines = processXrandr.readlines()
|
|
|
|
|
reRes = re.compile("current\s+(\d+)\s?x\s?(\d+)")
|
|
|
|
|
for line in lines:
|
|
|
|
|
searchRes = reRes.search(line)
|
|
|
|
|
if searchRes:
|
|
|
|
|
break
|
|
|
|
|
if searchRes:
|
|
|
|
|
return "%sx%s" % (searchRes.group(1), searchRes.group(2))
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
|
"""
|
|
|
|
|
Return current screen resolution (width, height).
|
|
|
|
|
Try detect by xdpyinfo, then Xorg.log, xorg.conf
|
|
|
|
|
"""
|
|
|
|
|
resolution = self.getResByXDpyInfo()
|
|
|
|
|
if resolution:
|
|
|
|
|
return resolution
|
|
|
|
|
#resolution = self.getResByXDpyInfo() or self.getResByXrandr()
|
|
|
|
|
#if resolution:
|
|
|
|
|
#return resolution
|
|
|
|
|
|
|
|
|
|
if self.Get('os_root_type') != 'usb-hdd':
|
|
|
|
|
xlog = "/var/log/Xorg.0.log"
|
|
|
|
|
if os.access(xlog, os.R_OK):
|
|
|
|
|
with open(xlog, 'r') as f:
|
|
|
|
|
logdata = f.read()
|
|
|
|
|
logdata = ''
|
|
|
|
|
encoding = ['utf-8', 'cp1252', 'utf-16']
|
|
|
|
|
for enc in encoding:
|
|
|
|
|
try:
|
|
|
|
|
with open(xlog, 'r', encoding=enc) as f:
|
|
|
|
|
logdata = f.read()
|
|
|
|
|
break
|
|
|
|
|
except UnicodeDecodeError:
|
|
|
|
|
continue
|
|
|
|
|
for re_pat in (
|
|
|
|
|
"Output [\S]+ using initial mode (\d+)x(\d+)",
|
|
|
|
|
"Virtual screen size determined to be"
|
|
|
|
|