X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=ddns.in;h=455b0ad02169797530f969496a92986aae9897d2;hb=1b8c6925b932ebb24b68fd4ec756c58baed2f306;hp=8e96858505a951b8e4e0665ec8cd32e7ed0156c4;hpb=0b5e00a20faa4789bf4f241b1147ba8f6c0a031c;p=ddns.git diff --git a/ddns.in b/ddns.in index 8e96858..455b0ad 100644 --- a/ddns.in +++ b/ddns.in @@ -19,9 +19,56 @@ # # ############################################################################### +import argparse + import ddns -d = ddns.DDNSCore(debug=1) -d.load_configuration("@configsdir@/ddns.conf") +from ddns.i18n import _ + +CONFIGURATION_FILE = "@configsdir@/ddns.conf" + +def main(): + # Parse command line + p = argparse.ArgumentParser(description=_("Dynamic DNS Updater")) + + p.add_argument("-d", "--debug", action="store_true", + help=_("Enable debugging output")) + + p.add_argument("-c", "--config", default=CONFIGURATION_FILE, + help=_("Load configuration file (Default: %s)") % CONFIGURATION_FILE) + + # Create subparsers for commands. + subparsers = p.add_subparsers(help=_("Sub-command help"), + dest="subparsers_name") + + # update + p_update = subparsers.add_parser("update", help=_("Update DNS record")) + p_update.add_argument("hostname") + p_update.add_argument("--force", action="store_true", + help=_("Execute update even if the record is already up to date")) + + # update-all + p_update_all = subparsers.add_parser("update-all", help=_("Update all DNS records")) + p_update_all.add_argument("--force", action="store_true", + help=_("Execute update even if the record is already up to date")) + + args = p.parse_args() + + # Initialise the DDNSCore module. + d = ddns.DDNSCore(debug=args.debug) + + # Load configuration. + if args.config: + d.load_configuration(args.config) + + # Handle commands... + if args.subparsers_name == "update": + d.updateone(hostname=args.hostname, force=args.force) + + elif args.subparsers_name == "update-all": + d.updateall(force=args.force) + + else: + raise RuntimeError("Unhandled command: %s" % args.subparsers_name) -d.updateall() +main()