コード例 #1
0
ファイル: i3status.py プロジェクト: parantapa/pbapps
def main():
    # Setup logfile
    logfile = get_logdir() + "/i3status.log"
    logbook.FileHandler(logfile).push_application()

    with log.catch_exceptions():
        # Write out my own pid
        pidfile = get_rundir() + "/i3status.pid"
        with open(pidfile, "w") as fobj:
            fobj.write(str(os.getpid()))

        # Get the external state directory
        extdir = get_i3status_rundir()

        # Make stdin and stdout UTF-8
        sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
        sys.stdin = codecs.getreader("utf-8")(sys.stdin)

        # Setup dummy signal handler on SIGUSR1
        # Useful for waking up from sleep
        register_exit_signals()
        signal.signal(signal.SIGUSR1, dummy_handler)

        # Write out the header
        write({"version": 1, "click_events": True}, True)
        write(None)

        while True:
            # We ignore the input
            _ = read()
            write(read_blocks(extdir))
            time.sleep(5)
コード例 #2
0
ファイル: i3status-signal.py プロジェクト: parantapa/pbapps
def do_main(service, signame):
    """
    Send the signal to the process.
    """

    # Create the external state directory
    extdir = get_i3status_rundir()

    # Get the service pids
    service_pids = get_pids(extdir)

    # If we dont have any active services then exit
    if not service_pids:
        log.info("No active services found.")
        return

    # Select the service name
    if service is None:
        cmd = ["dmenu-wrap"]
        proc = Popen(cmd, stdin=PIPE, stdout=PIPE)
        service, _ = proc.communicate("\n".join(sorted(service_pids)))
        service = service.strip()
    log.info("Selected service: {}", service)

    # Signal list
    signame_signum = {
        "usr1": signal.SIGUSR1,
        # "usr2": signal.SIGUSR2,
        # "kill": signal.SIGKILL,
        # "term": signal.SIGTERM,
        "-": None
    }

    # Select the signal to send
    if signame is None:
        cmd = ["dmenu-wrap"]
        proc = Popen(cmd, stdin=PIPE, stdout=PIPE)
        signame, _ = proc.communicate("\n".join(signame_signum))
        signame = signame.strip()
    log.info("Selected signame: {}", signame)

    # If we dont select any signal then exit.
    if signame == "-":
        log.info("Got empty signal ..")
        return

    # Send signal to code
    pid = service_pids[service]
    signum = signame_signum[signame]

    log.info("Sending signal {} to pid {} ...", signum, pid)
    os.kill(pid, signum)
コード例 #3
0
ファイル: reddit-bg.py プロジェクト: parantapa/pbapps
def main():
    prio = 30

    # Setup logfile
    logfile = "%s/%s.log" % (get_logdir(), MODULE)
    logbook.FileHandler(logfile).push_application()

    with log.catch_exceptions():
        # Get the external state directory
        extdir = get_i3status_rundir()

        # Write out my own pid
        pidfile = "%s/%d%s.pid" % (extdir, prio, MODULE)
        with open(pidfile, "w") as fobj:
            fobj.write(str(os.getpid()))

        register_exit_signals()
        signal.signal(signal.SIGUSR1, dummy_handler)

        # File to write block info
        blockfile = "%s/%d%s.block" % (extdir, prio, MODULE)

        do_main(blockfile)