Esempio n. 1
0
def main():
    configure_logging()

    global CRANKD_OPTIONS, CRANKD_CONFIG

    CRANKD_OPTIONS = process_commandline()
    CRANKD_CONFIG = load_config(CRANKD_OPTIONS)

    if "NSDistributed" in CRANKD_CONFIG:
        add_distributed_notifications(CRANKD_CONFIG["NSDistributed"])

    if "NSWorkspace" in CRANKD_CONFIG:
        add_workspace_notifications(CRANKD_CONFIG['NSWorkspace'])

    if "SystemConfiguration" in CRANKD_CONFIG:
        add_sc_notifications(CRANKD_CONFIG['SystemConfiguration'])

    if "FSEvents" in CRANKD_CONFIG:
        add_fs_notifications(CRANKD_CONFIG['FSEvents'])

    if "NSNetService" in CRANKD_CONFIG:
        add_mdns_notifications(CRANKD_CONFIG['NSNetService'])

    if "CLLocation" in CRANKD_CONFIG:
        add_cl_notifications(CRANKD_CONFIG['CLLocation'])

    # We reuse our FSEvents code to watch for changes to our files and
    # restart if any of our libraries have been updated:
    add_conditional_restart(
        CRANKD_OPTIONS.config_file,
        "Configuration file %s changed" % CRANKD_OPTIONS.config_file)
    for m in filter(lambda i: i and hasattr(i, '__file__'),
                    sys.modules.values()):
        if m.__name__ == "__main__":
            msg = "%s was updated" % m.__file__
        else:
            msg = "Module %s was updated" % m.__name__

        add_conditional_restart(m.__file__, msg)

    signal.signal(signal.SIGHUP, partial(restart, "SIGHUP received"))

    start_fs_events()

    # NOTE: This timer is basically a kludge around the fact that we can't reliably get
    #       signals or Control-C inside a runloop. This wakes us up often enough to
    #       appear tolerably responsive:
    CFRunLoopAddTimer(
        NSRunLoop.currentRunLoop().getCFRunLoop(),
        CFRunLoopTimerCreate(None, CFAbsoluteTimeGetCurrent(), 2.0, 0, 0,
                             timer_callback, None), kCFRunLoopCommonModes)

    try:
        AppHelper.runConsoleEventLoop(installInterrupt=True)
    except KeyboardInterrupt:
        logging.info("KeyboardInterrupt received, exiting")

    sys.exit(0)
Esempio n. 2
0
def main():
    add_workspace_notifications(load_workspace_notifications())

    # NOTE: This timer is basically a kludge around the fact that we can't reliably get
    #       signals or Control-C inside a runloop. This wakes us up often enough to
    #       appear tolerably responsive:
    CFRunLoopAddTimer(
        NSRunLoop.currentRunLoop().getCFRunLoop(),
        CFRunLoopTimerCreate(None, CFAbsoluteTimeGetCurrent(), 2.0, 0, 0,
                             timer_callback, None), kCFRunLoopCommonModes)

    try:
        AppHelper.runConsoleEventLoop(installInterrupt=True)
    except KeyboardInterrupt:
        logging.info("KeyboardInterrupt received, exiting")

    sys.exit(0)
Esempio n. 3
0
    sc_keys = ['State:/Network/Global/IPv4', 'State:/Network/Global/IPv6']

    store = SCDynamicStoreCreate(None, "global-network-change",
                                 network_state_changed, None)
    SCDynamicStoreSetNotificationKeys(store, None, sc_keys)

    CFRunLoopAddSource(
        # NSRunLoop.currentRunLoop().getCFRunLoop(),
        CFRunLoopGetCurrent(),
        SCDynamicStoreCreateRunLoopSource(None, store, 0),
        kCFRunLoopCommonModes)

    # signal.signal(signal.SIGHUP, partial(quit, "SIGHUP received"))

    # NOTE: This timer is basically a kludge around the fact that we can't reliably get
    #       signals or Control-C inside a runloop. This wakes us up often enough to
    #       appear tolerably responsive:
    CFRunLoopAddTimer(
        NSRunLoop.currentRunLoop().getCFRunLoop(),
        CFRunLoopTimerCreate(None, CFAbsoluteTimeGetCurrent(), timer_interval,
                             0, 0, timer_callback, None),
        kCFRunLoopCommonModes)

    try:
        AppHelper.runConsoleEventLoop(installInterrupt=True)
    except KeyboardInterrupt:
        print "KeyboardInterrupt received, exiting"

    sys.exit(0)
Esempio n. 4
0
        run_prey()

    sc_keys = ['State:/Network/Global/IPv4', 'State:/Network/Global/IPv6']

    store = SCDynamicStoreCreate(None, "global-network-change",
                                 network_state_changed, None)
    SCDynamicStoreSetNotificationKeys(store, None, sc_keys)

    CFRunLoopAddSource(
        # NSRunLoop.currentRunLoop().getCFRunLoop(),
        CFRunLoopGetCurrent(),
        SCDynamicStoreCreateRunLoopSource(None, store, 0),
        kCFRunLoopCommonModes)

    # signal.signal(signal.SIGHUP, partial(quit, "SIGHUP received"))

    # NOTE: This timer is basically a kludge around the fact that we can't reliably get
    #       signals or Control-C inside a runloop. This wakes us up often enough to
    #       appear tolerably responsive:
    CFRunLoopAddTimer(
        NSRunLoop.currentRunLoop().getCFRunLoop(),
        CFRunLoopTimerCreate(None, CFAbsoluteTimeGetCurrent(), 2.0, 0, 0,
                             timer_callback, None), kCFRunLoopCommonModes)

    try:
        AppHelper.runConsoleEventLoop(installInterrupt=True)
    except KeyboardInterrupt:
        print "KeyboardInterrupt received, exiting"

    sys.exit(0)