From: Michael Tremer Date: Tue, 10 Jun 2014 23:22:43 +0000 (+0200) Subject: ddns: Add argument to list all providers in command line. X-Git-Tag: 001~59 X-Git-Url: http://git.ipfire.org/?p=oddments%2Fddns.git;a=commitdiff_plain;h=2dae4713a345a4dd61e40de644bef38e00d75663;hp=1b8c6925b932ebb24b68fd4ec756c58baed2f306 ddns: Add argument to list all providers in command line. --- diff --git a/ddns.in b/ddns.in index 455b0ad..726eac3 100644 --- a/ddns.in +++ b/ddns.in @@ -41,6 +41,10 @@ def main(): subparsers = p.add_subparsers(help=_("Sub-command help"), dest="subparsers_name") + # list-providers + p_list_providers = subparsers.add_parser("list-providers", + help=_("List all available providers")) + # update p_update = subparsers.add_parser("update", help=_("Update DNS record")) p_update.add_argument("hostname") @@ -62,7 +66,11 @@ def main(): d.load_configuration(args.config) # Handle commands... - if args.subparsers_name == "update": + if args.subparsers_name == "list-providers": + provider_names = d.get_provider_names() + print "\n".join(provider_names) + + elif args.subparsers_name == "update": d.updateone(hostname=args.hostname, force=args.force) elif args.subparsers_name == "update-all": diff --git a/src/ddns/__init__.py b/src/ddns/__init__.py index 74be346..ff3d3cc 100644 --- a/src/ddns/__init__.py +++ b/src/ddns/__init__.py @@ -94,6 +94,12 @@ class DDNSCore(object): ): self.register_provider(provider) + def get_provider_names(self): + """ + Returns a list of names of all registered providers. + """ + return sorted(self.providers.keys()) + def load_configuration(self, filename): configs = ConfigParser.SafeConfigParser() configs.read([filename,])