diff --git a/scripts/TouchinBuild/CommandBuilders/CreateBackupCommandBuilder.py b/scripts/TouchinBuild/CommandBuilders/CreateBackupCommandBuilder.py index c6719da..a1de956 100644 --- a/scripts/TouchinBuild/CommandBuilders/CreateBackupCommandBuilder.py +++ b/scripts/TouchinBuild/CommandBuilders/CreateBackupCommandBuilder.py @@ -1,4 +1,4 @@ -from commands.CreateBackupCommand import CreateBackupCommand +from commands.BaseBackupCommand.CreateBackupCommand import CreateBackupCommand from parsers.ParserBackup.CreateBackupParser import CreateBackupParser diff --git a/scripts/TouchinBuild/CommandBuilders/DeleteBackupCommandBuilder.py b/scripts/TouchinBuild/CommandBuilders/DeleteBackupCommandBuilder.py index 4e66812..05d0720 100644 --- a/scripts/TouchinBuild/CommandBuilders/DeleteBackupCommandBuilder.py +++ b/scripts/TouchinBuild/CommandBuilders/DeleteBackupCommandBuilder.py @@ -1,4 +1,4 @@ -from commands.DeleteBackupCommand import DeleteBackupCommand +from commands.BaseBackupCommand.DeleteBackupCommand import DeleteBackupCommand from parsers.ParserBackup.DeleteBackupParser import DeleteBackupParser @@ -18,7 +18,7 @@ class DeleteBackupCommandBuilder: assert line is not None parser = DeleteBackupParser() - parser.parseLine(line) + backupArguments = parser.parseLine(line) - command = DeleteBackupCommand() + command = DeleteBackupCommand(backupArguments) return command diff --git a/scripts/TouchinBuild/CommandBuilders/RestoreBackupCommandBuilder.py b/scripts/TouchinBuild/CommandBuilders/RestoreBackupCommandBuilder.py index dc9404b..bef5c0c 100644 --- a/scripts/TouchinBuild/CommandBuilders/RestoreBackupCommandBuilder.py +++ b/scripts/TouchinBuild/CommandBuilders/RestoreBackupCommandBuilder.py @@ -1,4 +1,4 @@ -from commands.RestoreBackupCommand import RestoreBackupCommand +from commands.BaseBackupCommand.RestoreBackupCommand import RestoreBackupCommand from parsers.ParserBackup.RestoreBackupParser import RestoreBackupParser @@ -18,7 +18,7 @@ class RestoreBackupCommandBuilder: assert line is not None parser = RestoreBackupParser() - parser.parseLine(line) + backupArguments = parser.parseLine(line) - command = RestoreBackupCommand() + command = RestoreBackupCommand(backupArguments) return command diff --git a/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/__init__.py b/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/__init__.py new file mode 100644 index 0000000..cc31abc --- /dev/null +++ b/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/__init__.py @@ -0,0 +1 @@ +__author__ = 'rzaitov' diff --git a/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/test_create_backup.py b/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/test_create_backup.py new file mode 100644 index 0000000..43af7bb --- /dev/null +++ b/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/test_create_backup.py @@ -0,0 +1,25 @@ +import unittest +from parsers.ParserBackup.CreateBackupParser import CreateBackupParser + + +class TestCreateBackup(unittest.TestCase): + def setUp(self): + self.parser = CreateBackupParser() + + def test_parseCurrentDir(self): + line = "create backup for '.'" + backupArg = self.parser.parseLine(line) + + self.assertEqual('.', backupArg.folderPath) + + def test_parseRelativePath(self): + line = "create backup for '../Some/Path'" + backupArg = self.parser.parseLine(line) + + self.assertEqual('../Some/Path', backupArg.folderPath) + + def test_parseAbsPath(self): + line = "create backup for '/Some/Abs/Path'" + backupArg = self.parser.parseLine(line) + + self.assertEqual('/Some/Abs/Path', backupArg.folderPath) \ No newline at end of file diff --git a/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/test_deleteBackup.py b/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/test_deleteBackup.py new file mode 100644 index 0000000..153da7b --- /dev/null +++ b/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/test_deleteBackup.py @@ -0,0 +1,25 @@ +import unittest +from parsers.ParserBackup.DeleteBackupParser import DeleteBackupParser + + +class TestDeleteBackup(unittest.TestCase): + def setUp(self): + self.parser = DeleteBackupParser() + + def test_parseCurrentDir(self): + line = "delete backup '.'" + backupArg = self.parser.parseLine(line) + + self.assertEqual('.', backupArg.folderPath) + + def test_parseRelativePath(self): + line = "delete backup '../Some/Path'" + backupArg = self.parser.parseLine(line) + + self.assertEqual('../Some/Path', backupArg.folderPath) + + def test_parseAbsPath(self): + line = "delete backup '/Some/Abs/Path'" + backupArg = self.parser.parseLine(line) + + self.assertEqual('/Some/Abs/Path', backupArg.folderPath) \ No newline at end of file diff --git a/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/test_restoreBackup.py b/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/test_restoreBackup.py new file mode 100644 index 0000000..589e897 --- /dev/null +++ b/scripts/TouchinBuild/Tests/UnitTests/ParserBackup/test_restoreBackup.py @@ -0,0 +1,25 @@ +import unittest +from parsers.ParserBackup.RestoreBackupParser import RestoreBackupParser + + +class TestRestoreBackup(unittest.TestCase): + def setUp(self): + self.parser = RestoreBackupParser() + + def test_parseCurrentDir(self): + line = "restore from backup '.'" + backupArg = self.parser.parseLine(line) + + self.assertEqual('.', backupArg.folderPath) + + def test_parseRelativePath(self): + line = "restore from backup '../Some/Path'" + backupArg = self.parser.parseLine(line) + + self.assertEqual('../Some/Path', backupArg.folderPath) + + def test_parseAbsPath(self): + line = "restore from backup '/Some/Abs/Path'" + backupArg = self.parser.parseLine(line) + + self.assertEqual('/Some/Abs/Path', backupArg.folderPath) \ No newline at end of file diff --git a/scripts/TouchinBuild/commands/BaseBackupCommand/BaseBackupCommand.py b/scripts/TouchinBuild/commands/BaseBackupCommand/BaseBackupCommand.py new file mode 100644 index 0000000..1ac6215 --- /dev/null +++ b/scripts/TouchinBuild/commands/BaseBackupCommand/BaseBackupCommand.py @@ -0,0 +1,17 @@ +import os + + +class BaseBackupCommand: + def __init__(self, backupArguments): + assert backupArguments is not None + + self.backupArguments = backupArguments + + def getAbsSrc(self): + return self.getAbs(self.backupArguments.getSourceFolderName()) + + def getAbsDst(self): + return self.getAbs(self.backupArguments.getBackupFolderName()) + + 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 new file mode 100644 index 0000000..f7ae199 --- /dev/null +++ b/scripts/TouchinBuild/commands/BaseBackupCommand/CreateBackupCommand.py @@ -0,0 +1,14 @@ +import shutil +from commands.BaseBackupCommand.BaseBackupCommand import BaseBackupCommand + + +class CreateBackupCommand(BaseBackupCommand): + def __init__(self, backupArguments): + BaseBackupCommand.__init__(self, backupArguments) + + def execute(self): + src = self.getAbsSrc() + backupDir = self.getAbsDst() + + shutil.rmtree(backupDir, ignore_errors=True) + shutil.copytree(src, backupDir, symlinks=False) diff --git a/scripts/TouchinBuild/commands/BaseBackupCommand/DeleteBackupCommand.py b/scripts/TouchinBuild/commands/BaseBackupCommand/DeleteBackupCommand.py new file mode 100644 index 0000000..1e0c319 --- /dev/null +++ b/scripts/TouchinBuild/commands/BaseBackupCommand/DeleteBackupCommand.py @@ -0,0 +1,12 @@ +import shutil +from commands.BaseBackupCommand.BaseBackupCommand import BaseBackupCommand + + +class DeleteBackupCommand(BaseBackupCommand): + def __init__(self, backupArguments): + BaseBackupCommand.__init__(self, backupArguments) + + def execute(self): + backupDir = self.getAbsDst() + + shutil.rmtree(backupDir, ignore_errors=True) diff --git a/scripts/TouchinBuild/commands/BaseBackupCommand/RestoreBackupCommand.py b/scripts/TouchinBuild/commands/BaseBackupCommand/RestoreBackupCommand.py new file mode 100644 index 0000000..35ac176 --- /dev/null +++ b/scripts/TouchinBuild/commands/BaseBackupCommand/RestoreBackupCommand.py @@ -0,0 +1,14 @@ +import shutil +from commands.BaseBackupCommand.BaseBackupCommand import BaseBackupCommand + + +class RestoreBackupCommand(BaseBackupCommand): + def __init__(self, backupArguments): + BaseBackupCommand.__init__(self, backupArguments) + + def execute(self): + src = self.getAbsSrc() + backupDir = self.getAbsDst() + + shutil.rmtree(src, ignore_errors=True) + shutil.copytree(backupDir, src, symlinks=False) diff --git a/scripts/TouchinBuild/commands/BaseBackupCommand/__init__.py b/scripts/TouchinBuild/commands/BaseBackupCommand/__init__.py new file mode 100644 index 0000000..cc31abc --- /dev/null +++ b/scripts/TouchinBuild/commands/BaseBackupCommand/__init__.py @@ -0,0 +1 @@ +__author__ = 'rzaitov' diff --git a/scripts/TouchinBuild/commands/CreateBackupCommand.py b/scripts/TouchinBuild/commands/CreateBackupCommand.py deleted file mode 100644 index fde6715..0000000 --- a/scripts/TouchinBuild/commands/CreateBackupCommand.py +++ /dev/null @@ -1,14 +0,0 @@ -import shutil - -class CreateBackupCommand: - def __init__(self, backupArguments): - assert backupArguments is not None - - self.__backupArguments = backupArguments - - def execute(self): - src = self.__backupArguments.getSourceFolderName() - dst = self.__backupArguments.getBackupFolderName() - - shutil.rmtree(dst, ignore_errors=True) - shutil.copytree(src, dst, symlinks=False) diff --git a/scripts/TouchinBuild/commands/DeleteBackupCommand.py b/scripts/TouchinBuild/commands/DeleteBackupCommand.py deleted file mode 100644 index ac5dddc..0000000 --- a/scripts/TouchinBuild/commands/DeleteBackupCommand.py +++ /dev/null @@ -1,11 +0,0 @@ -import os -import shutil - -class DeleteBackupCommand: - def __init__(self): - pass - - def execute(self): - dirs = [name for name in os.listdir('.') if os.path.isdir(os.path.join('.', name)) & name.startswith('backup.')] - for d in dirs: - shutil.rmtree(d) \ No newline at end of file diff --git a/scripts/TouchinBuild/commands/RestoreBackupCommand.py b/scripts/TouchinBuild/commands/RestoreBackupCommand.py deleted file mode 100644 index dfb9247..0000000 --- a/scripts/TouchinBuild/commands/RestoreBackupCommand.py +++ /dev/null @@ -1,18 +0,0 @@ -import os -import shutil - - -class RestoreBackupCommand: - def __init__(self): - pass - - def execute(self): - dirPairs = [(name, "backup.{0}".format(name)) for name in os.listdir('.') if os.path.isdir(name) and not name.startswith('backup.')] - - for pair in dirPairs: - absPair = (pair[0], pair[1]) - if not os.path.exists(absPair[1]): - continue - - shutil.rmtree(absPair[0]) # delete src - shutil.copytree(absPair[1], absPair[0]) # restore from backup diff --git a/scripts/TouchinBuild/parsers/ParserBackup/BackupArguments.py b/scripts/TouchinBuild/parsers/ParserBackup/BackupArguments.py new file mode 100644 index 0000000..fd8d84a --- /dev/null +++ b/scripts/TouchinBuild/parsers/ParserBackup/BackupArguments.py @@ -0,0 +1,11 @@ +class BackupArguments: + def __init__(self): + self.folderPath = None + + def getSourceFolderName(self): + return self.folderPath + + def getBackupFolderName(self): + return "backup.{0}".format(self.folderPath) + + diff --git a/scripts/TouchinBuild/parsers/ParserBackup/CreateBackupArguments.py b/scripts/TouchinBuild/parsers/ParserBackup/CreateBackupArguments.py deleted file mode 100644 index fbeea2b..0000000 --- a/scripts/TouchinBuild/parsers/ParserBackup/CreateBackupArguments.py +++ /dev/null @@ -1,11 +0,0 @@ -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/TouchinBuild/parsers/ParserBackup/CreateBackupParser.py b/scripts/TouchinBuild/parsers/ParserBackup/CreateBackupParser.py index f8a782c..cd9462b 100644 --- a/scripts/TouchinBuild/parsers/ParserBackup/CreateBackupParser.py +++ b/scripts/TouchinBuild/parsers/ParserBackup/CreateBackupParser.py @@ -1,32 +1,19 @@ import re -from parsers.ParserBackup.CreateBackupArguments import CreateBackupArguments -from parsers.LineParser import LineParser +from parsers.ParserBackup.ParserBackupBase import ParserBackupBase -class CreateBackupParser(LineParser): +class CreateBackupParser(ParserBackupBase): def __init__(self): - LineParser.__init__(self) - self.__createBackupArguments = CreateBackupArguments() + ParserBackupBase.__init__(self) - def parseLine(self, line): + def getMatchInfo(self, line): assert line is not None folderNameRegexp = r"'(?P[^']+)'$" - regexpSource = self.startsWith('create backup for') + folderNameRegexp + regexpSource = self.startsWith('create') + self.than('backup') + self.than('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 + return match, regexpSource \ No newline at end of file diff --git a/scripts/TouchinBuild/parsers/ParserBackup/DeleteBackupParser.py b/scripts/TouchinBuild/parsers/ParserBackup/DeleteBackupParser.py index 2b4e3cc..c210f32 100644 --- a/scripts/TouchinBuild/parsers/ParserBackup/DeleteBackupParser.py +++ b/scripts/TouchinBuild/parsers/ParserBackup/DeleteBackupParser.py @@ -1,23 +1,18 @@ import re -from parsers.LineParser import LineParser +from parsers.ParserBackup.ParserBackupBase import ParserBackupBase -class DeleteBackupParser(LineParser): +class DeleteBackupParser(ParserBackupBase): def __init__(self): - LineParser.__init__(self) + ParserBackupBase.__init__(self) - def parseLine(self, line): + def getMatchInfo(self, line): assert line is not None - regexpSource = r'delete backup\s*' + folderNameRegexp = r"'(?P[^']+)'$" + regexpSource = self.startsWith('delete') + self.than('backup') + folderNameRegexp 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 + return match, regexpSource \ No newline at end of file diff --git a/scripts/TouchinBuild/parsers/ParserBackup/ParserBackupBase.py b/scripts/TouchinBuild/parsers/ParserBackup/ParserBackupBase.py new file mode 100644 index 0000000..96ffba6 --- /dev/null +++ b/scripts/TouchinBuild/parsers/ParserBackup/ParserBackupBase.py @@ -0,0 +1,36 @@ +import re + +from parsers.LineParser import LineParser +from parsers.ParserBackup.BackupArguments import BackupArguments + + +class ParserBackupBase(LineParser): + def __init__(self): + LineParser.__init__(self) + self.__backupArguments = BackupArguments() + + def parseLine(self, line): + assert line is not None + + mathInfo = self.getMatchInfo(line) + match = mathInfo[0] + regexpSource = mathInfo[1] + + self._guardMatch(match, line, regexpSource) + + folderName = match.group('folder') + self.__backupArguments.folderPath = folderName + + return self.__backupArguments + + def getMatchInfo(self, line): + return None, None + + def isValidLine(self, line): + assert line is not None + + matchInfo = self.getMatchInfo(line) + match = matchInfo[0] + + return match is not None + diff --git a/scripts/TouchinBuild/parsers/ParserBackup/RestoreBackupParser.py b/scripts/TouchinBuild/parsers/ParserBackup/RestoreBackupParser.py index 5a6c10f..54285a6 100644 --- a/scripts/TouchinBuild/parsers/ParserBackup/RestoreBackupParser.py +++ b/scripts/TouchinBuild/parsers/ParserBackup/RestoreBackupParser.py @@ -1,24 +1,18 @@ import re -from parsers.LineParser import LineParser +from parsers.ParserBackup.ParserBackupBase import ParserBackupBase -class RestoreBackupParser(LineParser): +class RestoreBackupParser(ParserBackupBase): def __init__(self): - LineParser.__init__(self) + ParserBackupBase.__init__(self) - def parseLine(self, line): + def getMatchInfo(self, line): assert line is not None - regexpSource = self.startsWith('restore') + self.than('from') + self.endsWith('backup') + folderNameRegexp = r"'(?P[^']+)'$" + regexpSource = self.startsWith('restore') + self.than('from') + self.than('backup') + folderNameRegexp 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') - return isValid - + return match, regexpSource \ No newline at end of file diff --git a/scripts/TouchinBuild/run_manual_tests.py b/scripts/TouchinBuild/run_manual_tests.py index bee8872..c0fff48 100644 --- a/scripts/TouchinBuild/run_manual_tests.py +++ b/scripts/TouchinBuild/run_manual_tests.py @@ -9,9 +9,9 @@ os.chdir(baseDir) #import Tests.ManualTests.csproj_test #import ManualTests.info_plist_test #import ManualTests.copy_test -#import ManualTests.create_backup_test -#import ManualTests.delete_backup_test -#import ManualTests.restore_backup_test +import Tests.ManualTests.create_backup_test +#import Tests.ManualTests.delete_backup_test +#import Tests.ManualTests.restore_backup_test #import ManualTests.csproj_test #import ManualTests.run_sh_command #import ManualTests.make_dirs @@ -21,5 +21,4 @@ os.chdir(baseDir) #import Tests.ManualTests.testflight_test #import Tests.ManualTests.install_profile #import Tests.ManualTests.macros_include_test - -import Tests.ManualTests.resolve_settings \ No newline at end of file +#import Tests.ManualTests.resolve_settings \ No newline at end of file