diff --git a/pym/cl_template.py b/pym/cl_template.py index 9b5c4ee..1458a38 100644 --- a/pym/cl_template.py +++ b/pym/cl_template.py @@ -304,7 +304,7 @@ class fileHeader(_terms): typeAppend = "" # Возможные типы вставки шаблонов _fileAppend = "join", "before", "after", "replace", "remove", "skip",\ - "patch" + "patch", "clear" # Интерпретатор (#!/bin/bash) (#!/usr/bin/python) execStr = "" # Символ комментария @@ -476,7 +476,7 @@ class dirHeader(_terms): typeAppend = "" # Возможные типы вставки шаблонов - _fileAppend = "join", "remove", "skip" + _fileAppend = "join", "remove", "skip", "clear" # условные операторы terms = ('>', '<', '==', '!=', '>=', '<=') @@ -3941,6 +3941,25 @@ should include a check of the variable 'cl-name'.")) applyDir) return ("", False, []) + # Очищаем директорию + if objHead.typeAppend == "clear": + if os.path.isdir(applyDir): + for rmPath in os.listdir(applyDir): + removePath = pathJoin(applyDir, rmPath) + if os.path.isdir(removePath): + # удаляем директорию + try: + removeDir(removePath) + except: + self.setError(_("Can not delete dir: " ) +\ + removePath) + else: + try: + os.unlink(removePath) + except: + self.setError(_("Can not delete: " ) + removePath) + return ("", False, []) + # Созданные директории createdDirs = [] # chmod - изменяем права @@ -4130,6 +4149,16 @@ should include a check of the variable 'cl-name'.")) if realPath in self.filesFilter: return ([], False) typeAppendTemplate = objHeadNew.typeAppend + # Очищаем оригинальный файл + if typeAppendTemplate == "clear": + try: + open(pathOldFile, "w").truncate(0) + except: + self.setError(_("Error in template") + ": " +\ + nameFileTemplate) + self.setError(_("Can not clear file") + ": " +\ + pathOldFile) + return (applyFiles, False) # Удаляем оригинальный файл if typeAppendTemplate == "remove": if os.path.islink(pathOldFile):