Example #1
0
def timestamp_file(path):
    """
    timestamp_file(path)

    Creates a file containing the time in UNIX (epoch) time
    """
    write_file(path, shell_tools.get_unix_time())
Example #2
0
def timestamp_file(path):
    """
    timestamp_file(path)

    Creates a file containing the time in UNIX (epoch) time
    """
    write_file(path, shell_tools.get_unix_time())
Example #3
0
def get_uptime():
    """
    get_uptime()

    Get system uptime in minutes.
    """
    boot_time = int(shell_tools.run(
        "sysctl -n kern.boottime")["stdout"].split()[3].strip(',')
    )
    return (shell_tools.get_unix_time() - boot_time) / 60
Example #4
0
def verify_pickle(pickle_name, cache_expiration, pickle_path='/var'):
    """
    def verify_pickle(pickle_path, cache_expiration)

    Validate that the file exists, contains data, and is within the cache time
    range
    """
    pickle_path = "%s/%s" % (pickle_path, pickle_name)
    if os.path.exists(pickle_path):
        if os.stat(pickle_path).st_size > 0:
            if (get_creation_time(pickle_path) + cache_expiration) > shell_tools.get_unix_time():
                return True
        remove(pickle_path)
    return False
Example #5
0
def verify_pickle(pickle_name, cache_expiration, pickle_path='/var'):
    """
    def verify_pickle(pickle_path, cache_expiration)

    Validate that the file exists, contains data, and is within the cache time
    range
    """
    pickle_path = "%s/%s" % (pickle_path, pickle_name)
    if os.path.exists(pickle_path):
        if os.stat(pickle_path).st_size > 0:
            if (get_creation_time(pickle_path) + cache_expiration) > shell_tools.get_unix_time():
                return True
        remove(pickle_path)
    return False
Example #6
0
def get_time_since(time, mode="secs"):
    """
    get_time_since(time, mode="secs")

    Returns the time since in seconds
    mode options: year, weeks, days, hours, mins, secs
    """
    now = shell_tools.get_unix_time()
    unit = {
        'years': 365 * 86400,
        'weeks': 604800,
        'days': 86400,
        'hours': 3600,
        'mins': 60,
        'secs': 0,
    }
    since = now - time
    if unit[mode] == 0:
        return since
    return since / unit[mode]