@@ -29,7 +29,7 @@ import gurl
29
29
class timerController (Foundation .NSObject ):
30
30
'''Thanks to frogor for help in figuring this part out'''
31
31
def activateWindow_ (self , timer_obj ):
32
- print ('Re-activating .nib to the foreground' )
32
+ nudgelog ('Re-activating .nib to the foreground' )
33
33
# Move the application to the front
34
34
NSApplication .sharedApplication ().activateIgnoringOtherApps_ (True )
35
35
# Move the main window to the front
@@ -71,7 +71,7 @@ def downloadfile(options):
71
71
try :
72
72
filename = options ['name' ]
73
73
except KeyError :
74
- print (('No \' name\' key defined in json for %s' %
74
+ nudgelog (('No \' name\' key defined in json for %s' %
75
75
pkgregex (options ['file' ])))
76
76
sys .exit (1 )
77
77
@@ -82,11 +82,11 @@ def downloadfile(options):
82
82
if connection .percentComplete != - 1 :
83
83
if connection .percentComplete != percent_complete :
84
84
percent_complete = connection .percentComplete
85
- print (('Downloading %s - Percent complete: %s ' % (
85
+ nudgelog (('Downloading %s - Percent complete: %s ' % (
86
86
filename , percent_complete )))
87
87
elif connection .bytesReceived != bytes_received :
88
88
bytes_received = connection .bytesReceived
89
- print (('Downloading %s - Bytes received: %s ' % (
89
+ nudgelog (('Downloading %s - Bytes received: %s ' % (
90
90
filename , bytes_received )))
91
91
92
92
except (KeyboardInterrupt , SystemExit ):
@@ -99,15 +99,15 @@ def downloadfile(options):
99
99
raise
100
100
101
101
if connection .error is not None :
102
- print (('Error: %s %s ' % (str (connection .error .code ()),
102
+ nudgelog (('Error: %s %s ' % (str (connection .error .code ()),
103
103
str (connection .error .localizedDescription ()))))
104
104
if connection .SSLerror :
105
- print ('SSL error: %s ' % (str (connection .SSLerror )))
105
+ nudgelog ('SSL error: %s ' % (str (connection .SSLerror )))
106
106
if connection .response is not None :
107
- print ('Status: %s ' % (str (connection .status )))
108
- print ('Headers: %s ' % (str (connection .headers )))
107
+ nudgelog ('Status: %s ' % (str (connection .status )))
108
+ nudgelog ('Headers: %s ' % (str (connection .headers )))
109
109
if connection .redirection != []:
110
- print ('Redirection: %s ' % (str (connection .redirection )))
110
+ nudgelog ('Redirection: %s ' % (str (connection .redirection )))
111
111
112
112
113
113
def get_console_username_info ():
@@ -176,7 +176,7 @@ def load_nudge_globals():
176
176
global nudge
177
177
nudge = Nibbler (os .path .join (NUDGE_PATH , 'nudge.nib' ))
178
178
except IOError :
179
- print ('Unable to load nudge nib file!' )
179
+ nudgelog ('Unable to load nudge nib file!' )
180
180
exit (20 )
181
181
182
182
@@ -197,6 +197,11 @@ def nudge_already_loaded():
197
197
return False
198
198
199
199
200
+ def nudgelog (text ):
201
+ '''logger for nudge'''
202
+ Foundation .NSLog ('[Nudge] ' + text )
203
+
204
+
200
205
def pref (pref_name , domain = 'com.erikng.nudge' ):
201
206
"""Returns a preference from the specified domain.
202
207
@@ -274,7 +279,7 @@ def get_minimum_minor_update_days(update_minor_days, pending_apple_updates, nudg
274
279
for item in nudge_su_prefs :
275
280
for update in pending_apple_updates :
276
281
if str (item ['name' ]) == str (update ['Product Key' ]):
277
- print ('{} has a forced date' .format (update ['Product Key' ]))
282
+ nudgelog ('{} has a forced date' .format (update ['Product Key' ]))
278
283
force_date_strp = datetime .strptime (item ['force_install_date' ], '%Y-%m-%d-%H:%M' )
279
284
date_diff_seconds = (force_date_strp - todays_date ).total_seconds ()
280
285
date_diff_days = int (round (date_diff_seconds / 86400 ))
@@ -289,7 +294,7 @@ def main():
289
294
opts , _ = get_parsed_options ()
290
295
291
296
if nudge_already_loaded ():
292
- print ('nudge already loaded!' )
297
+ nudgelog ('nudge already loaded!' )
293
298
exit (0 )
294
299
295
300
# Get the current username
@@ -339,18 +344,18 @@ def main():
339
344
try :
340
345
json_raw = urllib .request .urlopen (json_url ).read ()
341
346
except urllib .error .URLError as err :
342
- print (err )
347
+ nudgelog (err )
343
348
shutil .rmtree (tmp_dir )
344
349
exit (1 )
345
350
else :
346
351
# If the file doesn't exist, grab it and wait half a second to save.
347
352
while not os .path .isfile (json_path ):
348
- print (('Starting download: %s' % (urllib .parse .unquote (
353
+ nudgelog (('Starting download: %s' % (urllib .parse .unquote (
349
354
json_data ['url' ]).decode ('utf8' ))))
350
355
downloadfile (json_data )
351
356
time .sleep (0.5 )
352
357
else :
353
- print ('nudge JSON file not specified!' )
358
+ nudgelog ('nudge JSON file not specified!' )
354
359
shutil .rmtree (tmp_dir )
355
360
exit (1 )
356
361
@@ -403,22 +408,22 @@ def main():
403
408
update_minor_days = nudge_prefs .get ('update_minor_days' , 14 )
404
409
405
410
# Start information
406
- print ('Target OS version: %s ' % minimum_os_version )
411
+ nudgelog ('Target OS version: %s ' % minimum_os_version )
407
412
if update_minor :
408
413
if minimum_os_sub_build_version == '10A00' :
409
414
update_minor = False
410
415
else :
411
- print ('Target OS subversion: %s' % minimum_os_sub_build_version )
416
+ nudgelog ('Target OS subversion: %s' % minimum_os_sub_build_version )
412
417
413
418
414
419
# cleanup the tmp stuff now
415
420
if cleanup :
416
- print ('Cleaning up temporary files...' )
421
+ nudgelog ('Cleaning up temporary files...' )
417
422
shutil .rmtree (tmp_dir )
418
423
419
424
if random_delay :
420
425
delay = random .randint (1 ,1200 )
421
- print ('Delaying run for {} seconds...' .format (delay ))
426
+ nudgelog ('Delaying run for {} seconds...' .format (delay ))
422
427
time .sleep (delay )
423
428
424
429
# If the admin put '10.14' and not '10.14.0' the major version will be '10'
@@ -432,20 +437,20 @@ def main():
432
437
433
438
# Example 10.14.6 (18G103) >= 10.14.6 (18G84)
434
439
if os_version_sub_build >= LooseVersion (minimum_os_sub_build_version ) and update_minor :
435
- print ('OS version sub build is higher or equal to the minimum threshold: %s' % str (os_version_sub_build ))
440
+ nudgelog ('OS version sub build is higher or equal to the minimum threshold: %s' % str (os_version_sub_build ))
436
441
exit (0 )
437
442
# Example: 10.14.6 >= 10.14.6
438
443
elif os_version >= LooseVersion (minimum_os_version ) and not update_minor :
439
- print ('OS version is higher or equal to the minimum threshold: %s' % str (os_version ))
444
+ nudgelog ('OS version is higher or equal to the minimum threshold: %s' % str (os_version ))
440
445
exit (0 )
441
446
# Example: 10.14/10.14.0 >= 10.14
442
447
elif os_version_major >= LooseVersion (minimum_os_version_major ) and not update_minor :
443
- print ('OS major version is higher or equal to the minimum threshold and minor updates not enabled: %s ' % str (os_version ))
448
+ nudgelog ('OS major version is higher or equal to the minimum threshold and minor updates not enabled: %s ' % str (os_version ))
444
449
exit (0 )
445
450
else :
446
- print ('OS version is below the minimum threshold: %s' % str (os_version ))
451
+ nudgelog ('OS version is below the minimum threshold: %s' % str (os_version ))
447
452
if update_minor and LooseVersion (minimum_os_sub_build_version ) > os_version_sub_build :
448
- print ('OS version is below the minimum threshold subversion: %s' % str (os_version_sub_build ))
453
+ nudgelog ('OS version is below the minimum threshold subversion: %s' % str (os_version_sub_build ))
449
454
450
455
minor_updates_required = False
451
456
@@ -459,22 +464,22 @@ def main():
459
464
PATH_TO_APP = LOCAL_URL_FOR_UPGRADE
460
465
else :
461
466
if not os .path .exists (PATH_TO_APP ):
462
- print ('Update application not found! Exiting...' )
467
+ print ('Update application not found! Exiting...' )
463
468
exit (1 )
464
469
else :
465
470
# do minor version stuff
466
471
if update_minor :
467
- print ('Checking for minor updates.' )
472
+ nudgelog ('Checking for minor updates.' )
468
473
swupd_output = download_apple_updates ()
469
474
if not swupd_output :
470
- print ('Could not run softwareupdate' )
475
+ nudgelog ('Could not run softwareupdate' )
471
476
# Exit 0 as we might be offline
472
477
# TODO: Check if we're offline to exit with the
473
478
# appropriate code
474
479
exit (0 )
475
480
476
481
if pending_apple_updates () == [] or pending_apple_updates () is None :
477
- print ('No Software updates to install' )
482
+ nudgelog ('No Software updates to install' )
478
483
set_pref ('first_seen' , None )
479
484
set_pref ('last_seen' , None )
480
485
exit (0 )
@@ -500,7 +505,7 @@ def main():
500
505
minor_updates_required = True
501
506
502
507
if not minor_updates_required :
503
- print ('Only updates that can be installed in the background pending.' )
508
+ nudgelog ('Only updates that can be installed in the background pending.' )
504
509
set_pref ('first_seen' , None )
505
510
set_pref ('last_seen' , None )
506
511
exit ()
@@ -517,9 +522,9 @@ def main():
517
522
today = datetime .utcnow ()
518
523
last_seen_strp = datetime .strptime (last_seen , '%Y-%m-%d %H:%M:%S +0000' )
519
524
difference = today - last_seen_strp
520
- print (difference .days )
525
+ nudgelog (difference .days )
521
526
if difference .days < days_between_notifications :
522
- print ('Last seen date is within notification threshold: %s ' % str (days_between_notifications ))
527
+ nudgelog ('Last seen date is within notification threshold: %s ' % str (days_between_notifications ))
523
528
exit (0 )
524
529
525
530
if not first_seen :
@@ -681,9 +686,9 @@ def main():
681
686
# Use cut off dates, but don't use the timer functionality
682
687
if no_timer :
683
688
nudge .timer .invalidate ()
684
- print ('Timer invalidated!' )
689
+ nudgelog ('Timer invalidated!' )
685
690
else :
686
- print ('Timer is set to %s' % str (timer ))
691
+ nudgelog ('Timer is set to %s' % str (timer ))
687
692
688
693
# Set up our window controller and delegate
689
694
nudge .hidden = True
0 commit comments