пофиксил комманды создания/удаления/восстановления бэкапа
This commit is contained in:
parent
aba01994b3
commit
56fe80c45b
|
|
@ -1,4 +1,4 @@
|
|||
from commands.CreateBackupCommand import CreateBackupCommand
|
||||
from commands.BaseBackupCommand.CreateBackupCommand import CreateBackupCommand
|
||||
from parsers.ParserBackup.CreateBackupParser import CreateBackupParser
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
__author__ = 'rzaitov'
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -0,0 +1 @@
|
|||
__author__ = 'rzaitov'
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
@ -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<folder>[^']+)'$"
|
||||
|
||||
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
|
||||
|
|
@ -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<folder>[^']+)'$"
|
||||
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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -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<folder>[^']+)'$"
|
||||
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
|
||||
|
|
@ -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
|
||||
#import Tests.ManualTests.resolve_settings
|
||||
Loading…
Reference in New Issue