Skip to content
This repository was archived by the owner on Feb 8, 2023. It is now read-only.

Commit 6f237ab

Browse files
committed
move to a logger line IAs
1 parent 08ab1be commit 6f237ab

File tree

1 file changed

+38
-33
lines changed
  • payload/Library/nudge/Resources

1 file changed

+38
-33
lines changed

payload/Library/nudge/Resources/nudge

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import gurl
2929
class timerController(Foundation.NSObject):
3030
'''Thanks to frogor for help in figuring this part out'''
3131
def activateWindow_(self, timer_obj):
32-
print('Re-activating .nib to the foreground')
32+
nudgelog('Re-activating .nib to the foreground')
3333
# Move the application to the front
3434
NSApplication.sharedApplication().activateIgnoringOtherApps_(True)
3535
# Move the main window to the front
@@ -71,7 +71,7 @@ def downloadfile(options):
7171
try:
7272
filename = options['name']
7373
except KeyError:
74-
print(('No \'name\' key defined in json for %s' %
74+
nudgelog(('No \'name\' key defined in json for %s' %
7575
pkgregex(options['file'])))
7676
sys.exit(1)
7777

@@ -82,11 +82,11 @@ def downloadfile(options):
8282
if connection.percentComplete != -1:
8383
if connection.percentComplete != percent_complete:
8484
percent_complete = connection.percentComplete
85-
print(('Downloading %s - Percent complete: %s ' % (
85+
nudgelog(('Downloading %s - Percent complete: %s ' % (
8686
filename, percent_complete)))
8787
elif connection.bytesReceived != bytes_received:
8888
bytes_received = connection.bytesReceived
89-
print(('Downloading %s - Bytes received: %s ' % (
89+
nudgelog(('Downloading %s - Bytes received: %s ' % (
9090
filename, bytes_received)))
9191

9292
except (KeyboardInterrupt, SystemExit):
@@ -99,15 +99,15 @@ def downloadfile(options):
9999
raise
100100

101101
if connection.error is not None:
102-
print(('Error: %s %s ' % (str(connection.error.code()),
102+
nudgelog(('Error: %s %s ' % (str(connection.error.code()),
103103
str(connection.error.localizedDescription()))))
104104
if connection.SSLerror:
105-
print('SSL error: %s ' % (str(connection.SSLerror)))
105+
nudgelog('SSL error: %s ' % (str(connection.SSLerror)))
106106
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)))
109109
if connection.redirection != []:
110-
print('Redirection: %s ' % (str(connection.redirection)))
110+
nudgelog('Redirection: %s ' % (str(connection.redirection)))
111111

112112

113113
def get_console_username_info():
@@ -176,7 +176,7 @@ def load_nudge_globals():
176176
global nudge
177177
nudge = Nibbler(os.path.join(NUDGE_PATH, 'nudge.nib'))
178178
except IOError:
179-
print('Unable to load nudge nib file!')
179+
nudgelog('Unable to load nudge nib file!')
180180
exit(20)
181181

182182

@@ -197,6 +197,11 @@ def nudge_already_loaded():
197197
return False
198198

199199

200+
def nudgelog(text):
201+
'''logger for nudge'''
202+
Foundation.NSLog('[Nudge] ' + text)
203+
204+
200205
def pref(pref_name, domain='com.erikng.nudge'):
201206
"""Returns a preference from the specified domain.
202207
@@ -274,7 +279,7 @@ def get_minimum_minor_update_days(update_minor_days, pending_apple_updates, nudg
274279
for item in nudge_su_prefs:
275280
for update in pending_apple_updates:
276281
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']))
278283
force_date_strp = datetime.strptime(item['force_install_date'], '%Y-%m-%d-%H:%M')
279284
date_diff_seconds = (force_date_strp - todays_date).total_seconds()
280285
date_diff_days = int(round(date_diff_seconds / 86400))
@@ -289,7 +294,7 @@ def main():
289294
opts, _ = get_parsed_options()
290295

291296
if nudge_already_loaded():
292-
print('nudge already loaded!')
297+
nudgelog('nudge already loaded!')
293298
exit(0)
294299

295300
# Get the current username
@@ -339,18 +344,18 @@ def main():
339344
try:
340345
json_raw = urllib.request.urlopen(json_url).read()
341346
except urllib.error.URLError as err:
342-
print(err)
347+
nudgelog(err)
343348
shutil.rmtree(tmp_dir)
344349
exit(1)
345350
else:
346351
# If the file doesn't exist, grab it and wait half a second to save.
347352
while not os.path.isfile(json_path):
348-
print(('Starting download: %s' % (urllib.parse.unquote(
353+
nudgelog(('Starting download: %s' % (urllib.parse.unquote(
349354
json_data['url']).decode('utf8'))))
350355
downloadfile(json_data)
351356
time.sleep(0.5)
352357
else:
353-
print('nudge JSON file not specified!')
358+
nudgelog('nudge JSON file not specified!')
354359
shutil.rmtree(tmp_dir)
355360
exit(1)
356361

@@ -403,22 +408,22 @@ def main():
403408
update_minor_days = nudge_prefs.get('update_minor_days', 14)
404409

405410
# Start information
406-
print('Target OS version: %s ' % minimum_os_version)
411+
nudgelog('Target OS version: %s ' % minimum_os_version)
407412
if update_minor:
408413
if minimum_os_sub_build_version == '10A00':
409414
update_minor = False
410415
else:
411-
print('Target OS subversion: %s' % minimum_os_sub_build_version)
416+
nudgelog('Target OS subversion: %s' % minimum_os_sub_build_version)
412417

413418

414419
# cleanup the tmp stuff now
415420
if cleanup:
416-
print('Cleaning up temporary files...')
421+
nudgelog('Cleaning up temporary files...')
417422
shutil.rmtree(tmp_dir)
418423

419424
if random_delay:
420425
delay = random.randint(1,1200)
421-
print('Delaying run for {} seconds...'.format(delay))
426+
nudgelog('Delaying run for {} seconds...'.format(delay))
422427
time.sleep(delay)
423428

424429
# If the admin put '10.14' and not '10.14.0' the major version will be '10'
@@ -432,20 +437,20 @@ def main():
432437

433438
# Example 10.14.6 (18G103) >= 10.14.6 (18G84)
434439
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))
436441
exit(0)
437442
# Example: 10.14.6 >= 10.14.6
438443
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))
440445
exit(0)
441446
# Example: 10.14/10.14.0 >= 10.14
442447
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))
444449
exit(0)
445450
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))
447452
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))
449454

450455
minor_updates_required = False
451456

@@ -459,22 +464,22 @@ def main():
459464
PATH_TO_APP = LOCAL_URL_FOR_UPGRADE
460465
else:
461466
if not os.path.exists(PATH_TO_APP):
462-
print ('Update application not found! Exiting...')
467+
print('Update application not found! Exiting...')
463468
exit(1)
464469
else:
465470
# do minor version stuff
466471
if update_minor:
467-
print('Checking for minor updates.')
472+
nudgelog('Checking for minor updates.')
468473
swupd_output = download_apple_updates()
469474
if not swupd_output:
470-
print('Could not run softwareupdate')
475+
nudgelog('Could not run softwareupdate')
471476
# Exit 0 as we might be offline
472477
# TODO: Check if we're offline to exit with the
473478
# appropriate code
474479
exit(0)
475480

476481
if pending_apple_updates() == [] or pending_apple_updates() is None:
477-
print('No Software updates to install')
482+
nudgelog('No Software updates to install')
478483
set_pref('first_seen', None)
479484
set_pref('last_seen', None)
480485
exit(0)
@@ -500,7 +505,7 @@ def main():
500505
minor_updates_required = True
501506

502507
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.')
504509
set_pref('first_seen', None)
505510
set_pref('last_seen', None)
506511
exit()
@@ -517,9 +522,9 @@ def main():
517522
today = datetime.utcnow()
518523
last_seen_strp = datetime.strptime(last_seen, '%Y-%m-%d %H:%M:%S +0000')
519524
difference = today - last_seen_strp
520-
print(difference.days)
525+
nudgelog(difference.days)
521526
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))
523528
exit(0)
524529

525530
if not first_seen:
@@ -681,9 +686,9 @@ def main():
681686
# Use cut off dates, but don't use the timer functionality
682687
if no_timer:
683688
nudge.timer.invalidate()
684-
print('Timer invalidated!')
689+
nudgelog('Timer invalidated!')
685690
else:
686-
print('Timer is set to %s' % str(timer))
691+
nudgelog('Timer is set to %s' % str(timer))
687692

688693
# Set up our window controller and delegate
689694
nudge.hidden = True

0 commit comments

Comments
 (0)