Add merge option.

master3.3
Mike Hiretsky 13 years ago
parent 1501cc128e
commit a36d89b0ea

Binary file not shown.

@ -67,7 +67,6 @@ class updateConfFiles(color_print):
self.clVars = clVars self.clVars = clVars
self.installProgs = self.clVars.GetList("cl_merges") self.installProgs = self.clVars.GetList("cl_merges")
def applyCltTemplate(self, cltTemplatePath): def applyCltTemplate(self, cltTemplatePath):
"""Применяем clt шаблон""" """Применяем clt шаблон"""
realPath = "/usr/lib/calculate-2.2/calculate-install" realPath = "/usr/lib/calculate-2.2/calculate-install"
@ -126,7 +125,7 @@ subdirectories %s")%', '.join(dirsTemplates))
else: else:
self.clVars.printVars() self.clVars.printVars()
def applyAllTemplates(self, location="all"): def applyAllTemplates(self, location="all", package=None):
"""Обновление конфигурационных файлов""" """Обновление конфигурационных файлов"""
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")
@ -135,6 +134,8 @@ subdirectories %s")%', '.join(dirsTemplates))
_("To install the program, run 'cl-install --install'")) _("To install the program, run 'cl-install --install'"))
return False return False
if package and "/" in package:
package = package.partition('/')[2]
sectionsWork = map(lambda x: x.rpartition("-")[2], self.installProgs) sectionsWork = map(lambda x: x.rpartition("-")[2], self.installProgs)
dictPakkages = {} dictPakkages = {}
oldPymPath = "" oldPymPath = ""
@ -174,6 +175,9 @@ subdirectories %s")%', '.join(dirsTemplates))
clTempl = template(clVars, cltFilter=False, clTempl = template(clVars, cltFilter=False,
printWarning=False) printWarning=False)
error = None error = None
if(package):
clVars.Set("cl_belong_pkg",package,True)
try: try:
if location=="clt": if location=="clt":
# apply clt templates # apply clt templates

@ -14,12 +14,14 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import os, sys import os, sys, re
from cl_apply_template import updateConfFiles, __app__, __version__ from cl_apply_template import updateConfFiles, __app__, __version__
from cl_opt import opt from cl_opt import opt
from cl_share_cmd import share_cmd from cl_share_cmd import share_cmd
from cl_lang import lang from cl_lang import lang
from cl_utils import listDirectory,pathJoin
from os import path
lang().setLanguage(sys.modules[__name__]) lang().setLanguage(sys.modules[__name__])
USAGE = _("%prog [options] path_clt_file") USAGE = _("%prog [options] path_clt_file")
@ -37,6 +39,10 @@ CMD_OPTIONS = [{'shortOption':"l",
'choices':['all','clt','local','remote'], 'choices':['all','clt','local','remote'],
'help':_("select location templates \ 'help':_("select location templates \
'all','clt','local','remote'")}, 'all','clt','local','remote'")},
{'longOption':'merge',
'optVal':"PACKAGE",
'help':_("apply templates for specified package only")
},
{'longOption':"clt", {'longOption':"clt",
'optVal':"CLT_TEMPLATE", 'optVal':"CLT_TEMPLATE",
'help':_("process clt template (default)") 'help':_("process clt template (default)")
@ -57,8 +63,35 @@ class apply_template_cmd(share_cmd):
# Создаем объект логики # Создаем объект логики
self.logicObj = updateConfFiles() 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): 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 len(args) == 0:
if not optObj.clt and not optObj.l: if not optObj.clt and not optObj.l:
errMsg = _("required option")+": --clt "+_("or")+" --locate" errMsg = _("required option")+": --clt "+_("or")+" --locate"
@ -89,17 +122,17 @@ class apply_template_cmd(share_cmd):
cltTemplate = os.path.join(currentPath, cltTemplate) cltTemplate = os.path.join(currentPath, cltTemplate)
return self.logicObj.applyCltTemplate(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""" """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""" """We use remote templates"""
return self.logicObj.applyAllTemplates(location="remote") return self.logicObj.applyAllTemplates(location="remote",package=pkg)
def applyCltTemplates(self): def applyCltTemplates(self):
"""We use all clt templates""" """We use all clt templates"""

@ -49,15 +49,15 @@ if __name__ == "__main__":
if listLocate: if listLocate:
if 'all' in listLocate: if 'all' in listLocate:
# apply all templates # apply all templates
if not obj.applyAllTemplates(): if not obj.applyAllTemplates(options.merge):
sys.exit(1) sys.exit(1)
elif 'local' in listLocate: elif 'local' in listLocate:
# apply local templates # apply local templates
if not obj.applyLocalTemplates(): if not obj.applyLocalTemplates(options.merge):
sys.exit(1) sys.exit(1)
elif 'remote' in listLocate: elif 'remote' in listLocate:
# apply remote templates # apply remote templates
if not obj.applyRemoteTemplates(): if not obj.applyRemoteTemplates(options.merge):
sys.exit(1) sys.exit(1)
elif 'clt' in listLocate: elif 'clt' in listLocate:
# apply clt templates # apply clt templates

Loading…
Cancel
Save