def parse_args(): import argparse parser = argparse.ArgumentParser(description="afraid.org Dynamic DNS", formatter_class=argparse.ArgumentDefaultsHelpFormatter); parser.add_argument('config_file', type=str, help='Path to configuration file') parser.add_argument('-v', action='count', default=0, help='Set level of verbosity') parser.add_argument('--configure', action='store_true', help='Interactively configure your dyndns config file') # Check and Exit Arguments check_and_exit = parser.add_argument_group('Check and Exit') check_and_exit.add_argument('-e', '--external-ip', action='store_true', help='Check current IP and exit') check_and_exit.add_argument('-r', '--get-records', action='store_true', help='Return all records and exit') args = parser.parse_args() # Error check aruments import os path = args.config_file if not os.path.exists(path) or not os.path.isfile(path): print >> stderr, "%s does not exit" % path exit(1) return args
def main(): args = parse_args() config = Config(args.config_file, args.v) update = True if args.external_ip: get_and_print_ip(config.ip, args.v) update = False if args.get_records: get_and_print_records(config.api_key, args.v) update = False if args.configure: configure_config_file(config, args.v) update = False if update: update_records(config, args.v) exit(0)