From f33638664835a99b2e11584251a19e6f2374f998 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Thu, 5 Jan 2017 09:17:45 +0200 Subject: Fixed login hook decorator test --- machammer/hooks.py | 12 ++++++++++++ tests.py | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/machammer/hooks.py b/machammer/hooks.py index 8826ad9..40b7986 100644 --- a/machammer/hooks.py +++ b/machammer/hooks.py @@ -29,3 +29,15 @@ def reboot(path=None): def shutdown(path=None): """Set shutdown hook to path, or disable shutdown hook.""" pass + + +def mount(mountpoint, path=None): + """Execute path if mountpoint is mounted. Set path to None to disable.""" + label = 'com.github.filipp.machammer.mounthook' + defaults.set('/Library/LaunchAgents/%s' % label, 'Label', label) + defaults.set('/Library/LaunchAgents/%s' % label, 'Program', path) + defaults.set('/Library/LaunchAgents/%s' % label, 'StartOnMount', + '-boolean', + 'TRUE') + defaults.set('/Library/LaunchAgents/%s' % label, 'WatchPaths', '-array', + mountpoint) diff --git a/tests.py b/tests.py index 0dd36c5..9c9580f 100755 --- a/tests.py +++ b/tests.py @@ -127,7 +127,7 @@ class HooksTestCase(TestCase): hooks.login('/lalala') self.assertEquals(self.gethook(), '/lalala') - def test_set_login_function(self): + def test_set_login_decorator(self): from machammer.decorators import login @login @@ -137,6 +137,7 @@ class HooksTestCase(TestCase): subprocess.call(['/usr/bin/say', 'Hello ' + sys.argv[1]]) blaa() + self.assertEquals(self.gethook(), '/var/root/Library/mh_loginhook.py') def test_unset_login(self): hooks.login() -- cgit v1.2.3