#-*- 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 from cl_print import color_print from cl_utils import _error # Перевод сообщений для программы from cl_lang import lang lang().setLanguage(sys.modules[__name__]) class share_cmd(color_print, _error): """Класс общих методов обработки опций командной строки""" def printVars(self, optObj): """Печать переменных""" if optObj.v: varsFilter = None varsNames = [] format = "default" # Фильтрование переменных if optObj.filter: optCmd = optObj.filter if ',' in optCmd: varsNames = optCmd.split(",") else: varsFilter = optCmd if optObj.xml: format = "xml" try: v = int(optObj.v) except: v = 1 self.logicObj.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 optObj.set: if not self.logicObj.clVars.WriteVars(): 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()