From e95ce9d3b37782c4e7de9cc77ff882588f49a434 Mon Sep 17 00:00:00 2001 From: Greg Neagle Date: Thu, 29 Jul 2010 17:36:38 +0000 Subject: [PATCH] Various minor edits to make pylint happier. git-svn-id: http://munki.googlecode.com/svn/trunk@622 a4e17f2e-e282-11dd-95e1-755cbddbdd66 --- code/client/launchapp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/code/client/launchapp b/code/client/launchapp index 5df571db..a78f95e9 100755 --- a/code/client/launchapp +++ b/code/client/launchapp @@ -29,17 +29,21 @@ import subprocess import time -def getconsoleuser(): +def getconsoleuser(): + '''Uses Apple's SystemConfiguration framework to get the current + console user''' from SystemConfiguration import SCDynamicStoreCopyConsoleUser cfuser = SCDynamicStoreCopyConsoleUser( None, None, None ) return cfuser[0] def main(): + '''Pass arguments to /usr/bin/open only if we are the current + console user or no user and we're at the login window''' consoleuser = getconsoleuser() try: thisuser = os.environ['USER'] - except: + except KeyError: # when run via launchd at loginwindow context, os.environ['USER'] # is undefined, so we'll return root (the effective user) thisuser = "root" @@ -47,20 +51,22 @@ def main(): if (consoleuser == thisuser) or \ (consoleuser == None and thisuser == "root"): cmd = ["/usr/bin/open"] - try: + if len(sys.argv) > 1: cmd.extend(sys.argv[1:]) - except: - print >>sys.stderr, "Must specify an app to launch!" + else: + print >> sys.stderr, "Must specify an app to launch!" exit(-1) retcode = subprocess.call(cmd) + # sleep 10 secs to make launchd happy time.sleep(10) exit(retcode) else: # we aren't in the current GUI session + # sleep 10 secs to make launchd happy time.sleep(10) exit(0) if __name__ == '__main__': - main() + main()