parent
6dac597c23
commit
b07681e60b
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1,103 @@
|
||||
#-*- 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 updateSystemConfigs, color_print,\
|
||||
__app__, __version__
|
||||
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.logicObj = updateSystemConfigs()
|
||||
|
||||
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 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.logicObj.isExistsProtectFiles(configPath):
|
||||
self.logicObj.logger.info(_("Package %s") %nameProgram)
|
||||
self.logicObj.logger.warn(_("Not found protected files"))
|
||||
return True
|
||||
# Обновление конфигурационных файлов
|
||||
if not self.logicObj.updateConfig(nameProgram, configPath):
|
||||
return False
|
||||
return True
|
@ -0,0 +1,43 @@
|
||||
#!/usr/bin/python
|
||||
#-*- 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.
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0,os.path.abspath('/usr/lib/calculate-2.2/calculate-lib/pym'))
|
||||
from update_config.cl_update_config_cmd import update_cmd
|
||||
import cl_lang
|
||||
# Перевод модуля
|
||||
tr = cl_lang.lang()
|
||||
tr.setLocalDomain('cl_lib')
|
||||
tr.setLanguage(sys.modules[__name__])
|
||||
|
||||
if __name__ == "__main__":
|
||||
obj = update_cmd()
|
||||
ret = obj.optobj.parse_args()
|
||||
if ret is False:
|
||||
sys.exit(1)
|
||||
opts, args = ret
|
||||
programName = args[0]
|
||||
# Установка цвета печати сообщений
|
||||
obj.setPrintNoColor(opts)
|
||||
# Выполняем логику программы
|
||||
if opts.system:
|
||||
if not obj.updateSystemConfig(programName, opts.path):
|
||||
sys.exit(1)
|
||||
if opts.desktop:
|
||||
pass
|
||||
sys.exit(0)
|
Loading…
Reference in new issue