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:
self.clVars.printVars()
def applyAllTemplates(self):
def applyAllTemplates(self, location="all"):
"""Обновление конфигурационных файлов"""
if not "calculate-install" in self.installProgs:
self.printERROR(_("Can not installed %s")
@ -150,8 +150,21 @@ subdirectories %s")%', '.join(dirsTemplates))
oldPymPath = os.path.abspath(pymPath)
clVars = DataVarsObject(sectName)
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
clVars.Set("cl_action", "merge", True)
clVars.Set("cl_action", "merge" ,True)
# будут применены все шаблоны .clt (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")
EXAMPLES = _("%prog --all")
EXAMPLES = _("%prog --locate all")
DESCRIPTION = _("The Calculate Linux utility to use templates")
CMD_OPTIONS = [{'longOption':"clt",
'optVal':"CLT_TEMPLATE",
'help':_("process clt template (default)")
},
{'longOption':"all",
'help':_("process all templates")
CMD_OPTIONS = [{'longOption':"locate",
'optVal':"LOCATE",
'type':'choice',
'choices':['all','clt','local','remote'],
'help':_("select location templates \
'all','clt'(default),'local','remote'")
},
{'shortOption':"v",
'longOption':"vars",
@ -56,55 +56,19 @@ class apply_template_cmd(share_cmd):
check_values=self.checkOpts)
# Создаем объект логики
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):
"""Проверка опций командной строки"""
if len(args)==0:
optionsRequired = self.getOptionsRequired(optObj)
if len(filter(lambda x: x, optionsRequired))>1:
errMsg = _("incompatible options")+":"+" %s"\
%self.getStringIncompatibleOptions()
if len(args) == 0:
if optObj.locate == "clt":
errMsg = _("incorrect option")+":"+" --%s" %"locate" + " " + \
str(optObj.locate)
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)
return False
elif optObj.clt:
errMsg = _("incorrect option")+":"+" --%s" %"clt"
elif len(args) == 1:
if optObj.locate and optObj.locate != "clt":
errMsg = _("incorrect option")+":"+" --%s" %"locate" + " " + \
str(optObj.locate)
self.optobj.error(errMsg)
return False
else:
@ -123,3 +87,13 @@ class apply_template_cmd(share_cmd):
def applyAllTemplates(self):
"""Применяем все шаблоны"""
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:
obj.printVars(options)
sys.exit(0)
# check root
if not obj.isRoot():
sys.exit(1)
if options.all:
# apply all templates
if not obj.applyAllTemplates():
sys.exit(1)
elif options.clt:
# apply one clt template
if not obj.applyCltTemplate(options.clt):
sys.exit(1)
elif args:
listLocate = options.locate
if listLocate:
if 'all' in listLocate:
# apply all templates
if not obj.applyAllTemplates():
sys.exit(1)
elif 'local' in listLocate:
# apply local templates
if not obj.applyLocalTemplates():
sys.exit(1)
elif 'remote' in listLocate:
# apply remote templates
if not obj.applyRemoteTemplates():
sys.exit(1)
if args:
cltPath = args[0]
# apply one clt template
if not obj.applyCltTemplate(cltPath):

Loading…
Cancel
Save