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.
96 lines
3.4 KiB
96 lines
3.4 KiB
#-*- coding: utf-8 -*-
|
|
|
|
# Copyright 2010 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 sys
|
|
import os
|
|
|
|
from cl_print import color_print
|
|
from cl_utils import _error
|
|
import cl_install
|
|
|
|
# Перевод сообщений для программы
|
|
from cl_lang import lang
|
|
lang().setLanguage(sys.modules[__name__])
|
|
import cl_overriding
|
|
|
|
class share_cmd(color_print, _error):
|
|
"""Класс общих методов обработки опций командной строки"""
|
|
def isRoot(self, printError=True):
|
|
"""Detect root user"""
|
|
if os.getuid() == 0 and os.getgid() == 0:
|
|
return True
|
|
else:
|
|
if printError:
|
|
self.printERROR(_("The user is not root"))
|
|
return False
|
|
|
|
def printVars(self, optObj):
|
|
"""Печать переменных"""
|
|
if optObj.v:
|
|
varsFilter = None
|
|
varsNames = []
|
|
format = "default"
|
|
# Фильтрование переменных
|
|
if optObj.filter:
|
|
optCmd = optObj.filter
|
|
if ',' in optCmd:
|
|
varsNames = optCmd.split(",")
|
|
elif '*' in optCmd:
|
|
varsFilter = optCmd.replace("*", ".*")
|
|
else:
|
|
varsNames.append(optCmd)
|
|
if optObj.xml:
|
|
format = "xml"
|
|
try:
|
|
v = int(optObj.v)
|
|
except:
|
|
v = 1
|
|
cl_overriding.exit = cl_install.defaultExit
|
|
cl_overriding.printERROR = cl_install.defaultPrintERROR
|
|
self.logicObj.clVars.printVars(varsFilter, varsNames,
|
|
outFormat=format,
|
|
verbose=v)
|
|
|
|
def setVars(self, optObj):
|
|
"""Установка переменных"""
|
|
if optObj.set:
|
|
for val in optObj.set:
|
|
k,o,v = val.partition('=')
|
|
if self.logicObj.clVars.exists(k):
|
|
if self.logicObj.clVars.SetWriteVar(k,v) == False:
|
|
return False
|
|
else:
|
|
self.printERROR(_('variable %s not found')%k)
|
|
return False
|
|
return True
|
|
|
|
def writeVars(self, optObj):
|
|
"""Запись переменных"""
|
|
if not self.logicObj.clVars.WriteVars(header="install"):
|
|
errMsg = self.getError()
|
|
if errMsg:
|
|
self.printERROR(errMsg.strip())
|
|
self.printERROR(_('Can not write template variables'))
|
|
return False
|
|
return True
|
|
|
|
def setPrintNoColor(self, optObj):
|
|
"""Установка печати сообщений без цвета"""
|
|
if optObj.color and optObj.color=="never":
|
|
color_print.colorPrint = lambda *arg : sys.stdout.write(arg[-1]) or\
|
|
sys.stdout.flush()
|
|
|