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