From ec57e67133695d566296d426f1b9e91558b3f293 Mon Sep 17 00:00:00 2001 From: Rustam Zaitov Date: Tue, 29 Oct 2013 02:14:09 +0400 Subject: [PATCH 1/8] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D0=BF=D0=B0=D1=80=D1=81=D0=B5=D1=80=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D1=8B=20=D1=81=D0=BE=D0=B7?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B1=D1=8D=D0=BA=D0=B0=D0=BF?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - scripts/UnitTests/BackupParser/__init__.py | 1 + .../BackupParser/test_createBackupParser.py | 13 +++++++++ .../BackupParser/CreateBackupArguments.py | 3 ++ .../parser/BackupParser/CreateBackupParser.py | 29 +++++++++++++++++++ scripts/parser/BackupParser/__init__.py | 1 + scripts/parser/CopyParser/CopyLineParser.py | 8 ----- scripts/parser/LineParser.py | 10 ++++++- 8 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 scripts/UnitTests/BackupParser/__init__.py create mode 100644 scripts/UnitTests/BackupParser/test_createBackupParser.py create mode 100644 scripts/parser/BackupParser/CreateBackupArguments.py create mode 100644 scripts/parser/BackupParser/CreateBackupParser.py create mode 100644 scripts/parser/BackupParser/__init__.py diff --git a/.gitignore b/.gitignore index 36a62c6..217ce48 100644 --- a/.gitignore +++ b/.gitignore @@ -168,7 +168,6 @@ Generated_Code #added for RIA/Silverlight projects # Backup & report files from converting an old project file to a newer # Visual Studio version. Backup files are not needed, because we have git ;-) _UpgradeReport_Files/ -Backup*/ UpgradeLog*.XML diff --git a/scripts/UnitTests/BackupParser/__init__.py b/scripts/UnitTests/BackupParser/__init__.py new file mode 100644 index 0000000..cc31abc --- /dev/null +++ b/scripts/UnitTests/BackupParser/__init__.py @@ -0,0 +1 @@ +__author__ = 'rzaitov' diff --git a/scripts/UnitTests/BackupParser/test_createBackupParser.py b/scripts/UnitTests/BackupParser/test_createBackupParser.py new file mode 100644 index 0000000..8b5b199 --- /dev/null +++ b/scripts/UnitTests/BackupParser/test_createBackupParser.py @@ -0,0 +1,13 @@ +import unittest +from parser.BackupParser.CreateBackupParser import CreateBackupParser + + +class TestCreateBackupParser(unittest.TestCase): + def setUp(self): + self.__parser = CreateBackupParser() + + def test_validInput(self): + line = "create backup for 'SomeFolder'" + createBackupArgs = self.__parser.parseLine(line) + + self.assertEqual('SomeFolder', createBackupArgs.folderName) \ No newline at end of file diff --git a/scripts/parser/BackupParser/CreateBackupArguments.py b/scripts/parser/BackupParser/CreateBackupArguments.py new file mode 100644 index 0000000..0a43b19 --- /dev/null +++ b/scripts/parser/BackupParser/CreateBackupArguments.py @@ -0,0 +1,3 @@ +class CreateBackupArguments: + def __init__(self): + self.folderName = None diff --git a/scripts/parser/BackupParser/CreateBackupParser.py b/scripts/parser/BackupParser/CreateBackupParser.py new file mode 100644 index 0000000..2e897f6 --- /dev/null +++ b/scripts/parser/BackupParser/CreateBackupParser.py @@ -0,0 +1,29 @@ +from parser.BackupParser.CreateBackupArguments import CreateBackupArguments +from parser.LineParser import LineParser +import re + +class CreateBackupParser(LineParser): + def __init__(self): + self.__createBackupArguments = CreateBackupArguments() + + def parseLine(self, line): + assert line is not None + + folderNameRegexp = r"'(?P[^']+)'$" + + regexpSource = self.startsWithKeywordToken('create backup for') + folderNameRegexp + regexp = re.compile(regexpSource, re.UNICODE) + + match = regexp.match(line) + self._guardMatch(match, line, regexpSource) + + folderName = match.group('folder') + self.__createBackupArguments.folderName = folderName + + return self.__createBackupArguments + + def isValidLine(self, line): + assert line is not None + + isValid = line.startswith('create backup') + return isValid diff --git a/scripts/parser/BackupParser/__init__.py b/scripts/parser/BackupParser/__init__.py new file mode 100644 index 0000000..cc31abc --- /dev/null +++ b/scripts/parser/BackupParser/__init__.py @@ -0,0 +1 @@ +__author__ = 'rzaitov' diff --git a/scripts/parser/CopyParser/CopyLineParser.py b/scripts/parser/CopyParser/CopyLineParser.py index 6e9c81e..6166b2f 100644 --- a/scripts/parser/CopyParser/CopyLineParser.py +++ b/scripts/parser/CopyParser/CopyLineParser.py @@ -24,14 +24,6 @@ class CopyLineParser(LineParser): self.__copyArguments.setArguments(src, dst) return self.__copyArguments - def keywordToken(self, keyword): - assert keyword is not None - return r'\s+' + keyword + r'\s+' - - def startsWithKeywordToken(self, keyword): - assert keyword is not None - return r'^' + keyword + r'\s+' - def isValidLine(self, line): assert line is not None diff --git a/scripts/parser/LineParser.py b/scripts/parser/LineParser.py index 3a077bc..014c94c 100644 --- a/scripts/parser/LineParser.py +++ b/scripts/parser/LineParser.py @@ -7,9 +7,17 @@ class LineParser: assert line is not None return False + def keywordToken(self, keyword): + assert keyword is not None + return r'\s+' + keyword + r'\s+' + + def startsWithKeywordToken(self, keyword): + assert keyword is not None + return r'^' + keyword + r'\s+' + def _guardMatch(self, match_object, source, regexpSource = None): if match_object is None: - msg = 'Recognition exception: {0} for {1}'.format(source, regexpSource) + msg = 'Recognition exception: "{0}" for "{1}"'.format(source, regexpSource) raise Exception(msg) From d62eacda7dbb0dc2b53c9a915d21ad3287426fb2 Mon Sep 17 00:00:00 2001 From: Rustam Zaitov Date: Tue, 29 Oct 2013 02:14:45 +0400 Subject: [PATCH 2/8] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D0=BF=D0=B0=D1=80=D1=81=D0=B5=D1=80=20?= =?UTF-8?q?=D0=B2=D0=BE=D1=81=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8=D0=B7=20=D0=B1=D1=8D=D0=BA?= =?UTF-8?q?=D0=B0=D0=BF=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BackupParser/test_restoreBackupParser.py | 11 +++++++++++ .../BackupParser/RestoreBackupParser.py | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 scripts/UnitTests/BackupParser/test_restoreBackupParser.py create mode 100644 scripts/parser/BackupParser/RestoreBackupParser.py diff --git a/scripts/UnitTests/BackupParser/test_restoreBackupParser.py b/scripts/UnitTests/BackupParser/test_restoreBackupParser.py new file mode 100644 index 0000000..2168d78 --- /dev/null +++ b/scripts/UnitTests/BackupParser/test_restoreBackupParser.py @@ -0,0 +1,11 @@ +import unittest +from parser.BackupParser.RestoreBackupParser import RestoreBackupParser + + +class TestRestoreBackupParser(unittest.TestCase): + def setUp(self): + self.__parser = RestoreBackupParser() + + def test_ValidInput(self): + line = 'restore from backup' + self.__parser.parseLine(line) \ No newline at end of file diff --git a/scripts/parser/BackupParser/RestoreBackupParser.py b/scripts/parser/BackupParser/RestoreBackupParser.py new file mode 100644 index 0000000..f8bafb5 --- /dev/null +++ b/scripts/parser/BackupParser/RestoreBackupParser.py @@ -0,0 +1,19 @@ +from parser.LineParser import LineParser +import re + + +class RestoreBackupParser(LineParser): + def parseLine(self, line): + assert line is not None + + regexpSource = r'restore from backup\s*' + regexp = re.compile(regexpSource, re.UNICODE) + + match = regexp.match(line) + self._guardMatch(match, line, regexpSource) + + def isValidLine(self, line): + assert line is not None + + isValid = line.startswith('restore from backup') + From a2914ce339a13c17f0223e10e9f7ba993190e24d Mon Sep 17 00:00:00 2001 From: Rustam Zaitov Date: Tue, 29 Oct 2013 02:28:07 +0400 Subject: [PATCH 3/8] =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D0=BF=D0=B0=D1=80=D1=81=D0=B5=D1=80=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D1=8B=20=D1=83=D0=B4=D0=B0?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B1=D1=8D=D0=BA=D0=B0=D0=BF?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BackupParser/test_deleteBackupParser.py | 23 +++++++++++++++++++ .../parser/BackupParser/DeleteBackupParser.py | 18 +++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 scripts/UnitTests/BackupParser/test_deleteBackupParser.py create mode 100644 scripts/parser/BackupParser/DeleteBackupParser.py diff --git a/scripts/UnitTests/BackupParser/test_deleteBackupParser.py b/scripts/UnitTests/BackupParser/test_deleteBackupParser.py new file mode 100644 index 0000000..fbe91a7 --- /dev/null +++ b/scripts/UnitTests/BackupParser/test_deleteBackupParser.py @@ -0,0 +1,23 @@ +import unittest +from parser.BackupParser.DeleteBackupParser import DeleteBackupParser + + +class TestDeleteBackupParser(unittest.TestCase): + def setUp(self): + self.__parser = DeleteBackupParser() + + def test_isValid(self): + line = 'delete backup' + isValid = self.__parser.isValidLine(line) + + self.assertEqual(True, isValid) + + def test_isNotValid(self): + line = 'bla backup' + isValid = self.__parser.isValidLine(line) + + self.assertEqual(False, isValid) + + def test_validInput(self): + line = 'delete backup' + self.__parser.parseLine(line) \ No newline at end of file diff --git a/scripts/parser/BackupParser/DeleteBackupParser.py b/scripts/parser/BackupParser/DeleteBackupParser.py new file mode 100644 index 0000000..cf92e91 --- /dev/null +++ b/scripts/parser/BackupParser/DeleteBackupParser.py @@ -0,0 +1,18 @@ +from parser.LineParser import LineParser +import re + +class DeleteBackupParser(LineParser): + def parseLine(self, line): + assert line is not None + + regexpSource = r'delete backup\s*' + regexp = re.compile(regexpSource, re.UNICODE) + + match = regexp.match(line) + self._guardMatch(match, line, regexpSource) + + def isValidLine(self, line): + assert line is not None + + isValid = line.startswith('delete backup') + return isValid From fa542158c88c26fca3d9c56bbe2e506068ff46fd Mon Sep 17 00:00:00 2001 From: Rustam Zaitov Date: Tue, 29 Oct 2013 02:50:01 +0400 Subject: [PATCH 4/8] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D1=83?= =?UTF-8?q?=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B1?= =?UTF-8?q?=D1=8D=D0=BA=D0=B0=D0=BF=D0=B0=20=D0=B8=20=D0=B5=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=80=D0=BE=D0=B8=D1=82=D0=B5=D0=BB=D1=8C,?= =?UTF-8?q?=20=D0=B0=20=D1=82=D0=B0=D0=BA=D0=B6=D0=B5=20=D1=80=D1=83=D1=87?= =?UTF-8?q?=D0=BD=D0=BE=D0=B9=20=D1=82=D0=B5=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CreateBackupCommandBuilder.py | 24 +++++++++++++++++++ scripts/ManualTests/create_backup_test.py | 12 ++++++++++ scripts/commands/CreateBackupCommand.py | 16 +++++++++++++ .../BackupParser/CreateBackupArguments.py | 8 +++++++ scripts/run_manual_tests.py | 4 +++- 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 scripts/CommandBuilders/CreateBackupCommandBuilder.py create mode 100644 scripts/ManualTests/create_backup_test.py create mode 100644 scripts/commands/CreateBackupCommand.py diff --git a/scripts/CommandBuilders/CreateBackupCommandBuilder.py b/scripts/CommandBuilders/CreateBackupCommandBuilder.py new file mode 100644 index 0000000..f1f7f17 --- /dev/null +++ b/scripts/CommandBuilders/CreateBackupCommandBuilder.py @@ -0,0 +1,24 @@ +from commands.CreateBackupCommand import CreateBackupCommand +from parser.BackupParser.CreateBackupParser import CreateBackupParser + + +class CreateBackupCommandBuilder: + def __init__(self, pathProvider): + assert pathProvider is not None + + self.__pathProvider = pathProvider + + def isCreateBackup(self, line): + assert line is not None + + parser = CreateBackupParser() + return parser.isValidLine(line) + + def getCommandFor(self, line): + assert line is not None + + parser = CreateBackupParser() + backupArguments = parser.parseLine(line) + + command = CreateBackupCommand(self.__pathProvider, backupArguments) + return command diff --git a/scripts/ManualTests/create_backup_test.py b/scripts/ManualTests/create_backup_test.py new file mode 100644 index 0000000..8362787 --- /dev/null +++ b/scripts/ManualTests/create_backup_test.py @@ -0,0 +1,12 @@ +from CommandBuilders.CreateBackupCommandBuilder import CreateBackupCommandBuilder +from ManualTests.path_provider import PathProvider + +line = "create backup for 'BuildSample'" + +baseDir = '../' +path_provider = PathProvider(baseDir) + +cmdBuilder = CreateBackupCommandBuilder(path_provider) +command = cmdBuilder.getCommandFor(line) + +command.execute() \ No newline at end of file diff --git a/scripts/commands/CreateBackupCommand.py b/scripts/commands/CreateBackupCommand.py new file mode 100644 index 0000000..59d5ab9 --- /dev/null +++ b/scripts/commands/CreateBackupCommand.py @@ -0,0 +1,16 @@ +import shutil + +class CreateBackupCommand: + def __init__(self, pathProvider, createBackupArguments): + assert pathProvider is not None + assert createBackupArguments is not None + + self.__pathProvider = pathProvider + self.__createBackupArguments = createBackupArguments + + def execute(self): + src = self.__pathProvider.resolveAbsPath(self.__createBackupArguments.getSourceFolderName()) + dst = self.__pathProvider.resolveAbsPath(self.__createBackupArguments.getBackupFolderName()) + + shutil.rmtree(dst, ignore_errors=True) + shutil.copytree(src, dst, symlinks=False) diff --git a/scripts/parser/BackupParser/CreateBackupArguments.py b/scripts/parser/BackupParser/CreateBackupArguments.py index 0a43b19..fbeea2b 100644 --- a/scripts/parser/BackupParser/CreateBackupArguments.py +++ b/scripts/parser/BackupParser/CreateBackupArguments.py @@ -1,3 +1,11 @@ class CreateBackupArguments: def __init__(self): self.folderName = None + + def getSourceFolderName(self): + return self.folderName + + def getBackupFolderName(self): + return "backup.{0}".format(self.folderName) + + diff --git a/scripts/run_manual_tests.py b/scripts/run_manual_tests.py index dab7faf..d37be40 100644 --- a/scripts/run_manual_tests.py +++ b/scripts/run_manual_tests.py @@ -1,3 +1,5 @@ #import ManualTests.csproj_test #import ManualTests.info_plist_test -import ManualTests.copy_test \ No newline at end of file +#import ManualTests.copy_test + +import ManualTests.create_backup_test \ No newline at end of file From b7dd51866d4e94a108893964c58dac1a73dcc149 Mon Sep 17 00:00:00 2001 From: Rustam Zaitov Date: Tue, 29 Oct 2013 03:14:32 +0400 Subject: [PATCH 5/8] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D1=83?= =?UTF-8?q?=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B1?= =?UTF-8?q?=D1=8D=D0=BA=D0=B0=D0=BF=D0=B0,=20=D0=BF=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=20=D0=BA=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=B9=20=D0=B8=20=D1=80=D1=83=D1=87=D0=BD=D0=BE=D0=B9=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeleteBackupCommandBuilder.py | 25 +++++++++++++++++++ scripts/ManualTests/delete_backup_test.py | 12 +++++++++ scripts/commands/DeleteBackupCommand.py | 15 +++++++++++ scripts/run_manual_tests.py | 3 ++- 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 scripts/CommandBuilders/DeleteBackupCommandBuilder.py create mode 100644 scripts/ManualTests/delete_backup_test.py create mode 100644 scripts/commands/DeleteBackupCommand.py diff --git a/scripts/CommandBuilders/DeleteBackupCommandBuilder.py b/scripts/CommandBuilders/DeleteBackupCommandBuilder.py new file mode 100644 index 0000000..0e9eb76 --- /dev/null +++ b/scripts/CommandBuilders/DeleteBackupCommandBuilder.py @@ -0,0 +1,25 @@ +from commands.DeleteBackupCommand import DeleteBackupCommand +from parser.BackupParser.DeleteBackupParser import DeleteBackupParser + + +class DeleteBackupCommandBuilder: + def __init__(self, pathProvider): + assert pathProvider is not None + self.__pathProvider = pathProvider + + def isDeleteBackup(self, line): + assert line is not None + + parser = DeleteBackupParser() + isValid = parser.isValidLine(line) + + return isValid + + def getCommandFor(self, line): + assert line is not None + + parser = DeleteBackupParser() + parser.parseLine(line) + + command = DeleteBackupCommand(self.__pathProvider) + return command diff --git a/scripts/ManualTests/delete_backup_test.py b/scripts/ManualTests/delete_backup_test.py new file mode 100644 index 0000000..7ac8044 --- /dev/null +++ b/scripts/ManualTests/delete_backup_test.py @@ -0,0 +1,12 @@ +from CommandBuilders.DeleteBackupCommandBuilder import DeleteBackupCommandBuilder +from ManualTests.path_provider import PathProvider + +line = "delete backup" + +baseDir = '../' +path_provider = PathProvider(baseDir) + +cmdBuilder = DeleteBackupCommandBuilder(path_provider) +command = cmdBuilder.getCommandFor(line) + +command.execute() \ No newline at end of file diff --git a/scripts/commands/DeleteBackupCommand.py b/scripts/commands/DeleteBackupCommand.py new file mode 100644 index 0000000..db69c71 --- /dev/null +++ b/scripts/commands/DeleteBackupCommand.py @@ -0,0 +1,15 @@ +import os +import shutil + +class DeleteBackupCommand: + def __init__(self, pathProvider): + assert pathProvider is not None + + self.__pathProvider = pathProvider + + def execute(self): + baseDir = self.__pathProvider.resolveAbsPath('.') + + dirs = [name for name in os.listdir(baseDir) if os.path.isdir(os.path.join(baseDir, name))] + for dir in dirs: + shutil.rmtree(dir) \ No newline at end of file diff --git a/scripts/run_manual_tests.py b/scripts/run_manual_tests.py index d37be40..15afad6 100644 --- a/scripts/run_manual_tests.py +++ b/scripts/run_manual_tests.py @@ -1,5 +1,6 @@ #import ManualTests.csproj_test #import ManualTests.info_plist_test #import ManualTests.copy_test +#import ManualTests.create_backup_test -import ManualTests.create_backup_test \ No newline at end of file +import ManualTests.delete_backup_test \ No newline at end of file From 8c0c1d1c43f35423771040502c4e157268da507a Mon Sep 17 00:00:00 2001 From: Rustam Zaitov Date: Tue, 29 Oct 2013 03:25:38 +0400 Subject: [PATCH 6/8] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83=20=D0=B2=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D0=B5=20=D1=83=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=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/commands/DeleteBackupCommand.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/commands/DeleteBackupCommand.py b/scripts/commands/DeleteBackupCommand.py index db69c71..6eb9735 100644 --- a/scripts/commands/DeleteBackupCommand.py +++ b/scripts/commands/DeleteBackupCommand.py @@ -10,6 +10,6 @@ class DeleteBackupCommand: def execute(self): baseDir = self.__pathProvider.resolveAbsPath('.') - dirs = [name for name in os.listdir(baseDir) if os.path.isdir(os.path.join(baseDir, name))] + dirs = [self.__pathProvider.resolveAbsPath(name) for name in os.listdir(baseDir) if os.path.isdir(os.path.join(baseDir, name)) & name.startswith('backup.')] for dir in dirs: shutil.rmtree(dir) \ No newline at end of file From 10a41bf1dba7929df497e4de6d1e7749136ea8ec Mon Sep 17 00:00:00 2001 From: Rustam Zaitov Date: Tue, 29 Oct 2013 03:48:08 +0400 Subject: [PATCH 7/8] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B0=D0=BD=D0=B4=D1=83=20=D0=B2=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B8=D0=B7=20=D0=B1=D1=8D=D0=BA=D0=B0=D0=BF=D0=B0,?= =?UTF-8?q?=20=D0=B5=D0=B5=20=D0=BF=D0=BE=D1=81=D1=82=D1=80=D0=BE=D0=B8?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8C=20=D0=B8=20=D1=80=D1=83=D1=87=D0=BD?= =?UTF-8?q?=D0=BE=D0=B9=20=D1=82=D0=B5=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RestoreBackupCommandBuilder.py | 25 +++++++++++++++++++ scripts/ManualTests/restore_backup_test.py | 15 +++++++++++ scripts/commands/RestoreBackupCommand.py | 21 ++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 scripts/CommandBuilders/RestoreBackupCommandBuilder.py create mode 100644 scripts/ManualTests/restore_backup_test.py create mode 100644 scripts/commands/RestoreBackupCommand.py diff --git a/scripts/CommandBuilders/RestoreBackupCommandBuilder.py b/scripts/CommandBuilders/RestoreBackupCommandBuilder.py new file mode 100644 index 0000000..4b7c9a3 --- /dev/null +++ b/scripts/CommandBuilders/RestoreBackupCommandBuilder.py @@ -0,0 +1,25 @@ +from commands.RestoreBackupCommand import RestoreBackupCommand +from parser.BackupParser.RestoreBackupParser import RestoreBackupParser + + +class RestoreBackupCommandBuilder: + def __init__(self, pathProvider): + assert pathProvider is not None + self.__pathProvider = pathProvider + + def isRestoreBackup(self, line): + assert line is not None + + parser = RestoreBackupParser() + isValid = parser.isValidLine(line) + + return isValid + + def getCommandFor(self, line): + assert line is not None + + parser = RestoreBackupParser() + parser.parseLine(line) + + command = RestoreBackupCommand(self.__pathProvider) + return command diff --git a/scripts/ManualTests/restore_backup_test.py b/scripts/ManualTests/restore_backup_test.py new file mode 100644 index 0000000..8bbd378 --- /dev/null +++ b/scripts/ManualTests/restore_backup_test.py @@ -0,0 +1,15 @@ +from CommandBuilders.RestoreBackupCommandBuilder import RestoreBackupCommandBuilder +from ManualTests.path_provider import PathProvider + +line = "restore from backup" + +baseDir = '../' +path_provider = PathProvider(baseDir) + +builder = RestoreBackupCommandBuilder(path_provider) +command = builder.getCommandFor(line) + +command.execute() + + + diff --git a/scripts/commands/RestoreBackupCommand.py b/scripts/commands/RestoreBackupCommand.py new file mode 100644 index 0000000..c0153c7 --- /dev/null +++ b/scripts/commands/RestoreBackupCommand.py @@ -0,0 +1,21 @@ +import os +import shutil + + +class RestoreBackupCommand: + def __init__(self, pathProvider): + assert pathProvider is not None + + self.__pathProvider = pathProvider + + def execute(self): + baseDir = self.__pathProvider.resolveAbsPath('.') + + dirPairs = [(name, "backup.{0}".format(name)) for name in os.listdir(baseDir) if os.path.isdir(self.__pathProvider.resolveAbsPath(name)) and not name.startswith('backup.')] + + for pair in dirPairs: + if not os.path.exists(pair[1]): + continue + + shutil.rmtree(pair[0]) # delete src + shutil.copytree(pair[1], pair[0]) # restore from backup From 5a717d273e3405fa087c0aeb7767d0cc0943bab3 Mon Sep 17 00:00:00 2001 From: Rustam Zaitov Date: Tue, 29 Oct 2013 03:53:11 +0400 Subject: [PATCH 8/8] =?UTF-8?q?=D0=9F=D0=BE=D1=84=D0=B8=D0=BA=D1=81=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B2=D0=BE=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=B7=20=D0=B1=D1=8D=D0=BA?= =?UTF-8?q?=D0=B0=D0=BF=D0=B0,=20=D0=BD=D0=B5=20=D1=80=D0=B5=D0=B7=D0=BE?= =?UTF-8?q?=D0=BB=D0=B2=D0=B8=D0=BB=D0=B8=D1=81=D1=8C=20=D0=BF=D1=83=D1=82?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/commands/RestoreBackupCommand.py | 7 ++++--- scripts/run_manual_tests.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/commands/RestoreBackupCommand.py b/scripts/commands/RestoreBackupCommand.py index c0153c7..edf56de 100644 --- a/scripts/commands/RestoreBackupCommand.py +++ b/scripts/commands/RestoreBackupCommand.py @@ -14,8 +14,9 @@ class RestoreBackupCommand: dirPairs = [(name, "backup.{0}".format(name)) for name in os.listdir(baseDir) if os.path.isdir(self.__pathProvider.resolveAbsPath(name)) and not name.startswith('backup.')] for pair in dirPairs: - if not os.path.exists(pair[1]): + absPair = (self.__pathProvider.resolveAbsPath(pair[0]), self.__pathProvider.resolveAbsPath(pair[1])) + if not os.path.exists(absPair[1]): continue - shutil.rmtree(pair[0]) # delete src - shutil.copytree(pair[1], pair[0]) # restore from backup + shutil.rmtree(absPair[0]) # delete src + shutil.copytree(absPair[1], absPair[0]) # restore from backup diff --git a/scripts/run_manual_tests.py b/scripts/run_manual_tests.py index 15afad6..5eb4d29 100644 --- a/scripts/run_manual_tests.py +++ b/scripts/run_manual_tests.py @@ -2,5 +2,6 @@ #import ManualTests.info_plist_test #import ManualTests.copy_test #import ManualTests.create_backup_test +#import ManualTests.delete_backup_test -import ManualTests.delete_backup_test \ No newline at end of file +import ManualTests.restore_backup_test \ No newline at end of file