|
|
|
@ -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")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|