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-2.2-lib/pym/update_config/cl_update_config_cmd.py

118 lines
5.0 KiB

#-*- coding: utf-8 -*-
# Copyright 2010 Mir 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.
from update_config.cl_update_config import __app__, __version__,\
updateSystemConfigs, updateUserConfigs
from cl_print import color_print as old_color_print
from cl_opt import opt
import sys
import cl_lang
# Перевод модуля
tr = cl_lang.lang()
tr.setLocalDomain('cl_lib')
tr.setLanguage(sys.modules[__name__])
# Использование программы
USAGE = _("%prog [options] package_name")
# Коментарии к использованию программы
COMMENT_EXAMPLES = _("Update configuration files of package nss_ldap")
# Пример использования программы
EXAMPLES = _("%prog --system --path / nss_ldap")
# Описание программы (что делает программа)
DESCRIPTION = _("Update configuration files package installed")
# Опции командной строки
CMD_OPTIONS=[{'longOption':"system",
'help':_("update system configuration files")},
{'longOption':"desktop",
'help':_("update desktop (user) configuration files")},
{'longOption':"path",
'optVal':"PATH",
'help':_("root path for saving the updated configuration files")}]
class update_cmd:
def __init__(self):
# Объект опций командной строки
self.optobj = opt(\
package=__app__,
version=__version__,
usage=USAGE,
examples=EXAMPLES,
comment_examples=COMMENT_EXAMPLES,
description=DESCRIPTION,
option_list=CMD_OPTIONS + opt.color_control,
check_values=self.checkOpts)
# Создаем объекты логики
self.logicSystemObj = updateSystemConfigs()
self.logicUserObj = updateUserConfigs()
def setPrintNoColor(self, optObj):
"""Установка печати сообщений без цвета"""
if optObj.color and optObj.color=="never":
old_color_print.colorPrint = lambda *arg: \
sys.stdout.write(arg[-1]) or\
sys.stdout.flush()
def checkOpts(self, optObj, args):
"""Проверка опций командной строки"""
if not args:
errMsg = _("no such argument") + ":" + " %s" %USAGE.split(" ")[-1]
self.optobj.error(errMsg)
return False
if len(args)>1:
errMsg = _("incorrect argument") + ":" + " %s" %" ".join(args)
self.optobj.error(errMsg)
return False
if optObj.system and not optObj.path:
errMsg = _("no such option") + ":" + " --path"
self.optobj.error(errMsg)
return False
if not filter(lambda x: x, [optObj.system, optObj.desktop]):
errMsg = _("no such options") + ":" + " --system " + _("or") +\
" --desktop"
self.optobj.error(errMsg)
return False
return optObj, args
def updateSystemConfig(self, nameProgram, configPath):
"""Обновление системных конфигурационных файлов"""
# Проверка есть ли в пакете защищенные конфигурационные файлы
if not self.logicSystemObj.isExistsProtectFiles(configPath):
self.logicSystemObj.logger.info(_("Package %s") %nameProgram)
self.logicSystemObj.logger.warn(_("Not found protected files"))
return True
# Обновление конфигурационных файлов
if not self.logicSystemObj.updateConfig(nameProgram, configPath):
return False
return True
def updateUserConfig(self, nameProgram):
"""Обновление конфигурационных файлов для пользователей в X сеансах"""
# Пользователи в X сессии
xUsers = self.logicUserObj.getXUsers()
if not xUsers:
self.logicUserObj.logger.info(_("Package %s") %nameProgram)
self.logicUserObj.logger.warn(_("Not found X sessions users"))
return True
# Обновление конфигурационных файлов
if not self.logicUserObj.updateConfig(nameProgram, xUsers):
return False
return True