Модифицировал комманду создания бэкапа
This commit is contained in:
parent
1655b7f47a
commit
b02e7b9733
|
|
@ -1,5 +1,5 @@
|
|||
restore from backup '.' # восстанавливаем из бэкапа (исходники от сборки предыдущей конфигурации могут быть модифицированными)
|
||||
create backup for '.'
|
||||
restore from backup # восстанавливаем из бэкапа (исходники от сборки предыдущей конфигурации могут быть модифицированными)
|
||||
create backup
|
||||
|
||||
inside 'BuildSample/BuildSample.sln' remove NotCompileApp project
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from CommandBuilders.CreateBackupCommandBuilder import CreateBackupCommandBuilder
|
||||
|
||||
line = "create backup for 'BuildSample'"
|
||||
line = "create backup"
|
||||
|
||||
cmdBuilder = CreateBackupCommandBuilder()
|
||||
command = cmdBuilder.getCommandFor(line)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
self.assertEqual(False, isValid)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@ class CreateBackupParser(ParserBackupBase):
|
|||
def getMatchInfo(self, line):
|
||||
assert line is not None
|
||||
|
||||
folderNameRegexp = r"'(?P<folder>[^']+)'$"
|
||||
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue