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

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

@ -25,4 +25,4 @@ class VariableClVer(ReadonlyVariable):
""" """
Package version 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.build_scripts import build_scripts
from distutils.command.install_scripts import install_scripts from distutils.command.install_scripts import install_scripts
__version__ = "3.1.1" __version__ = "3.1.4"
__app__ = "calculate-lib" __app__ = "calculate-lib"
module_name = "calculate.lib" module_name = "calculate.lib"

Loading…
Cancel
Save