def create_backup_of_shortcuts(config, user, dry_run=False): def _create_directory_if_needed(directory): if os.path.exists(directory): return logger.debug("Creating directory: %s" % directory) os.makedirs(directory) backup_dir = backup_directory(config) if backup_dir is None: logger.info( "No backups directory specified, so not backing up shortcuts.vdf before overwriting. See config.txt for more info" ) return _create_directory_if_needed(backup_dir) if not os.path.isdir(backup_dir): logger.warning( "Backup directory path is something other than a directory. Skipping backups" ) return backup_path = shortcuts_backup_path(backup_dir, user) # Make sure the user-specific backups dir exists _create_directory_if_needed(os.path.dirname(backup_path)) shortcuts.write_shortcuts(backup_path, shortcuts.get_shortcuts(user))
def create_backup_of_shortcuts(config, user, dry_run=False): def _create_directory_if_needed(directory): if os.path.exists(directory): return logger.debug("Creating directory: %s" % directory) os.makedirs(directory) backup_dir = backup_directory(config) if backup_dir is None: logger.info("No backups directory specified, so not backing up shortcuts.vdf before overwriting. See config.txt for more info") return _create_directory_if_needed(backup_dir) if not os.path.isdir(backup_dir): logger.warning("Backup directory path is something other than a directory. Skipping backups") return backup_path = shortcuts_backup_path(backup_dir, user) # Make sure the user-specific backups dir exists _create_directory_if_needed(os.path.dirname(backup_path)) shortcuts.write_shortcuts(backup_path, shortcuts.get_shortcuts(user))
def _create_backup(self, user, dry_run=False): if dry_run: self.logger.debug("Not creating backup because its a dry run") return backup_path = self.config.shortcuts_backup_path(user) if backup_path is None: self.logger.info("No backups directory specified, so not backing up shortcuts.vdf before overwriting. See config.txt for more info") return shortcuts.write_shortcuts(backup_path, shortcuts.get_shortcuts(user))
def test_write_shortcuts_creates_file_if_it_doesnt_exist(self): d = tempfile.mkdtemp() path = os.path.join(d, "shortcuts.vdf") updated_shortcuts = [_dummy_shortcut()] self.assertFalse(os.path.exists(path)) shortcuts.write_shortcuts(path, updated_shortcuts) self.assertTrue(os.path.exists(path)) self.assertEqual(shortcuts.read_shortcuts(path), updated_shortcuts) os.remove(path) os.rmdir(d)
def _create_backup(self, user, dry_run=False): if dry_run: logger.debug("Not creating backup because its a dry run") return backup_path = self.config.shortcuts_backup_path(user) if backup_path is None: logger.info( "No backups directory specified, so not backing up shortcuts.vdf before overwriting. See config.txt for more info" ) return shortcuts.write_shortcuts(backup_path, shortcuts.get_shortcuts(user))