cmd/wait_for_internet.py

37 lines
963 B
Python
Raw Normal View History

2021-10-13 04:42:55 +00:00
import argparse
import sys
from voussoirkit import betterhelp
from voussoirkit import networktools
from voussoirkit import vlogging
def wait_for_internet_argparse(args):
try:
networktools.wait_for_internet(timeout=args.timeout)
return 0
except networktools.NoInternet:
return 1
@vlogging.main_decorator
def main(argv):
2022-02-13 03:50:00 +00:00
parser = argparse.ArgumentParser(
description='''
This program will block until internet access is available. It can be useful to
run this program before running another program that expects an internet
connection.
''',
)
parser.add_argument(
'timeout',
type=int,
help='''
An integer number of seconds, after which to give up and return 1.
''',
)
2021-10-13 04:42:55 +00:00
parser.set_defaults(func=wait_for_internet_argparse)
2022-02-13 03:50:00 +00:00
return betterhelp.go(parser, argv)
2021-10-13 04:42:55 +00:00
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))