Source

python-specbar / example.py

#!/usr/bin/env python

import os
import random

import specbar


def monitor_dir(directory, name):
    """Stupid function that counts files in a given directory."""
    filecount = len([x for x in os.listdir(directory) if os.path.isfile(x)])
    return {name: filecount}


# Register CPU information (builtin)
specbar.register(specbar.get_cpu_info)

# Register own function for two directories
specbar.register(monitor_dir, '/home/user/important_dir', 'imp1')
specbar.register(monitor_dir, '/home/user/very_important_dir', 'imp2')

# Register own function using decorator syntax
@specbar.info_collector()
def fortune_number():
    return dict(fortune_number=random.randint(1, 100))

# Build format string
myformat = (
    'CPU: {model}@{speed:<5} IMP: {imp1:<3} VIMP: {imp2:<3} '
    'Fortune number: {fortune_number}'
)

# Call main loop
specbar.loop(myformat)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.