sleep.py

Fri, 26 Jan 2018 19:04:04 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Fri, 26 Jan 2018 19:04:04 +0000
changeset 74
4f56142e7497
parent 69
8705e296c7a0
child 76
4b08fca3ce34
permissions
-rw-r--r--

Separated repository configuration form backup configuration;
gave passphrase management to Repository object;
various fixes.

#
# Wake/sleep detection for scheduling adjustments
#

import Foundation
import AppKit
import borgend
import platform

logger=borgend.logger.getChild(__name__)

class SleepHandler(Foundation.NSObject):
    """ Handle wake/sleep notifications """

    def handleSleepNotification(self, aNotification):
        logger.info("System going to sleep")

    def handleWakeNotification(self, aNotification):
        logger.info("System waking up from sleep")

if platform.system()=='Darwin':
    workspace = AppKit.NSWorkspace.sharedWorkspace()
    notification_center = workspace.notificationCenter()
    sleep_handler = SleepHandler.new()

    notification_center.addObserver_selector_name_object_(
        sleep_handler,
        "handleSleepNotification",
        AppKit.NSWorkspaceWillSleepNotification,
        None)

    notification_center.addObserver_selector_name_object_(
        sleep_handler,
        "handleWakeNotification",
        AppKit.NSWorkspaceDidWakeNotification,
        None)

mercurial