From b02e7b9733acb5e1a9e42a053b64fe1acf5ff99d Mon Sep 17 00:00:00 2001 From: rzaitov Date: Tue, 12 Nov 2013 15:09:46 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=BE=D0=B4=D0=B8=D1=84=D0=B8=D1=86?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=BA=D0=BE=D0=BC=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=B4=D1=83=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B1=D1=8D=D0=BA=D0=B0=D0=BF=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/IosSetupSteps.txt | 4 +-- .../CreateBackupCommandBuilder.py | 4 +-- .../Tests/ManualTests/create_backup_test.py | 2 +- .../ParserBackup/test_create_backup.py | 22 +++++--------- .../BaseBackupCommand/BaseBackupCommand.py | 18 ++++++------ .../BaseBackupCommand/CreateBackupCommand.py | 29 ++++++++++++++++--- .../BaseBackupCommand/DeleteBackupCommand.py | 6 ++-- .../BaseBackupCommand/RestoreBackupCommand.py | 10 +++---- .../ParserBackup/CreateBackupParser.py | 4 +-- 9 files changed, 56 insertions(+), 43 deletions(-) diff --git a/scripts/IosSetupSteps.txt b/scripts/IosSetupSteps.txt index e788e1a..beb656b 100644 --- a/scripts/IosSetupSteps.txt +++ b/scripts/IosSetupSteps.txt @@ -1,5 +1,5 @@ -restore from backup '.' # восстанавливаем из бэкапа (исходники от сборки предыдущей конфигурации могут быть модифицированными) -create backup for '.' +restore from backup # восстанавливаем из бэкапа (исходники от сборки предыдущей конфигурации могут быть модифицированными) +create backup inside 'BuildSample/BuildSample.sln' remove NotCompileApp project diff --git a/scripts/TouchinBuild/CommandBuilders/CreateBackupCommandBuilder.py b/scripts/TouchinBuild/CommandBuilders/CreateBackupCommandBuilder.py index ddb1c34..5bd0bd3 100644 --- a/scripts/TouchinBuild/CommandBuilders/CreateBackupCommandBuilder.py +++ b/scripts/TouchinBuild/CommandBuilders/CreateBackupCommandBuilder.py @@ -16,7 +16,7 @@ class CreateBackupCommandBuilder: assert line is not None parser = CreateBackupParser() - folderPath = parser.parseLine(line) + parser.parseLine(line) - command = CreateBackupCommand(folderPath) + command = CreateBackupCommand() return command diff --git a/scripts/TouchinBuild/Tests/ManualTests/create_backup_test.py b/scripts/TouchinBuild/Tests/ManualTests/create_backup_test.py index 48bc235..c770259 100644 --- a/scripts/TouchinBuild/Tests/ManualTests/create_backup_test.py +++ b/scripts/TouchinBuild/Tests/ManualTests/create_backup_test.py @@ -1,6 +1,6 @@ from CommandBuilders.CreateBackupCommandBuilder import CreateBackupCommandBuilder -line = "create backup for 'BuildSample'" +line = "create backup" cmdBuilder = CreateBackupCommandBuilder() command = cmdBuilder.getCommandFor(line) diff --git a/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/test_create_backup.py b/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/test_create_backup.py index 1f60683..c415aff 100644 --- a/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/test_create_backup.py +++ b/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/test_create_backup.py @@ -6,20 +6,14 @@ class TestCreateBackup(unittest.TestCase): def setUp(self): self.parser = CreateBackupParser() - def test_parseCurrentDir(self): - line = "create backup for '.'" - folderPath = self.parser.parseLine(line) + def test_isValid(self): + line = "create backup" + isValid = self.parser.isValidLine(line) - self.assertEqual('.', folderPath) + self.assertEqual(True, isValid) - def test_parseRelativePath(self): - line = "create backup for '../Some/Path'" - folderPath = self.parser.parseLine(line) + def test_isNotValid(self): + line = "create backup bla bla" + isValid = self.parser.isValidLine(line) - self.assertEqual('../Some/Path', folderPath) - - def test_parseAbsPath(self): - line = "create backup for '/Some/Abs/Path'" - folderPath = self.parser.parseLine(line) - - self.assertEqual('/Some/Abs/Path', folderPath) \ No newline at end of file + self.assertEqual(False, isValid) \ No newline at end of file diff --git a/scripts/TouchinBuild/commands/BaseBackupCommand/BaseBackupCommand.py b/scripts/TouchinBuild/commands/BaseBackupCommand/BaseBackupCommand.py index a728846..74dcb22 100644 --- a/scripts/TouchinBuild/commands/BaseBackupCommand/BaseBackupCommand.py +++ b/scripts/TouchinBuild/commands/BaseBackupCommand/BaseBackupCommand.py @@ -4,26 +4,26 @@ import os class BaseBackupCommand: - def __init__(self, folderPath): - assert folderPath is not None - - self.folderPath = folderPath + def __init__(self): + self.folderPath = '.' # вычислять абсолютные пути надо на этапе создания комманды # поскольку на этапе выполнения текущая директория может быть удалена - self.srcAbsPath = self.getAbsSrc() - self.backupAbsPath = self.getAbsDst() + self.srcAbsDirPath = self.getAbsSrc() + self.backupDirAbsPath = self.getAbsDst() + + self.backupIgnore = ['.git', '.gitignore', '.DS_Store'] def getAbsSrc(self): return self.getAbs(self.folderPath) def getAbsDst(self): absFolderPath = self.getAbs(self.folderPath) - srcDirName = os.path.basename(absFolderPath) absParentDir = os.path.dirname(absFolderPath) - dstAbs = self.getAbs(os.path.join(absParentDir, 'backup.{0}'.format(srcDirName))) - return dstAbs + backupAbsPath = os.path.join(absParentDir, 'backup') + + return backupAbsPath def getAbs(self, path): return os.path.abspath(path) \ No newline at end of file diff --git a/scripts/TouchinBuild/commands/BaseBackupCommand/CreateBackupCommand.py b/scripts/TouchinBuild/commands/BaseBackupCommand/CreateBackupCommand.py index adba2df..0498a0b 100644 --- a/scripts/TouchinBuild/commands/BaseBackupCommand/CreateBackupCommand.py +++ b/scripts/TouchinBuild/commands/BaseBackupCommand/CreateBackupCommand.py @@ -1,11 +1,32 @@ +import os import shutil from commands.BaseBackupCommand.BaseBackupCommand import BaseBackupCommand class CreateBackupCommand(BaseBackupCommand): - def __init__(self, folderPath): - BaseBackupCommand.__init__(self, folderPath) + def __init__(self): + BaseBackupCommand.__init__(self) def execute(self): - shutil.rmtree(self.backupAbsPath, ignore_errors=True) - shutil.copytree(self.srcAbsPath, self.backupAbsPath, symlinks=False) \ No newline at end of file + if os.path.exists(self.backupDirAbsPath): + raise Exception('folder: {0} already exists'.format(self.backupDirAbsPath)) + + os.mkdir(self.backupDirAbsPath) + + dirContent = os.listdir(self.srcAbsDirPath) + + for fileOrDir in dirContent: + if fileOrDir not in self.backupIgnore: + self.copyFileOrDirectoryToBackupFolder(fileOrDir) + + def copyFileOrDirectoryToBackupFolder(self, fileOrDirName): + assert fileOrDirName is not None + + srcAbsPath = os.path.join(self.srcAbsDirPath, fileOrDirName) + dstAbsPath = os.path.join(self.backupDirAbsPath, fileOrDirName) + + if os.path.isdir(srcAbsPath): + shutil.copytree(srcAbsPath, dstAbsPath) + else: + shutil.copy(srcAbsPath, dstAbsPath) + diff --git a/scripts/TouchinBuild/commands/BaseBackupCommand/DeleteBackupCommand.py b/scripts/TouchinBuild/commands/BaseBackupCommand/DeleteBackupCommand.py index ebdad25..6cc0806 100644 --- a/scripts/TouchinBuild/commands/BaseBackupCommand/DeleteBackupCommand.py +++ b/scripts/TouchinBuild/commands/BaseBackupCommand/DeleteBackupCommand.py @@ -3,8 +3,8 @@ from commands.BaseBackupCommand.BaseBackupCommand import BaseBackupCommand class DeleteBackupCommand(BaseBackupCommand): - def __init__(self, backupArguments): - BaseBackupCommand.__init__(self, backupArguments) + def __init__(self): + BaseBackupCommand.__init__(self) def execute(self): - shutil.rmtree(self.backupAbsPath, ignore_errors=True) + shutil.rmtree(self.backupDirAbsPath, ignore_errors=True) diff --git a/scripts/TouchinBuild/commands/BaseBackupCommand/RestoreBackupCommand.py b/scripts/TouchinBuild/commands/BaseBackupCommand/RestoreBackupCommand.py index e176153..9ec126c 100644 --- a/scripts/TouchinBuild/commands/BaseBackupCommand/RestoreBackupCommand.py +++ b/scripts/TouchinBuild/commands/BaseBackupCommand/RestoreBackupCommand.py @@ -4,10 +4,10 @@ from commands.BaseBackupCommand.BaseBackupCommand import BaseBackupCommand class RestoreBackupCommand(BaseBackupCommand): - def __init__(self, folderPath): - BaseBackupCommand.__init__(self, folderPath) + def __init__(self): + BaseBackupCommand.__init__(self) def execute(self): - if os.path.exists(self.backupAbsPath): - shutil.rmtree(self.srcAbsPath, ignore_errors=True) - shutil.copytree(self.backupAbsPath, self.srcAbsPath, symlinks=False) + if os.path.exists(self.backupDirAbsPath): + shutil.rmtree(self.srcAbsDirPath, ignore_errors=True) + shutil.copytree(self.backupDirAbsPath, self.srcAbsDirPath, symlinks=False) diff --git a/scripts/TouchinBuild/parsers/ParserBackup/CreateBackupParser.py b/scripts/TouchinBuild/parsers/ParserBackup/CreateBackupParser.py index cd9462b..f42ccae 100644 --- a/scripts/TouchinBuild/parsers/ParserBackup/CreateBackupParser.py +++ b/scripts/TouchinBuild/parsers/ParserBackup/CreateBackupParser.py @@ -10,9 +10,7 @@ class CreateBackupParser(ParserBackupBase): def getMatchInfo(self, line): assert line is not None - folderNameRegexp = r"'(?P[^']+)'$" - - regexpSource = self.startsWith('create') + self.than('backup') + self.than('for') + folderNameRegexp + regexpSource = self.startsWith('create') + self.spaceEndsWith('backup') regexp = re.compile(regexpSource, re.UNICODE) match = regexp.match(line)