Example #1
0
def checkupdates():
    if flags.clear_updates:
        pkgs.updates.count = 0
        pkgs.updates.timestamp = time()
        flags.clear_updates = False

    if pkgs.updates.due or pkgs.init:
        hour = int(strftime('%H'))
        day = strftime('%a').lower()

        night_time = hour not in range(8, 21)
        weekend = day.startswith('s')

        if not (night_time or weekend):
            pkgs.updates.timestamp = time()
            stderr.write('checking for system updates\n')
            pkgs.updates.count = systemcount('checkupdates')

    if flags.do_healthcheck or pkgs.init:
        if pkgs.pacnew.due:
            pkgs.pacnew.timestamp = time()
            pkgs.pacnew.count = systemcount('pacdiff -o')

        if pkgs.orphans.due:
            pkgs.orphans.timestamp = time()
            pkgs.orphans.count = systemcount('pacman -Qdtq')

        total_conflicts = sum((
            pkgs.pacnew.count,
            pkgs.orphans.count,
        ))

        if total_conflicts == 0:
            # Once conflicts have been resolved, we don't need to notify $USER
            # until the next time they update.
            flags.do_healthcheck = False

    pkgs.init = False

    total_count = sum((
        pkgs.pacnew.count,
        pkgs.orphans.count,
        pkgs.updates.count,
    ))

    if total_count == 0:
        return None

    if pkgs.pacnew.count:
        return label('pacnew', str(pkgs.pacnew.count))

    if pkgs.updates.count:
        return label('updates', str(pkgs.updates.count))

    if pkgs.orphans.count:
        return label('orphans', str(pkgs.orphans.count))
Example #2
0
def battery_source():
    percent = power.percent()

    if power.charging():
        if percent >= 99:
            state = 'full'
        state = '++'
        return ' '.join((label('bat', meter(percent)), state))

    return label('bat', meter(percent))
Example #3
0
def memory_usage():
    mem = {}

    with open('/proc/meminfo', 'r') as f:
        for line in f.readlines():
            line = line.strip().split()

            if len(line) == 3:
                key, val, _ = line
                key = key[:-1]

            elif len(line) == 2:
                key, val = line
                key = key[:-1]

            mem[key] = int(val)

    # memory usage as calculated by `free(1)`
    percent = (100 / mem['MemTotal']) * (
        mem['MemTotal'] - mem['Buffers'] - mem['Cached'] - mem['MemFree']
    )

    # Only show memory usage when we are more than halfway to swapping
    if percent > (swap_percent / 2):
        return label('ram', meter(percent))
    else:
        return None
Example #4
0
def disk_usage():
    disk = disks.next()

    device_name, mountpoint = disk
    device_name = basename(device_name)

    size, free = size_of(mountpoint)
    percent = (100 / size) * (size - free)

    return label(device_name, meter(percent))
Example #5
0
def backlight_percentage() -> str:
    bl_now = readint(glob('/sys/class/backlight/*/brightness')[0])

    percent = (100 / bl_max) * bl_now

    return label('bl', meter(percent))
Example #6
0
def percent():
    percent = cpu_percent()
    return label('cpu', meter(percent)) if percent > 20 else None