IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 4, 2019, 12:03:16 PM (7 years ago)
Author:
fairlamb
Message:

remove function, use from generic utils instead

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ipp-259_genericise_backups/tools/backups/backup_atlassian_applications.py

    r40898 r40911  
    1010
    1111import backups.utils.subprocess_utils as sub_utils
     12import backups.utils.generic_utils as gen_utils
    1213from backups.utils.errors import ConfigError, SubprocessError
    1314
    1415DEFAULT_CONFIG_FILE = path.join(path.dirname(__file__), 'atlassian_backups.config')
    15 
    16 
    17 def _move_dir_contents_to_dir(source_dirs: [str], destination_dirs: [str], verbose: bool=False):
    18     """ Moves all files from inside source paths to the destination dits.
    19 It's important to note that it moves index to index
    20 i.e. source[0] -> dest[0]; source[1] -> dest[1]
    21 
    22 This is actually a pretty generic function, should be moved into a utils class.
    23 """
    24 
    25     if source_dirs is None or destination_dirs is None:
    26         print("Error: You need to supply a source and destination")
    27         return 2
    28     if type(source_dirs) != list or type(destination_dirs) != list:
    29         print("Error: source_dirs and destination_dirs must be type: list")
    30         print("     type {0} and {1} given".format(type(source_dirs), type(destination_dirs)))
    31         return 2
    32     if len(source_dirs) != len(destination_dirs):
    33         print("Error: source and target paths are not equal; aborting file movement")
    34         return 2
    35 
    36     for i in range(0, len(source_dirs)):
    37         # Identify files in path, move each one:
    38         wildcard_search = "{0}/*".format(source_dirs[i])
    39         filepaths = glob.glob(wildcard_search)
    40         if len(filepaths) == 0:
    41             print("Warning: directory is empty: ", source_dirs[i])
    42             continue
    43         try:
    44             for fp in filepaths:
    45                 if verbose:
    46                     print("Moving: {0} -> {1}".format(fp, destination_dirs[i]))
    47                 command_and_args = ["mv", fp, destination_dirs[i]]
    48                 # shutil.move(fp, destination_dirs[i])
    49                 sub_utils.simple_unix_wrapper(command_and_args)
    50         except IOError as e:
    51             print("IOError copying: ", e.filename, e.filename2)
    52             return 2
    53 
    54     return 0
    5516
    5617
     
    12990
    13091        # Move latest to tmp (and delete if move ok)
    131         _move_dir_contents_to_dir(latest_paths, tmp_paths, self.verbose)
     92        gen_utils.copy_multiple_items_to_multiple_dirs(latest_paths, tmp_paths, self.verbose)
    13293
    13394        # copy jira
     
    145106        # If successful: move tmp to old
    146107        if jira_return == 0 and conf_return == 0 and tar_return == 0 and mysqldump_return == 0:
    147             _move_dir_contents_to_dir(tmp_paths, old_paths, self.verbose)
     108            gen_utils.copy_multiple_items_to_multiple_dirs(tmp_paths, old_paths, self.verbose)
    148109        else:
    149110            # If any failed: delete latest, move tmp back
    150             _move_dir_contents_to_dir(tmp_paths, latest_paths, self.verbose)
     111            gen_utils.copy_multiple_items_to_multiple_dirs(tmp_paths, latest_paths, self.verbose)
    151112            return 5
    152113
Note: See TracChangeset for help on using the changeset viewer.