Changeset 40967 for trunk/tools
- Timestamp:
- Oct 24, 2019, 2:41:04 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 8 deleted
- 6 edited
- 25 copied
-
. (modified) (1 prop)
-
tools (modified) (1 prop)
-
tools/backups/README (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/README )
-
tools/backups/atlassian_backups.config (deleted)
-
tools/backups/backup.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/backup.py )
-
tools/backups/backup_atlassian_applications.py (deleted)
-
tools/backups/backup_atlassian_applications_test.py (deleted)
-
tools/backups/backup_test.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/backup_test.py )
-
tools/backups/confluence_backup.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/confluence_backup.py )
-
tools/backups/confluence_backup_test.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/confluence_backup_test.py )
-
tools/backups/deploy_backups.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/deploy_backups.py )
-
tools/backups/fixture_test.py (deleted)
-
tools/backups/full_atlassian_backup_test.py (deleted)
-
tools/backups/ippops_homedir_backup.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/ippops_homedir_backup.py )
-
tools/backups/ippops_homedir_backup_test.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/ippops_homedir_backup_test.py )
-
tools/backups/jira_backup.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/jira_backup.py )
-
tools/backups/jira_backup_test.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/jira_backup_test.py )
-
tools/backups/mailman_backup.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/mailman_backup.py )
-
tools/backups/mailman_backup_test.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/mailman_backup_test.py )
-
tools/backups/svn_backup.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/svn_backup.py )
-
tools/backups/svn_backup_test.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/svn_backup_test.py )
-
tools/backups/testing/backup_test.config (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/testing/backup_test.config )
-
tools/backups/testing/confluence_test.config (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/testing/confluence_test.config )
-
tools/backups/testing/ippops_homedir_test.config (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/testing/ippops_homedir_test.config )
-
tools/backups/testing/jira_test.config (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/testing/jira_test.config )
-
tools/backups/testing/mailman_test.config (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/testing/mailman_test.config )
-
tools/backups/testing/svn_test.config (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/testing/svn_test.config )
-
tools/backups/testing/test.config (deleted)
-
tools/backups/testing/website_test.config (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/testing/website_test.config )
-
tools/backups/utils/config_parse_helper.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/utils/config_parse_helper.py )
-
tools/backups/utils/config_parse_helper_test.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/utils/config_parse_helper_test.py )
-
tools/backups/utils/database (deleted)
-
tools/backups/utils/generic_utils.py (modified) (3 diffs)
-
tools/backups/utils/generic_utils_test.py (modified) (10 diffs)
-
tools/backups/utils/python (deleted)
-
tools/backups/utils/subprocess_utils.py (modified) (3 diffs)
-
tools/backups/utils/subprocess_utils_test.py (modified) (2 diffs)
-
tools/backups/website_backup.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/website_backup.py )
-
tools/backups/website_backup_test.py (copied) (copied from branches/ipp-259_genericise_backups/tools/backups/website_backup_test.py )
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/ipp-259_genericise_backups (added) merged: 40910-40913,40915,40919-40924,40931-40932,40937,40944-40945,40949-40952,40958-40959,40962-40963,40966
- Property svn:mergeinfo changed
-
trunk/tools
- Property svn:mergeinfo changed
/branches/ipp-259_genericise_backups/tools (added) merged: 40911-40913,40915,40919-40924,40931-40932,40937,40944-40945,40949-40952,40958-40959,40962-40963,40966
- Property svn:mergeinfo changed
-
trunk/tools/backups/utils/generic_utils.py
r40898 r40967 1 import glob 1 2 import os.path as path 2 3 import shutil 4 from distutils.dir_util import copy_tree 3 5 4 from distutils.dir_util import copy_tree5 from backups.utils.errors import ValidationError6 from .subprocess_utils import simple_unix_wrapper 7 from .errors import ValidationError 6 8 7 9 … … 35 37 36 38 39 def _list_checks(sources: [str], targets: [str]): 40 if sources is None or targets is None: 41 raise ValidationError("Error: source for copy cannot be None type") 42 if targets is None: 43 raise ValidationError("Error: copy destination cannot be None type") 44 if type(sources) is not list or len(sources) == 0: 45 raise ValidationError("Error: sources must be given as a list with at least one entry") 46 if type(targets) is not list or len(targets) == 0: 47 raise ValidationError("Error: targets must be given as a list with at least one entry") 48 49 50 def copy_multiple_items_as_one_to_one(source_paths: [str], destination_paths: [str], verbose: bool=False): 51 _list_checks() 52 53 for i in range(0, len(source_paths)): 54 55 if not path.exists(destination_paths[i]): 56 if verbose: 57 print("Copy Warning: target path does not exist (skipping): ", destination_paths[i]) 58 continue 59 if not path.isdir(destination_paths[i]): 60 if verbose: 61 print("Copy Warning: target path is not a directory (skipping): ", destination_paths[i]) 62 continue 63 64 result = copy_to_dir(source_paths[i], destination_paths[i], verbose) 65 if result != 0: 66 return result 67 68 37 69 def copy_multiple_items_to_multiple_dirs(source_paths: [str], destination_paths: [str], verbose: bool=False): 38 70 """ Copies the sources to the destination paths. 39 71 40 72 This is a generic function that just wraps shutil.copy2""" 41 42 if source_paths is None: 43 raise ValidationError("Error: source for copy cannot be None type") 44 if destination_paths is None: 45 raise ValidationError("Error: copy destination cannot be None type") 46 47 if type(source_paths) is not list or len(source_paths) == 0: 48 raise ValidationError("Error: sources must be given as a list with at least one entry") 49 if type(destination_paths) is not list or len(destination_paths) == 0: 50 raise ValidationError("Error: destinations must be given as a list with at least one entry") 73 _list_checks(source_paths, destination_paths) 51 74 52 75 for dpath in destination_paths: … … 66 89 67 90 return 0 91 92 93 def move_dirs(source_dirs: [str], destination_dirs: [str], verbose: bool=False): 94 """ Moves all files from inside source paths to the destination dits. 95 It's important to note that it moves index to index 96 i.e. source[0] -> dest[0]; source[1] -> dest[1] 97 98 This is actually a pretty generic function, should be moved into a utils class. 99 """ 100 101 _list_checks(source_dirs, destination_dirs) 102 103 if len(source_dirs) != len(destination_dirs): 104 raise ValidationError("Error: source and target paths are not equal; aborting file movement") 105 106 for i in range(0, len(source_dirs)): 107 # Identify files in path, move each one: 108 wildcard_search = "{0}/*".format(source_dirs[i]) 109 filepaths = glob.glob(wildcard_search) 110 if len(filepaths) == 0: 111 print("Warning: directory is empty: ", source_dirs[i]) 112 continue 113 try: 114 for fp in filepaths: 115 if verbose: 116 print("Moving: {0} -> {1}".format(fp, destination_dirs[i])) 117 command_and_args = ["mv", fp, destination_dirs[i]] 118 # shutil.move(fp, destination_dirs[i]) 119 simple_unix_wrapper(command_and_args) 120 except IOError as e: 121 print("IOError copying: ", e.filename, e.filename2) 122 return 2 123 124 return 0 -
trunk/tools/backups/utils/generic_utils_test.py
r40898 r40967 1 import backups.utils.generic_utils as utils2 1 import os 3 2 import pytest 4 3 5 from backups.utils.errors import ValidationError 4 from .generic_utils import * 5 from .errors import ValidationError 6 6 from pathlib import Path 7 7 … … 19 19 def test_copy_fails_with_none_args(self, tmpdir): 20 20 with pytest.raises(ValidationError): 21 utils.copy_to_dir(None, tmpdir)21 copy_to_dir(None, tmpdir) 22 22 23 23 with pytest.raises(ValidationError): 24 24 real_file = make_a_real_file(tmpdir, "file.txt") 25 utils.copy_to_dir(real_file, None)25 copy_to_dir(real_file, None) 26 26 27 27 def test_copy_fails_if_source_does_not_exist(self, tmpdir): 28 28 with pytest.raises(ValidationError): 29 utils.copy_to_dir("not a real file", tmpdir)29 copy_to_dir("not a real file", tmpdir) 30 30 31 31 def test_copy_fails_if_destination_is_not_real(self, tmpdir): 32 32 with pytest.raises(ValidationError): 33 33 real_file = make_a_real_file(tmpdir, "real_file.txt") 34 utils.copy_to_dir(real_file, "not a real directory")34 copy_to_dir(real_file, "not a real directory") 35 35 36 36 def test_copy_fails_if_destination_is_not_a_directory(self, tmpdir): … … 42 42 43 43 with pytest.raises(ValidationError): 44 utils.copy_to_dir(real_file, not_a_directory)44 copy_to_dir(real_file, not_a_directory) 45 45 46 46 def test_copy_to_dir(self, tmpdir): … … 60 60 61 61 # run copy function and confirm copy exists (and original) 62 result = utils.copy_to_dir(file_to_copy, destination_dir)62 result = copy_to_dir(file_to_copy, destination_dir) 63 63 assert result == 0 64 64 assert os.path.exists(file_to_copy) … … 98 98 99 99 # Provide only the original tmpdir to the copying function 100 utils.copy_to_dir(subdir, destination_dir, True)100 copy_to_dir(subdir, destination_dir, True) 101 101 102 102 # assert that the subdirs and files all exist … … 110 110 111 111 with pytest.raises(ValidationError): 112 utils.copy_multiple_items_to_multiple_dirs(None, None)113 114 with pytest.raises(ValidationError): 115 utils.copy_multiple_items_to_multiple_dirs(tmpdir, None)116 117 with pytest.raises(ValidationError): 118 utils.copy_multiple_items_to_multiple_dirs(None, tmpdir)112 copy_multiple_items_to_multiple_dirs(None, None) 113 114 with pytest.raises(ValidationError): 115 copy_multiple_items_to_multiple_dirs(tmpdir, None) 116 117 with pytest.raises(ValidationError): 118 copy_multiple_items_to_multiple_dirs(None, tmpdir) 119 119 120 120 def test_copy_requires_args_to_be_in_list_format(self, tmpdir): … … 122 122 not_a_list = "not a list" 123 123 with pytest.raises(ValidationError): 124 utils.copy_multiple_items_to_multiple_dirs(not_a_list, tmpdir)124 copy_multiple_items_to_multiple_dirs(not_a_list, tmpdir) 125 125 126 126 tmpfile = make_a_real_file(tmpdir, "a_file.txt") 127 127 with pytest.raises(ValidationError): 128 utils.copy_multiple_items_to_multiple_dirs(tmpfile, not_a_list)128 copy_multiple_items_to_multiple_dirs(tmpfile, not_a_list) 129 129 130 130 def test_copy_is_fine_with_single_items(self, tmpdir): … … 136 136 assert not os.path.exists(expected_file) 137 137 138 result = utils.copy_multiple_items_to_multiple_dirs([tmpfile], [destination])138 result = copy_multiple_items_to_multiple_dirs([tmpfile], [destination]) 139 139 assert result == 0 140 140 assert os.path.exists(expected_file) … … 168 168 assert len(expected_files) == 9 169 169 170 result = utils.copy_multiple_items_to_multiple_dirs(source_files, dest_paths)170 result = copy_multiple_items_to_multiple_dirs(source_files, dest_paths) 171 171 assert result == 0 172 172 for ef in expected_files: … … 212 212 213 213 # Provide only the original tmpdir to the copying function 214 utils.copy_multiple_items_to_multiple_dirs([tmpdir], [destination_dir], True)214 copy_multiple_items_to_multiple_dirs([tmpdir], [destination_dir], True) 215 215 216 216 # assert that the subdirs and files all exist -
trunk/tools/backups/utils/subprocess_utils.py
r40898 r40967 2 2 3 3 # Plans are to flesh this out a bit more to make some smarter copying etc 4 from backups.utils.errors import ValidationError, SubprocessError4 from .errors import ValidationError, SubprocessError 5 5 6 6 … … 34 34 35 35 36 def local_rsync_wrapper(args: [str]): 37 if args is None: 38 raise ValidationError(f"Error:no arguments provided to {local_rsync_wrapper.__name__}") 39 command_and_args = ["rsync"] + args 40 return simple_unix_wrapper(command_and_args) 41 42 36 43 def simple_unix_wrapper(command_and_args: [str]): 37 44 """ This should provide the program name and all arguments in a list. … … 42 49 43 50 try: 44 subprocess .check_call(command_and_args)51 subprocess_exitcode = subprocess.check_call(command_and_args) 45 52 except (subprocess.CalledProcessError) as cpe: 46 53 raise SubprocessError(f"{type(cpe)} in python simple_unix_wrapper") from cpe 47 54 except (ValidationError) as ve: 48 55 raise ValidationError(f"{type(ve)} in python simple_unix_wrapper") from ve 49 return 056 return subprocess_exitcode -
trunk/tools/backups/utils/subprocess_utils_test.py
r40898 r40967 5 5 6 6 from pathlib import Path 7 from backups.utils.errors import SubprocessError, ValidationError7 from .errors import SubprocessError, ValidationError 8 8 9 9 … … 164 164 assert bool(new_stats.st_mode & stat.S_IWOTH) is True 165 165 assert bool(new_stats.st_mode & stat.S_IXOTH) is True 166 167 168 class TestLocalRsyncWrapper(object): 169 """This is essentially a copy of the 'copy' tests above. 170 """ 171 172 def test_rsync_raises_validation_error_with_no_args(self): 173 with pytest.raises(ValidationError): 174 utils.local_rsync_wrapper(None) 175 176 def test_rsync_fails_with_invalid_args(self, tmpdir): 177 with pytest.raises(SubprocessError): 178 utils.local_rsync_wrapper(["not a real file", "not a valid rsync_location"]) 179 180 def test_rsync_fails_if_source_does_not_exist(self, tmpdir): 181 with pytest.raises(SubprocessError): 182 utils.local_rsync_wrapper(["not a real file", tmpdir]) 183 184 def test_simple_rsync(self, tmpdir): 185 real_file = make_a_real_file(tmpdir, "real_file.txt") 186 expected_filepath = os.path.join(tmpdir, "copied_file.txt") 187 assert not os.path.isfile(expected_filepath) 188 189 result = utils.local_rsync_wrapper(["-v", real_file, expected_filepath]) 190 assert os.path.isfile(expected_filepath) 191 assert result == 0 192 193 def test_simple_rsync_to_directory(self, tmpdir): 194 195 # Setup source file and target dir 196 filename = "real_file.txt" 197 real_file = make_a_real_file(tmpdir, filename) 198 199 destination_dir = os.path.join(tmpdir, "destination") 200 os.makedirs(destination_dir) 201 assert os.path.exists(destination_dir) 202 203 expected_filepath = os.path.join(destination_dir, filename) 204 assert not os.path.exists(expected_filepath) 205 206 # run rsync function and confirm rsync exists (and original) 207 result = utils.local_rsync_wrapper([real_file, destination_dir]) 208 assert result == 0 209 assert os.path.isfile(real_file) 210 assert os.path.exists(expected_filepath) 211 212 def test_rsyncing_directories_and_subdirectories(self, tmpdir): 213 214 subdir = os.path.join(tmpdir, "subdir") 215 subsubdir = os.path.join(subdir, "subsubdir") 216 os.makedirs(subsubdir) 217 filename_a = "file_in_subdir.txt" 218 filename_b = "file_in_subsubdir.txt" 219 make_a_real_file(subdir, filename_a) 220 make_a_real_file(subsubdir, filename_b) 221 222 destination_dir = os.path.join(tmpdir, "destination") 223 os.makedirs(destination_dir) 224 expected_filepath_a = os.path.join(destination_dir, "subdir", filename_a) 225 expected_filepath_b = os.path.join(destination_dir, "subdir", "subsubdir", filename_b) 226 assert not os.path.exists(expected_filepath_a) 227 assert not os.path.exists(expected_filepath_b) 228 229 # silently passes without -r, just skips over directories 230 assert not os.path.exists(expected_filepath_a) 231 assert not os.path.exists(expected_filepath_b) 232 233 utils.local_rsync_wrapper([subdir, destination_dir]) 234 assert not os.path.exists(expected_filepath_a) 235 assert not os.path.exists(expected_filepath_b) 236 237 # requires -r to copy directories (and contents) 238 utils.local_rsync_wrapper(["-r", subdir, destination_dir]) 239 assert os.path.exists(expected_filepath_a) 240 assert os.path.exists(expected_filepath_b)
Note:
See TracChangeset
for help on using the changeset viewer.
