MCPcopy
hub / github.com/StevenBlack/hosts / prompt_for_update

Function prompt_for_update

updateHostsFile.py:353–398  ·  view source on GitHub ↗

Prompt the user to update all hosts files. If requested, the function will update all data sources after it checks that a hosts file does indeed exist. Parameters ---------- freshen : bool Whether data sources should be updated. This function will return if

(freshen, updateauto)

Source from the content-addressed store, hash-verified

351
352# Prompt the User
353def prompt_for_update(freshen, updateauto):
354 """
355 Prompt the user to update all hosts files.
356
357 If requested, the function will update all data sources after it
358 checks that a hosts file does indeed exist.
359
360 Parameters
361 ----------
362 freshen : bool
363 Whether data sources should be updated. This function will return
364 if it is requested that data sources not be updated.
365 updateauto : bool
366 Whether or not to automatically update all data sources.
367
368 Returns
369 -------
370 updatesources : bool
371 Whether or not we should update data sources for exclusion files.
372 """
373
374 # Create a hosts file if it doesn't exist.
375 hostsfile = path_join_robust(BASEDIR_PATH, "hosts")
376
377 if not os.path.isfile(hostsfile):
378 try:
379 open(hostsfile, "w+").close()
380 except (IOError, OSError):
381 # Starting in Python 3.3, IOError is aliased
382 # OSError. However, we have to catch both for
383 # Python 2.x failures.
384 print_failure(
385 "ERROR: No 'hosts' file in the folder. Try creating one manually."
386 )
387
388 if not freshen:
389 return False
390
391 prompt = "Do you want to update all data sources?"
392
393 if updateauto or query_yes_no(prompt):
394 return True
395 elif not updateauto:
396 print("OK, we'll stick with what we've got locally.")
397
398 return False
399
400
401def prompt_for_exclusions(skipprompt):

Callers 6

test_freshen_updateMethod · 0.90
mainFunction · 0.85

Calls 3

path_join_robustFunction · 0.85
query_yes_noFunction · 0.85
print_failureFunction · 0.70

Tested by 5

test_freshen_updateMethod · 0.72