You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-utils-3-install/install/variables/X11.py

187 lines
7.7 KiB

#-*- coding: utf-8 -*-
# Copyright 2008-2012 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
import re
from os import path
from calculate.lib.datavars import Variables,VariableError
from calculate.lib.variables import X11
from calculate.lib.utils.portage import isPkgInstalled
from calculate.lib.utils.files import process,STDOUT,getProgPath
from calculate.lib.utils.common import (getVideoFromXorgLog,
getVideoFromXorgConf, getVideoFromCmdLine,
getAvailableVideo, getValueFromCmdLine,
getCompositeFromXorgconf, getVideoFromModules,
getVideoFromVendor,getInstalledVideo)
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_install',sys.modules[__name__])
class InstallX11(X11):
vars = ["os_install_x11_resolution","os_install_x11_video_drv",
"os_install_x11_composite","os_install_fb_resolution","hr_video_id"]
# xorg resolution
os_install_x11_resolution = {'mode':'w',
'type':'choiceedit',
'opt':['-X'],
'metavalue':"<width>x<height>",
'help':_("set Xorg resolution"),
'label':_("Screen resolution")}
# Video driver used by xorg
os_install_x11_video_drv = {'mode':'w',
'type':'choice',
'opt':['--video'],
'metavalue':"VIDEODRV",
'help':_("set the video driver"),
'label':_("{0} video driver").format("Xorg")}
# on/off composite
os_install_x11_composite = {'mode':'w',
'type':'bool',
'opt':['--composite'],
'help':_("set composite"),
'label':_("Composite")}
# fb resolution
os_install_fb_resolution = {'mode':'w',
'type':'choiceedit',
'opt':['--fb'],
'metavalue':"<width>x<height>",
'help':_("set framebuffer resolution"),
'label':_("Framebuffer resolution")}
# busid of video card
hr_video_id = {'value':""}
def choice_os_install_x11_video_drv(self):
"""Get available (already installed or installable drivers"""
image = self.Get('cl_image')
if image:
with image as distr:
distrPath = image.getDirectory()
if isPkgInstalled('xorg-server',prefix=distrPath):
return getAvailableVideo(prefix=distrPath)+['other']
return []
def get_os_install_x11_video_drv(self):
"""Get install video drv"""
# get available videodriver list from install or configure distributive
list_video = self.Choice('os_install_x11_video_drv')#getAvailableVideo(distrPath)
if not list_video:
return "other"
# if type system is usb-hdd then get detect video driver
if self.Get('os_install_root_type') == 'usb-hdd':
methods = ((getVideoFromModules,()),
(getVideoFromCmdLine,()),
(getVideoFromVendor,(self.Get('hr_video'),list_video)))
else:
# test current video driver for install system
methods = ((getVideoFromXorgLog,('/',list_video)),
(getVideoFromXorgConf,('/',)),
(getVideoFromModules,()),
(getVideoFromCmdLine,()),
(getVideoFromVendor,(self.Get('hr_video'),list_video)))
for func,args in methods:
drv = func(*args)
if drv in list_video:
return drv
return "other"
def choice_os_install_x11_resolution(self):
"""Sample resolutions"""
return ["800x600", "800x480", "640x480", "2560x1600", "2560x1440",
"2048x1152", "1920x1200", "1920x1080", "1680x945", "1680x1050",
"1600x900", "1600x768", "1600x1200", "1440x900", "1400x1050",
"1368x768", "1366x768", "1360x768", "1280x800", "1280x768",
"1280x720", "1280x1024", "1200x800", "1024x600", "1024x576",
"1024x768"]
def check_os_install_x11_resolution(self,value):
"""Check resolution"""
if not re.match('^\d+x\d+$',value):
raise VariableError(
_("Wrong resolution {resolution} {example}").format(
resolution=value,
example="(%s:%s)"%(_("Example"),"1024x768")))
def get_os_install_x11_resolution(self):
"""Xorg resolution"""
# get resolution from xorg.log
res = self.Get('os_x11_resolution')
if res or self.Get('os_install_root_type') in ('livecd','usb-hdd'):
return res
else:
return self.Choice('os_install_x11_resolution')[-1]
def get_os_install_x11_composite(self):
"""On/off composite"""
defaultCompositeOn = ("nvidia","intel","fglrx","nouveau","radeon")
composite = getValueFromCmdLine("calculate",5)
videodrv = getValueFromCmdLine("calculate",4)
if videodrv != "auto":
composite = {'nocomposite':'off',
'off':'off',
'on':'on',
'composite':'on'}.get(composite)
else:
composite = None
if self.Get('os_install_x11_video_drv') in defaultCompositeOn:
defaultComposite = "on"
else:
defaultComposite = "off"
if self.Get('os_install_x11_video_drv') == self.Get('os_x11_video_drv'):
state = getCompositeFromXorgconf()
else:
state = None
return composite or state or defaultComposite
choice_os_install_fb_resolution = choice_os_install_x11_resolution
check_os_install_fb_resolution = check_os_install_x11_resolution
def get_os_install_fb_resolution(self):
"""Get current framebuffer resolution"""
resolution = ""
fbres = getProgPath('/sbin/fbres')
if fbres:
processFbres = process(fbres,stderr=STDOUT)
textLines = processFbres.readlines()
if textLines:
cxx11,cyx11 = \
self.Get('os_install_x11_resolution').partition('x')[0::2]
cxfb, cyfb = textLines[0].partition('x')[0::2]
if not filter(lambda x:not x.isdigit(),
[cxfb,cyfb,cxx11,cyx11])and \
int(cxx11) >= int(cxfb) and int(cyx11) >= int(cyfb):
resolution = "%s-32"%textLines[0]
return resolution or "1024x768-32@60"
def uncompatible_video_vars(self):
"""
Network setting up unavailable for flash installation
"""
if self.Get('os_install_root_type') == 'flash':
return \
_("Video configuration unavailable for flash installation")
return ""
uncompatible_os_install_x11_video_drv = \
uncompatible_os_install_x11_resolution = \
uncompatible_os_install_fb_resolution = \
uncompatible_video_vars