<s> import struct <EOL> import os <EOL> from urlparse import urlparse <EOL> from objc import YES , NO , IBAction , IBOutlet , nil <EOL> import PyObjCTools <EOL> from Foundation import * <EOL> from AppKit import * <EOL> from MSCStatusController import MSCStatusController <EOL> import munki <EOL> import mschtml <EOL> import msclog <EOL> import MunkiItems <EOL> class MSCAppDelegate ( NSObject ) : <EOL> mainWindowController = IBOutlet ( ) <EOL> statusController = IBOutlet ( ) <EOL> def applicationShouldTerminate_ ( self , sender ) : <EOL> '''<STR_LIT>''' <EOL> return self . mainWindowController . appShouldTerminate ( ) <EOL> def applicationDidFinishLaunching_ ( self , sender ) : <EOL> '''<STR_LIT>''' <EOL> msclog . setup_logging ( ) <EOL> if sender . userInfo ( ) : <EOL> userNotification = sender . userInfo ( ) . get ( '<STR_LIT>' ) <EOL> if userNotification : <EOL> NSLog ( "<STR_LIT>" ) <EOL> self . userNotificationCenter_didActivateNotification_ ( <EOL> NSUserNotificationCenter . defaultUserNotificationCenter ( ) , userNotification ) <EOL> if NSApp . respondsToSelector_ ( '<STR_LIT>' ) : <EOL> NSApp . disableRelaunchOnLogin ( ) <EOL> ver = NSBundle . mainBundle ( ) . infoDictionary ( ) . get ( '<STR_LIT>' ) <EOL> msclog . log ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" % ver ) <EOL> if os . uname ( ) [ <NUM_LIT:2> ] . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> myImage = NSImage . imageNamed_ ( "<STR_LIT>" ) <EOL> NSApp . setApplicationIconImage_ ( myImage ) <EOL> if os . uname ( ) [ <NUM_LIT:2> ] . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] > '<STR_LIT>' : <EOL> NSUserNotificationCenter . defaultUserNotificationCenter ( ) . setDelegate_ ( self ) <EOL> self . statusController . registerForNotifications ( ) <EOL> if munki . thereAreUpdatesToBeForcedSoon ( hours = <NUM_LIT:2> ) : <EOL> lastcheck = NSDate . date ( ) <EOL> else : <EOL> lastcheck = munki . pref ( '<STR_LIT>' ) <EOL> max_cache_age = munki . pref ( '<STR_LIT>' ) <EOL> if not lastcheck : <EOL> self . mainWindowController . checkForUpdates ( ) <EOL> elif lastcheck . timeIntervalSinceNow ( ) * - <NUM_LIT:1> > int ( max_cache_age ) : <EOL> self . mainWindowController . checkForUpdates ( ) <EOL> elif MunkiItems . updateCheckNeeded ( ) : <EOL> self . mainWindowController . checkForUpdates ( ) <EOL> if not self . mainWindowController . webView . isLoading ( ) : <EOL> self . mainWindowController . loadInitialView ( ) <EOL> def applicationWillFinishLaunching_ ( self , notification ) : <EOL> '''<STR_LIT>''' <EOL> man = NSAppleEventManager . sharedAppleEventManager ( ) <EOL> man . setEventHandler_andSelector_forEventClass_andEventID_ ( <EOL> self , <EOL> "<STR_LIT>" , <EOL> struct . unpack ( "<STR_LIT>" , "<STR_LIT>" ) [ <NUM_LIT:0> ] , <EOL> struct . unpack ( "<STR_LIT>" , "<STR_LIT>" ) [ <NUM_LIT:0> ] ) <EOL> def openMunkiURL ( self , url ) : <EOL> '''<STR_LIT>''' <EOL> parsed_url = urlparse ( url ) <EOL> if parsed_url . scheme != '<STR_LIT>' : <EOL> msclog . debug_log ( "<STR_LIT>" % url ) <EOL> return <EOL> filename = mschtml . unquote ( parsed_url . netloc ) <EOL> if not os . path . splitext ( filename ) [ <NUM_LIT:1> ] : <EOL> filename += u'<STR_LIT>' <EOL> if filename . endswith ( u'<STR_LIT>' ) : <EOL> mschtml . build_page ( filename ) <EOL> self . mainWindowController . load_page ( filename ) <EOL> else : <EOL> msclog . debug_log ( "<STR_LIT>" % url ) <EOL> def openURL_withReplyEvent_ ( self , event , replyEvent ) : <EOL> '''<STR_LIT>''' <EOL> keyDirectObject = struct . unpack ( "<STR_LIT>" , "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> url = event . paramDescriptorForKeyword_ ( keyDirectObject ) . stringValue ( ) . decode ( '<STR_LIT:utf8>' ) <EOL> msclog . log ( "<STR_LIT>" , "<STR_LIT>" , url ) <EOL> self . openMunkiURL ( url ) <EOL> def userNotificationCenter_didActivateNotification_ ( self , center , notification ) : <EOL> '''<STR_LIT>''' <EOL> user_info = notification . userInfo ( ) <EOL> if user_info . get ( '<STR_LIT:action>' ) == '<STR_LIT>' : <EOL> url = user_info . get ( '<STR_LIT:value>' ) <EOL> msclog . log ( "<STR_LIT>" , "<STR_LIT>" % url ) <EOL> self . openMunkiURL ( url ) <EOL> center . removeDeliveredNotification_ ( notification ) <EOL> else : <EOL> msclog . log ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def userNotificationCenter_shouldPresentNotification_ ( self , center , notification ) : <EOL> return True <EOL> def userNotificationCenter_didDeliverNotification_ ( self , center , notification ) : <EOL> pass </s>
