Add diff format

master3.3
Mike Hiretsky 12 years ago
parent 32032836fb
commit a6c56b87c4

@ -350,7 +350,8 @@ class _terms(_error, _shareTermsFunction):
if flagNotIniFunct:
if flagNotEmptyVals and\
("_ver" in vals[0] or\
(flagFunction and searchFunct.group(1)=="pkg") or\
(flagFunction and searchFunct.group(1) in \
("pkg","merge")) or\
(flagFunction and searchFunct.group(1)=="load" and\
re.search("\(\s*ver\s*,",vals[0]))):
# Проверка значения на версию
@ -668,7 +669,8 @@ class fileHeader(_terms):
else:
if self.fileType != "raw" and self.fileType != "bin" and\
self.fileType != "":
if "format" in self.params and self.params["format"] == "patch":
if "format" in self.params and self.params["format"] in \
("patch","diff"):
self.params["append"] = "patch"
return "patch"
self.params["append"] = "join"
@ -3502,13 +3504,20 @@ class templateFunction(_error, _warning, _shareTemplate, _shareTermsFunction):
except TemplatesError as e:
self.printWARNING(str(e))
self.currentBelong = funcPkg
pkg = self.objVar.Get("cl_merge_pkg")
replace = ""
if pkg:
if funcPkg in pkg:
replace = "1"
if self.objVar.Get('cl_action') == 'patch':
if funcPkg == "%s/%s"%(self.objVar.Get('core.cl_core_pkg_category'),
self.objVar.Get('core.cl_core_pkg_name')):
replace = self.objVar.Get('core.cl_core_pkg_version')
else:
replace = ""
else:
replace = "1"
pkg = self.objVar.Get("cl_merge_pkg")
replace = ""
if pkg:
if funcPkg in pkg:
replace = "1"
else:
replace = "1"
textTemplateTmp = textTemplateTmp[:resS.start()] + replace +\
textTemplateTmp[resS.end():]
return textTemplateTmp
@ -3815,6 +3824,8 @@ class Template(_file,_terms,_warning,xmlShare,templateFormat,_shareTemplate):
self.changedFiles = ChangedFiles()
self.printSUCCESS = printSUCCESS
self.printERROR = printERROR
if printERROR:
self.setError = self.printERROR
self.printWARNING = printWARNING
self.askConfirm = askConfirm
self.stop = 0
@ -3879,6 +3890,8 @@ re.M|re.S)
self.functObj.printSUCCESS = self.printSUCCESS
self.functObj.printWARNING = self.printWARNING
self.functObj.printERROR = self.printERROR
if self.printERROR:
self.functObj.setError = self.printERROR
self.functObj.askConfirm = self.askConfirm
# Метод применения функций к шаблонам
self.applyFuncTemplate = self.functObj.applyFuncTemplate
@ -4191,7 +4204,7 @@ gettext -d cl_template "$*"
"""
return True
def templateModify(self,filesApl):
def templateModify(self):
"""
Files which created by apping templates
"""
@ -4484,7 +4497,11 @@ gettext -d cl_template "$*"
"""
self.printWARNING(_("Calculate Utilities have changed files")+":")
reGrey = re.compile(r"\._cfg\d{4}_")
rootPath = self.objVar.Get('cl_root_path')
for fn in sorted(list(set(filesApply))):
if rootPath != '/' and self.objVar.Get('cl_action') == 'patch' and \
fn.startswith(rootPath):
fn = fn[len(rootPath)+1:]
if reGrey.search(fn):
self.printSUCCESS(" "*5 + \
"<font color=\"dark gray\">%s</font>"%fn)
@ -4495,6 +4512,8 @@ gettext -d cl_template "$*"
"""
Update ._cfg0000 files
"""
if self.objVar.Get('cl_ebuild_phase') == 'compile':
return
chrootPath = self.objVar.Get('cl_chroot_path')
cfgs = getCfgFiles(self.objVar.Get('cl_config_protect'),
prefix=chrootPath)
@ -4658,7 +4677,6 @@ gettext -d cl_template "$*"
nameEnvFile = os.path.basename(nameFileConfig)
self.functObj.timeConfigsIni[nameEnvFile] = float(time.time())
self.filesApply += filesApl
self.templateModify(filesApl)
if filesApl:
self._addFile(filesApl)
return True
@ -5164,7 +5182,8 @@ gettext -d cl_template "$*"
else:
pathOldFile = pathJoin(path,os.path.split(nameFileConfig)[1])
pathOrigFile = pathOldFile
if not self.userProfile:
if not self.userProfile and \
not self.objVar.Get('cl_ebuild_phase') == 'compile':
pathOldFile = self.fixNameFileConfig(pathOldFile)
pathOldFile = self.checkOnNewConfigName(pathOldFile)
applyFiles = [pathOldFile]
@ -5562,6 +5581,7 @@ gettext -d cl_template "$*"
optFile)
if not objHeadNew:
return filesApply
self.templateModify()
if templateFileType != "bin":
# Вычисляем условные блоки
objHeadNew.body = self.applyTermsTemplate(objHeadNew.body,
@ -5616,7 +5636,7 @@ gettext -d cl_template "$*"
if objHeadNew.fileType:
formatTemplate = objHeadNew.fileType
typeAppendTemplate = objHeadNew.typeAppend
if formatTemplate == "patch":
if formatTemplate in ("patch","diff"):
if typeAppendTemplate != "patch":
self.setError(\
_("Wrong option append=%(type)s in template %(file)s")\
@ -5633,16 +5653,23 @@ gettext -d cl_template "$*"
if objHeadOld and objHeadOld.body:
self.textConfig = objHeadOld.body
# обработка конфигурационного файла
self.textTemplate = objTempl.processingFile(self.textConfig)
self.textTemplate = objTempl.processingFile(self.textConfig,
self.objVar.Get('cl_root_path'))
if objTempl.getError():
self.setError(_("Wrong template") + ": " +\
self.setError(_("Failed to use patch ") + \
nameFileTemplate)
return False
elif formatTemplate == 'diff':
self.printSUCCESS(_("Appling patch")+ " " + \
os.path.basename(nameFileTemplate))
if execStr:
self.textConfig = execStr + title + self.textTemplate
else:
self.textConfig = title + self.textTemplate
self.saveConfFile()
if formatTemplate in ("diff",):
return objTempl.patchFiles
else:
self.saveConfFile()
if 'run' in objHeadNew.params:
if not self.executeTemplate(self.textConfig,
objHeadNew.params['run']):
@ -6031,7 +6058,6 @@ class templateClt(scanDirectoryClt, Template):
nameEnvFile = os.path.basename(nameFileConfig)
self.functObj.timeConfigsIni[nameEnvFile] = float(time.time())
self.filesApply += filesApl
self.templateModify(filesApl)
return nameFileConfig
else:
return True
@ -6462,7 +6488,7 @@ class ProgressTemplate(Template):
self.value = value
return True
def templateModify(self,filesApl):
def templateModify(self):
if self.firstValue and hasattr(self,"onFirstValue"):
self.onFirstValue()
self.firstValue = False

@ -0,0 +1,57 @@
#-*- coding: utf-8 -*-
# Copyright 2008-2012 Calculate Ltd. http://www.calculate-linux.org
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys, re
import xml.dom.minidom
from calculate.lib.utils.common import _error
from calculate.lib.utils.files import process,STDOUT
from calculate.lib.cl_lang import setLocalTranslate
setLocalTranslate('cl_lib3',sys.modules[__name__])
class diff(_error):
"""
Format using diff
"""
text = ""
def __init__(self, text):
self.text = text
def textToXML(self):
return self.text
def processingFile(self, textConfigFile, rootPath=None):
self.patchFiles = []
retTextConfigFile = textConfigFile
for i in range(0,4):
patchDryRun = process('/usr/bin/patch','--dry-run',
'-p%d'%i,cwd=rootPath,)
patchDryRun.write(self.text)
if patchDryRun.success():
break
else:
self.setError(_("Patch failed"))
return False
patchRun = process('/usr/bin/patch',
'-p%d'%i,cwd=rootPath)
patchRun.write(self.text)
if patchRun.success():
for line in patchRun:
if line.startswith("patching file"):
self.patchFiles.append(line[13:].strip())
return patchRun.read()
return ""

@ -51,7 +51,7 @@ class patch(_error):
return False
return self.doc
def processingFile(self, textConfigFile):
def processingFile(self, textConfigFile, rootPath=None):
"""Обработка конфигурационного файла"""
if not self.doc:
self.setError(_("Failed to convert the text template to XML"))

@ -83,6 +83,7 @@ class process:
self.langc = "langc" in kwarg
self.stderr = kwarg.get("stderr",PIPE)
self.cwd = kwarg.get("cwd",None)
self.command = [command] + list(params)
self.stdin = stdin
self.iter = None
@ -98,6 +99,7 @@ class process:
stdout=self.stdout,
stdin=self.stdin(),
stderr=self.stderr,
cwd=self.cwd,
env=self.envdict)
def _defaultStdin(self):

@ -25,4 +25,4 @@ class VariableClVer(ReadonlyVariable):
"""
Package version
"""
value = "3.1.3"
value = "3.1.4"

@ -22,7 +22,7 @@ from distutils.core import setup
from distutils.command.build_scripts import build_scripts
from distutils.command.install_scripts import install_scripts
__version__ = "3.1.1"
__version__ = "3.1.4"
__app__ = "calculate-lib"
module_name = "calculate.lib"

Loading…
Cancel
Save