Example #1
0
def install_file( config, install_file, new_file):
    if(fileu.locate_file(config[install_file])):
        prnt.prnt( '-s', 'Located '+config[install_file]+' file!')
        try:
            fileu.copy_file(new_file, config[install_file])
            prnt.prnt( '-s', 'Installed the new file successfully!')
            return True
        except:
            prnt.prnt( '-f', 'Failed to install the new file!')
            return False
    else:
        prnt.prnt( '-f', 'Could not locate '+config[install_file]+' file!')
        return False
Example #2
0
def backup_file(config, back_file, destination):
    if (fileu.locate_file(config[back_file])):
        prnt.prnt('-s', 'Located your ' + config[back_file] + ' file!')
        try:
            fileu.copy_file(config[back_file], destination)
            prnt.prnt('-s', 'Backed it up successfully!')
            return True
        except:
            prnt.prnt('-f', 'Failed to back it up!')
            return False
    else:
        prnt.prnt('-f', 'Could not locate ' + config[back_file] + ' file!')
        return False
Example #3
0
def perform_backup(backup_config):
    """
    Performs backup according to provided config.
    """
    try:
        logging.info("Performing backup task: " + backup_config.__str__())

        logging.info("Archiving directory: " + backup_config.source)
        archive_file_path = fileutils.archive_dir(backup_config.source, ARCHIVE_FORMATS[3])
        logging.info("Copying archive to target directory: " + backup_config.target)
        fileutils.copy_file(archive_file_path, backup_config.target)

        logging.info("Backup complete")
    except Exception as ex:
        raise TaskError("Failed to perform backup: " + ex.__str__())
Example #4
0
def replace_wallpaper( configuration, json_file):
    prnt.prnt( '-n', 'Replacing wallpaper')

    if( fileu.locate_file(configuration['nitrogen-config'])):
        prnt.prnt( '-s', 'Located your nitrogen configuration file')
        if 'wallpaper' in json_file:
            wallpaper = json_file['wallpaper']
            prnt.prnt( '-s', 'Found the wallpaper info in the JSON file')

            rl.replace_line( configuration['nitrogen-config'], 'file', 'file= '+configuration['wallpaper-path']+wallpaper)
            new_file='wallpapers/'+wallpaper
            try:
                fileu.copy_file(new_file, configuration['wallpaper-path']+wallpaper)
                prnt.prnt( '-s', 'Installed the new file successfully!')
                return True
            except:
                prnt.prnt( '-f', 'Failed to install the new file!')
                return False
    else:
        prnt.prnt( '-f', 'Failed to locate your nitrogen configuration file')
Example #5
0
def perform_backup_check(backup_config):
    """
    Checks if backup was performed correctly according to specified config.
    """
    try:
        logging.info("Checking backup: " + backup_config.__str__())

        archive_path = get_newest_archive_path(backup_config.target)
        if not archive_path:
            raise TaskError("No archive was found in the target dir: " + backup_config.target)
        logging.info("Copying newest archive: " + archive_path)
        tmp_archive = fileutils.copy_file(archive_path, fileutils.get_tmp_remote_dir())
        logging.info("Checking archive consistency.")
        inconsistencies = fileutils.compare_archive_against_dir(tmp_archive, backup_config.source, backup_config.excludeRegexp)

        logging.info("Backup check completed")
        if inconsistencies:
            raise ArchiveIntegrityError("Found inconsistencies while checking archive and source.", inconsistencies)
    except ArchiveIntegrityError as ex:
        raise ex
    except Exception as ex:
        raise TaskError("Could not check backup: " + ex.__str__())