diff --git a/i18n/cl_install_ru.mo b/i18n/cl_install_ru.mo index fe1130d..ff3daaf 100644 Binary files a/i18n/cl_install_ru.mo and b/i18n/cl_install_ru.mo differ diff --git a/pym/cl_apply_template.py b/pym/cl_apply_template.py index f7d8f91..f8125a1 100644 --- a/pym/cl_apply_template.py +++ b/pym/cl_apply_template.py @@ -67,7 +67,6 @@ class updateConfFiles(color_print): self.clVars = clVars self.installProgs = self.clVars.GetList("cl_merges") - def applyCltTemplate(self, cltTemplatePath): """Применяем clt шаблон""" realPath = "/usr/lib/calculate-2.2/calculate-install" @@ -126,7 +125,7 @@ subdirectories %s")%', '.join(dirsTemplates)) else: self.clVars.printVars() - def applyAllTemplates(self, location="all"): + def applyAllTemplates(self, location="all", package=None): """Обновление конфигурационных файлов""" if not "calculate-install" in self.installProgs: self.printERROR(_("Can not installed %s") @@ -135,6 +134,8 @@ subdirectories %s")%', '.join(dirsTemplates)) _("To install the program, run 'cl-install --install'")) return False + if package and "/" in package: + package = package.partition('/')[2] sectionsWork = map(lambda x: x.rpartition("-")[2], self.installProgs) dictPakkages = {} oldPymPath = "" @@ -174,6 +175,9 @@ subdirectories %s")%', '.join(dirsTemplates)) clTempl = template(clVars, cltFilter=False, printWarning=False) error = None + + if(package): + clVars.Set("cl_belong_pkg",package,True) try: if location=="clt": # apply clt templates diff --git a/pym/cl_apply_template_cmd.py b/pym/cl_apply_template_cmd.py index 50084af..9229778 100644 --- a/pym/cl_apply_template_cmd.py +++ b/pym/cl_apply_template_cmd.py @@ -14,12 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os, sys +import os, sys, re from cl_apply_template import updateConfFiles, __app__, __version__ from cl_opt import opt from cl_share_cmd import share_cmd from cl_lang import lang +from cl_utils import listDirectory,pathJoin +from os import path lang().setLanguage(sys.modules[__name__]) USAGE = _("%prog [options] path_clt_file") @@ -37,6 +39,10 @@ CMD_OPTIONS = [{'shortOption':"l", 'choices':['all','clt','local','remote'], 'help':_("select location templates \ 'all','clt','local','remote'")}, + {'longOption':'merge', + 'optVal':"PACKAGE", + 'help':_("apply templates for specified package only") + }, {'longOption':"clt", 'optVal':"CLT_TEMPLATE", 'help':_("process clt template (default)") @@ -57,8 +63,35 @@ class apply_template_cmd(share_cmd): # Создаем объект логики self.logicObj = updateConfFiles() + reVerSplit = re.compile(r"^(.*?)-(([^-]+?)(?:-(r\d+))?)(?:.(tbz2))?$",re.S) + + def checkAtom(self,atom): + """Chech if atom is installed""" + dbPkg = '/var/db/pkg' + if "/" in atom: + category,slash,package = atom.partition("/") + categoryPath = pathJoin(dbPkg,category) + return \ + map(lambda x:"%s/%s"%(category,x.groups()[0]), + filter(lambda x:x and x.groups()[0] == package, + map(self.reVerSplit.search, + filter(lambda x:x.startswith(package), + listDirectory(categoryPath))))) + else: + return reduce(lambda x,y:x+self.checkAtom("%s/%s"%(y,atom)), + listDirectory(dbPkg),[]) + def checkOpts(self, optObj, args): """Проверка опций командной строки""" + if optObj.merge: + if not self.checkAtom(optObj.merge): + errMsg = _("incorrect option")+":"+\ + " --%s" %"merge" + \ + ": "+_("wrong package") + ": " +\ + str(optObj.merge) + self.optobj.error(errMsg) + return False + if len(args) == 0: if not optObj.clt and not optObj.l: errMsg = _("required option")+": --clt "+_("or")+" --locate" @@ -89,17 +122,17 @@ class apply_template_cmd(share_cmd): cltTemplate = os.path.join(currentPath, cltTemplate) return self.logicObj.applyCltTemplate(cltTemplate) - def applyAllTemplates(self): + def applyAllTemplates(self,pkg): """Применяем все шаблоны""" - return self.logicObj.applyAllTemplates() + return self.logicObj.applyAllTemplates(package=pkg) - def applyLocalTemplates(self): + def applyLocalTemplates(self,pkg): """We use local templates""" - return self.logicObj.applyAllTemplates(location="local") + return self.logicObj.applyAllTemplates(location="local",package=pkg) - def applyRemoteTemplates(self): + def applyRemoteTemplates(self,pkg): """We use remote templates""" - return self.logicObj.applyAllTemplates(location="remote") + return self.logicObj.applyAllTemplates(location="remote",package=pkg) def applyCltTemplates(self): """We use all clt templates""" diff --git a/scripts/cl-template b/scripts/cl-template index d0f221f..e9e6357 100644 --- a/scripts/cl-template +++ b/scripts/cl-template @@ -49,15 +49,15 @@ if __name__ == "__main__": if listLocate: if 'all' in listLocate: # apply all templates - if not obj.applyAllTemplates(): + if not obj.applyAllTemplates(options.merge): sys.exit(1) elif 'local' in listLocate: # apply local templates - if not obj.applyLocalTemplates(): + if not obj.applyLocalTemplates(options.merge): sys.exit(1) elif 'remote' in listLocate: # apply remote templates - if not obj.applyRemoteTemplates(): + if not obj.applyRemoteTemplates(options.merge): sys.exit(1) elif 'clt' in listLocate: # apply clt templates