Added cmd options '--locate=all/clt/local/remote' in cl-template.

netsetup
Самоукин Алексей 14 years ago
parent 6be747767c
commit f8e82e5321

@ -124,7 +124,7 @@ subdirectories %s")%', '.join(dirsTemplates))
else: else:
self.clVars.printVars() self.clVars.printVars()
def applyAllTemplates(self): def applyAllTemplates(self, location="all"):
"""Обновление конфигурационных файлов""" """Обновление конфигурационных файлов"""
if not "calculate-install" in self.installProgs: if not "calculate-install" in self.installProgs:
self.printERROR(_("Can not installed %s") self.printERROR(_("Can not installed %s")
@ -150,8 +150,21 @@ subdirectories %s")%', '.join(dirsTemplates))
oldPymPath = os.path.abspath(pymPath) oldPymPath = os.path.abspath(pymPath)
clVars = DataVarsObject(sectName) clVars = DataVarsObject(sectName)
clVars.importDataObject() clVars.importDataObject()
if location in ("local","remote"):
listTemplatePaths = clVars.Get("cl_template_path")
if len(listTemplatePaths) != 3:
self.printERROR(\
_("Error in template variable 'cl_template_path=%s'")\
%str(listTemplatePaths))
return False
elif location=="local":
clVars.Set("cl_template_path", [listTemplatePaths[1]],
True)
elif location=="remote":
clVars.Set("cl_template_path", [listTemplatePaths[2]],
True)
# merge # merge
clVars.Set("cl_action", "merge", True) clVars.Set("cl_action", "merge" ,True)
# будут применены все шаблоны .clt (cltFilter=False) # будут применены все шаблоны .clt (cltFilter=False)
# и обычные шаблоны # и обычные шаблоны
clTempl = template(clVars, cltFilter=False) clTempl = template(clVars, cltFilter=False)

@ -26,16 +26,16 @@ USAGE = _("%prog [options] path_clt_file")
COMMENT_EXAMPLES = _("Apply all of the templates for all packages") COMMENT_EXAMPLES = _("Apply all of the templates for all packages")
EXAMPLES = _("%prog --all") EXAMPLES = _("%prog --locate all")
DESCRIPTION = _("The Calculate Linux utility to use templates") DESCRIPTION = _("The Calculate Linux utility to use templates")
CMD_OPTIONS = [{'longOption':"clt", CMD_OPTIONS = [{'longOption':"locate",
'optVal':"CLT_TEMPLATE", 'optVal':"LOCATE",
'help':_("process clt template (default)") 'type':'choice',
}, 'choices':['all','clt','local','remote'],
{'longOption':"all", 'help':_("select location templates \
'help':_("process all templates") 'all','clt'(default),'local','remote'")
}, },
{'shortOption':"v", {'shortOption':"v",
'longOption':"vars", 'longOption':"vars",
@ -56,55 +56,19 @@ class apply_template_cmd(share_cmd):
check_values=self.checkOpts) check_values=self.checkOpts)
# Создаем объект логики # Создаем объект логики
self.logicObj = updateConfFiles() self.logicObj = updateConfFiles()
# Названия несовместимых опций
self.optionsNamesIncompatible = ["all", "clt"]
# Названия обязательных опций
self.optionsNamesRequired = self.optionsNamesIncompatible + ["v"]
def getOptionsRequired(self, optObj):
"""Получаем обязательные опции"""
retList = []
for nameOpt in self.optionsNamesRequired:
retList.append(getattr(optObj, nameOpt))
return retList
def _getNamesAllSetOptions(self):
"""Выдает словарь измененных опций"""
setOptDict = self.optobj.values.__dict__.items()
defaultOptDict = self.optobj.get_default_values().__dict__.items()
return dict(set(setOptDict) - set(defaultOptDict)).keys()
def getStringIncompatibleOptions(self):
"""Форматированная строка несовместимых опций разделенных ','"""
listOpt = list(set(self.optionsNamesIncompatible) &\
set(self._getNamesAllSetOptions()))
return ", ".join(map(lambda x: len(x) == 1 and "'-%s'"%x or "'--%s'"%x,\
listOpt))
def checkOpts(self, optObj, args): def checkOpts(self, optObj, args):
"""Проверка опций командной строки""" """Проверка опций командной строки"""
if len(args)==0: if len(args) == 0:
optionsRequired = self.getOptionsRequired(optObj) if optObj.locate == "clt":
if len(filter(lambda x: x, optionsRequired))>1: errMsg = _("incorrect option")+":"+" --%s" %"locate" + " " + \
errMsg = _("incompatible options")+":"+" %s"\ str(optObj.locate)
%self.getStringIncompatibleOptions()
self.optobj.error(errMsg)
return False
elif not filter(lambda x: x, optionsRequired):
errMsg = _("required option")+":"+" %s"\
%" or ".join(map(lambda x:\
len(x) == 1 and "'-%s'"%x or "'--%s'"%x,\
self.optionsNamesRequired))
self.optobj.error(errMsg)
return False
elif len(args)==1:
if optObj.all:
errMsg = _("incorrect option")+":"+" --%s" %"all"
self.optobj.error(errMsg) self.optobj.error(errMsg)
return False return False
elif optObj.clt: elif len(args) == 1:
errMsg = _("incorrect option")+":"+" --%s" %"clt" if optObj.locate and optObj.locate != "clt":
errMsg = _("incorrect option")+":"+" --%s" %"locate" + " " + \
str(optObj.locate)
self.optobj.error(errMsg) self.optobj.error(errMsg)
return False return False
else: else:
@ -123,3 +87,13 @@ class apply_template_cmd(share_cmd):
def applyAllTemplates(self): def applyAllTemplates(self):
"""Применяем все шаблоны""" """Применяем все шаблоны"""
return self.logicObj.applyAllTemplates() return self.logicObj.applyAllTemplates()
def applyLocalTemplates(self):
"""We use local templates"""
return self.logicObj.applyAllTemplates(location="local")
def applyRemoteTemplates(self):
"""We use remote templates"""
return self.logicObj.applyAllTemplates(location="remote")

@ -39,18 +39,25 @@ if __name__ == "__main__":
# Печать переменных # Печать переменных
if options.v: if options.v:
obj.printVars(options) obj.printVars(options)
sys.exit(0)
# check root # check root
if not obj.isRoot(): if not obj.isRoot():
sys.exit(1) sys.exit(1)
if options.all: listLocate = options.locate
if listLocate:
if 'all' in listLocate:
# apply all templates # apply all templates
if not obj.applyAllTemplates(): if not obj.applyAllTemplates():
sys.exit(1) sys.exit(1)
elif options.clt: elif 'local' in listLocate:
# apply one clt template # apply local templates
if not obj.applyCltTemplate(options.clt): if not obj.applyLocalTemplates():
sys.exit(1)
elif 'remote' in listLocate:
# apply remote templates
if not obj.applyRemoteTemplates():
sys.exit(1) sys.exit(1)
elif args: if args:
cltPath = args[0] cltPath = args[0]
# apply one clt template # apply one clt template
if not obj.applyCltTemplate(cltPath): if not obj.applyCltTemplate(cltPath):

Loading…
Cancel
Save