Реализовал создание бэкапов и восстановление из бэкапов
This commit is contained in:
parent
0594fa2644
commit
c5278ea5d0
|
|
@ -28,18 +28,21 @@ build_cmd_pattern = '{0} -v build "--configuration:{1}" "--target:Build" {2}'
|
|||
# print('finished with return code: {0}'.format(ret_code))
|
||||
|
||||
sln_dir = os.path.dirname(settings.sln_path)
|
||||
sln_file = open(settings.sln_path)
|
||||
sln_file_content = sln_file.read()
|
||||
# sln_file = open(settings.sln_path)
|
||||
# sln_file_content = sln_file.read()
|
||||
# print(sln_file_content)
|
||||
|
||||
project_description_re = re.compile(r' = "(?P<project_name>\S+)", "(?P<project_rel_path>[\S\\]+csproj)"')
|
||||
match_iter = project_description_re.finditer(sln_file_content)
|
||||
# project_description_re = re.compile(r' = "(?P<project_name>\S+)", "(?P<project_rel_path>[\S\\]+csproj)"')
|
||||
# match_iter = project_description_re.finditer(sln_file_content)
|
||||
|
||||
project_descriptions = [m.groupdict() for m in match_iter]
|
||||
for project_description in project_descriptions:
|
||||
rel_path = project_description['project_rel_path'].replace('\\', '/')
|
||||
abs_path = os.path.join(sln_dir, rel_path)
|
||||
build_cmd_text = build_cmd_pattern.format(settings.mdtool, sln_config, abs_path)
|
||||
print(build_cmd_text)
|
||||
ret_code = call(build_cmd_text, shell=True)
|
||||
print('finished with return code: {0}'.format(ret_code))
|
||||
# project_descriptions = [m.groupdict() for m in match_iter]
|
||||
# for project_description in project_descriptions:
|
||||
# rel_path = project_description['project_rel_path'].replace('\\', '/')
|
||||
# abs_path = os.path.join(sln_dir, rel_path)
|
||||
# build_cmd_text = build_cmd_pattern.format(settings.mdtool, sln_config, abs_path)
|
||||
# print(build_cmd_text)
|
||||
# ret_code = call(build_cmd_text, shell=True)
|
||||
# print('finished with return code: {0}'.format(ret_code))
|
||||
|
||||
# instruments.CreateOrRestoreFromBackup(sln_dir, settings.files_for_backup)
|
||||
# instruments.DeleteBackups(sln_dir, settings.files_for_backup)
|
||||
|
|
@ -1,18 +1,52 @@
|
|||
import shutil
|
||||
import os
|
||||
|
||||
def CreateOrRestoreFromBackup(base_dir, relative_path_to_files):
|
||||
|
||||
for rel_path in relative_path_to_files:
|
||||
def MapToBackupName(origin_path):
|
||||
|
||||
abs_path = os.path.join(base_dir, rel_path)
|
||||
abs_path_backup = "{0}.build_backup".format(os.path)
|
||||
|
||||
if os.path.exists(abs_path_backup):
|
||||
backup_path = "{0}.build_backup".format(origin_path)
|
||||
return backup_path
|
||||
|
||||
def FetchAbsOriginBackupInfo(base_dir, rel_path_to_origin_files):
|
||||
|
||||
abs_path_to_origin_files = [os.path.join(base_dir, rel) for rel in rel_path_to_origin_files]
|
||||
abs_origin_backup_infos = [{'origin': p, 'backup': MapToBackupName(p)} for p in abs_path_to_origin_files]
|
||||
|
||||
return abs_origin_backup_infos
|
||||
|
||||
def CreateOrRestoreFromBackup(base_dir, relative_path_to_files):
|
||||
|
||||
abs_origin_backup_infos = FetchAbsOriginBackupInfo(base_dir, relative_path_to_files)
|
||||
|
||||
for aobi in abs_origin_backup_infos:
|
||||
|
||||
abs_original = aobi['origin']
|
||||
abs_backup = aobi['backup']
|
||||
|
||||
if os.path.exists(abs_backup):
|
||||
# restore from backup
|
||||
shutil.copyfile(abs_path_backup, abs_path)
|
||||
shutil.copyfile(abs_backup, abs_original)
|
||||
else:
|
||||
# create backup
|
||||
shutil.copyfile(abs_path, abs_path_backup)
|
||||
shutil.copyfile(abs_original, abs_backup)
|
||||
|
||||
return None
|
||||
|
||||
def DeleteBackups(base_dir, relative_path_to_files):
|
||||
|
||||
abs_origin_backup_infos = FetchAbsOriginBackupInfo(base_dir, relative_path_to_files)
|
||||
|
||||
for aobi in abs_origin_backup_infos:
|
||||
|
||||
abs_backup = aobi['backup']
|
||||
|
||||
if os.path.exists(abs_backup):
|
||||
os.remove(abs_backup)
|
||||
|
||||
return None
|
||||
|
||||
def ResetDirectory(base_dir, relative_path_to_files):
|
||||
|
||||
CreateOrRestoreFromBackup(base_dir, relative_path_to_files)
|
||||
DeleteBackups(base_dir, relative_path_to_files)
|
||||
|
||||
return None
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
mdtool = "/Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool"
|
||||
sln_path = "/Users/rzaitov/Documents/Apps/BuildScript/BuildSample/BuildSample.sln"
|
||||
|
||||
files_for_backup = ["BuildSample.sln", "BuildSample/CoolApp.csproj"]
|
||||
projects_to_exclude = ["NotCompileApp"]
|
||||
Loading…
Reference in New Issue