]> git.ipfire.org Git - oddments/ddns.git/blame - ddns.in
Catch various network/server errors.
[oddments/ddns.git] / ddns.in
CommitLineData
f22ab085 1#!/usr/bin/python
3fdcb9d1
MT
2###############################################################################
3# #
4# ddns - A dynamic DNS client for IPFire #
5# Copyright (C) 2012 IPFire development team #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
f22ab085 21
1b8c6925
MT
22import argparse
23
f22ab085
MT
24import ddns
25
1b8c6925
MT
26from ddns.i18n import _
27
28CONFIGURATION_FILE = "@configsdir@/ddns.conf"
29
30def main():
31 # Parse command line
32 p = argparse.ArgumentParser(description=_("Dynamic DNS Updater"))
33
34 p.add_argument("-d", "--debug", action="store_true",
35 help=_("Enable debugging output"))
36
37 p.add_argument("-c", "--config", default=CONFIGURATION_FILE,
38 help=_("Load configuration file (Default: %s)") % CONFIGURATION_FILE)
39
40 # Create subparsers for commands.
41 subparsers = p.add_subparsers(help=_("Sub-command help"),
42 dest="subparsers_name")
43
2dae4713
MT
44 # list-providers
45 p_list_providers = subparsers.add_parser("list-providers",
46 help=_("List all available providers"))
47
1b8c6925
MT
48 # update
49 p_update = subparsers.add_parser("update", help=_("Update DNS record"))
50 p_update.add_argument("hostname")
51 p_update.add_argument("--force", action="store_true",
52 help=_("Execute update even if the record is already up to date"))
53
54 # update-all
55 p_update_all = subparsers.add_parser("update-all", help=_("Update all DNS records"))
56 p_update_all.add_argument("--force", action="store_true",
57 help=_("Execute update even if the record is already up to date"))
58
59 args = p.parse_args()
60
61 # Initialise the DDNSCore module.
62 d = ddns.DDNSCore(debug=args.debug)
63
64 # Load configuration.
65 if args.config:
66 d.load_configuration(args.config)
67
68 # Handle commands...
2dae4713
MT
69 if args.subparsers_name == "list-providers":
70 provider_names = d.get_provider_names()
71 print "\n".join(provider_names)
72
73 elif args.subparsers_name == "update":
1b8c6925
MT
74 d.updateone(hostname=args.hostname, force=args.force)
75
76 elif args.subparsers_name == "update-all":
77 d.updateall(force=args.force)
78
79 else:
80 raise RuntimeError("Unhandled command: %s" % args.subparsers_name)
f22ab085 81
1b8c6925 82main()