BackupManager

class BackupManager(data_root, backups_root=None)[source]

Methods

hed.tools.remodeling.backup_manager.BackupManager.__init__(...)

Constructor for the backup manager.

hed.tools.remodeling.backup_manager.BackupManager.create_backup(...)

Create a new backup from file_list.

hed.tools.remodeling.backup_manager.BackupManager.get_backup(...)

Return the dictionary corresponding to backup_name.

hed.tools.remodeling.backup_manager.BackupManager.get_backup_files(...)

Returns a list of full paths of files contained in the backup.

hed.tools.remodeling.backup_manager.BackupManager.get_backup_path(...)

Retrieve the file from the backup or throw an error.

hed.tools.remodeling.backup_manager.BackupManager.get_file_key(...)

hed.tools.remodeling.backup_manager.BackupManager.get_task(...)

Return the task if the file name contains a task_xxx where xxx is in task_names.

hed.tools.remodeling.backup_manager.BackupManager.restore_backup([...])

Restore the files from backup_name to the main directory.

Attributes

hed.tools.remodeling.backup_manager.BackupManager.BACKUP_DICTIONARY

hed.tools.remodeling.backup_manager.BackupManager.BACKUP_ROOT

hed.tools.remodeling.backup_manager.BackupManager.DEFAULT_BACKUP_NAME

hed.tools.remodeling.backup_manager.BackupManager.RELATIVE_BACKUP_LOCATION

BackupManager.__init__(data_root, backups_root=None)[source]

Constructor for the backup manager.

Parameters:
  • data_root (str) – Full path of the root of the data directory.

  • backups_root (str or None) – Full path to the root where backups subdirectory is located.

Raises:

HedFileError

  • If the data_root does not correspond to a real directory.

Notes: The backup_root will have remodeling/backups appended.

BackupManager.create_backup(file_list, backup_name=None, verbose=False)[source]

Create a new backup from file_list.

Parameters:
  • file_list (list) – Full paths of the files to be in the backup.

  • backup_name (str or None) – Name of the backup. If None, uses the default

  • verbose (bool) – If True, print out the files that are being backed up.

Returns:

True if the backup was successful. False if a backup of that name already exists.

Return type:

bool

Raises:
  • HedFileError

    • For missing or incorrect files.

  • OS-related error

    • OS-related error when file copying occurs.

BackupManager.get_backup(backup_name)[source]

Return the dictionary corresponding to backup_name.

Parameters:

backup_name (str) – Name of the backup to be retrieved.

Returns:

The dictionary with the backup info.

Notes

The dictionary with backup information has keys that are the paths of the backed up files relative to the backup root. The values in this dictionary are the dates on which the particular file was backed up.

BackupManager.get_backup_files(backup_name, original_paths=False)[source]

Returns a list of full paths of files contained in the backup.

Parameters:
  • backup_name (str) – Name of the backup.

  • original_paths (bool) – If true return the original paths.

Returns:

Full paths of the original files backed (original_paths=True) or the paths in the backup.

Return type:

list

Raises:

HedFileError

  • If not backup named backup_name exists.

BackupManager.get_backup_path(backup_name, file_name)[source]

Retrieve the file from the backup or throw an error.

Parameters:
  • backup_name (str) – Name of the backup.

  • file_name (str) – Full path of the file to be retrieved.

Returns:

Full path of the corresponding file in the backup.

Return type:

str

BackupManager.get_file_key(file_name)[source]
static BackupManager.get_task(task_names, file_path)[source]

Return the task if the file name contains a task_xxx where xxx is in task_names.

Parameters:
  • task_names (list) – List of task names (without the task_ prefix).

  • file_path (str) – Path of the filename to be tested.

Returns:

the task name or ‘’ if there is no task_xxx or xxx is not in task_names.

Return type:

str

BackupManager.restore_backup(backup_name='default_back', task_names=[], verbose=True)[source]

Restore the files from backup_name to the main directory.

Parameters:
  • backup_name (str) – Name of the backup to restore.

  • task_names (list) – A list of task names to restore.

  • verbose (bool) – If true, print out the file names being restored.

BackupManager.BACKUP_DICTIONARY = 'backup_lock.json'
BackupManager.BACKUP_ROOT = 'backup_root'
BackupManager.DEFAULT_BACKUP_NAME = 'default_back'
BackupManager.RELATIVE_BACKUP_LOCATION = './derivatives/remodel/backups'