Exemple #1
0
def purge_data_nav(force=False):
    """
    purge temp/data.nav.lz4 files
    the whole process will be skipped as soon as a single condition is encountered:
    - temp data file is more recent than actual data file
    - temp data file exists but actual data file is missing
    """
    if not force:
        print("Checking lz4 temp files purge conditions before proceeding...")
        reason = {}
        for instance in env.instances.values():
            plain_target = get_real_instance(instance).target_lz4_file
            temp_target = os.path.join(os.path.dirname(plain_target), 'temp', os.path.basename(plain_target))
            if exists(plain_target):
                if exists(temp_target) and files.getmtime(temp_target) > files.getmtime(plain_target):
                    reason[instance.name] = "{} is more recent than {}".format(temp_target, plain_target)
            elif exists(temp_target):
                reason[instance.name] = "{} does not exists".format(plain_target)
        if reason:
            print(yellow("Error: Can't purge lz4 temp files, reasons:"))
            for k, v in reason.iteritems():
                print("  {}: {}".format(k, v))
            exit(1)

    for instance in env.instances.values():
        plain_target = get_real_instance(instance).target_lz4_file
        temp_target = os.path.join(os.path.dirname(plain_target), 'temp', os.path.basename(plain_target))
        if exists(temp_target):
            files.remove(temp_target)
Exemple #2
0
def purge_data_nav(force=False):
    """
    purge temp/data.nav.lz4 files
    the whole process will be skipped as soon as a single condition is encountered:
    - temp data file is more recent than actual data file
    - temp data file exists but actual data file is missing
    """
    if not force:
        print("Checking lz4 temp files purge conditions before proceeding...")
        reason = {}
        for instance in env.instances.values():
            plain_target = get_real_instance(instance).target_lz4_file
            temp_target = os.path.join(os.path.dirname(plain_target), 'temp',
                                       os.path.basename(plain_target))
            if exists(plain_target):
                if exists(temp_target) and files.getmtime(
                        temp_target) > files.getmtime(plain_target):
                    reason[instance.name] = "{} is more recent than {}".format(
                        temp_target, plain_target)
            elif exists(temp_target):
                reason[instance.name] = "{} does not exists".format(
                    plain_target)
        if reason:
            print(yellow("Error: Can't purge lz4 temp files, reasons:"))
            for k, v in reason.iteritems():
                print("  {}: {}".format(k, v))
            exit(1)

    for instance in env.instances.values():
        plain_target = get_real_instance(instance).target_lz4_file
        temp_target = os.path.join(os.path.dirname(plain_target), 'temp',
                                   os.path.basename(plain_target))
        if exists(temp_target):
            files.remove(temp_target)
Exemple #3
0
def swap_data_nav(instance, force=False):
    """ swap old/new data.nav.lz4, only if new is still in temp directory
    """
    plain_target = get_real_instance(instance).target_lz4_file
    temp_target = os.path.join(os.path.dirname(plain_target), 'temp', os.path.basename(plain_target))
    if exists(plain_target):
        if exists(temp_target) and \
           (force or (files.getmtime(temp_target) > files.getmtime(plain_target))):
            swap_temp = os.path.join(os.path.dirname(temp_target), 'x')
            files.move(plain_target, swap_temp)
            files.move(temp_target, plain_target)
            files.move(swap_temp, temp_target)
    elif exists(temp_target):
        files.move(temp_target, plain_target)
Exemple #4
0
def swap_data_nav(instance, force=False):
    """ swap old/new data.nav.lz4, only if new is still in temp directory
    """
    plain_target = get_real_instance(instance).target_lz4_file
    temp_target = os.path.join(os.path.dirname(plain_target), 'temp', os.path.basename(plain_target))
    if exists(plain_target):
        if exists(temp_target) and \
           (force or (files.getmtime(temp_target) > files.getmtime(plain_target))):
            swap_temp = os.path.join(os.path.dirname(temp_target), 'x')
            files.move(plain_target, swap_temp)
            files.move(temp_target, plain_target)
            files.move(swap_temp, temp_target)
    elif exists(temp_target):
        files.move(temp_target, plain_target)
Exemple #5
0
def last_update_time():
    """
    Return the time of last update-check.
    (mtime of ``/var/lib/apt/periodic/update-success-stamp``)
    Return ``-1`` if there was no update before.

    Example::

        import fabtools

        print(fabtools.deb.last_update_time())
        # 1377603808.02
    """
    STAMP = '/var/lib/apt/periodic/update-success-stamp'
    if not is_file(STAMP):
        return -1
    return getmtime(STAMP)
Exemple #6
0
def last_update_time():
    """
    Return the time of last update-check.
    (mtime of ``/var/lib/apt/periodic/update-success-stamp``)
    Return ``-1`` if there was no update before.

    Example::

        import fabtools

        print(fabtools.deb.last_update_time())
        # 1377603808.02
    """
    STAMP = '/var/lib/apt/periodic/update-success-stamp'
    if not is_file(STAMP):
        return -1
    return getmtime(STAMP)
Exemple #7
0
def last_update_time():
    """
    Get the time of last APT index update

    This is the last modification time of ``/var/lib/apt/periodic/fabtools-update-success-stamp``.

    Returns ``-1`` if there was no update before.

    Example::

        import fabtools

        print(fabtools.deb.last_update_time())
        # 1377603808.02

    """
    STAMP = '/var/lib/apt/periodic/fabtools-update-success-stamp'
    if not is_file(STAMP):
        return -1
    return getmtime(STAMP)