From: Stefan Schantl Date: Sun, 7 Oct 2012 21:58:53 +0000 (+0000) Subject: Only initialize the backend, if necessary. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6d2cabc5918745328a09bd79e4ee467e46cf76bd;p=people%2Fstevee%2Fpypdns.git Only initialize the backend, if necessary. In the past the backend always has been initialzied and the database connection has been established, except it will be used or not. --- diff --git a/cli.py b/cli.py index 699d755..8bd1cf4 100644 --- a/cli.py +++ b/cli.py @@ -24,9 +24,7 @@ import backend import argparse from i18n import _ - -# Initialize DNS module. -dns = backend.DNS(backend.DB) +from backend import * # Create main class for the CLI. class Cli(object): @@ -85,14 +83,19 @@ class Cli(object): try: func = self.action2func[action] + except KeyError: raise Exception, "Unhandled action: %s" % action + else: + # Initialize DNS module. + self.dns = DNS(DB) + return func() def handle_show_domains(self): # Get all domains and print them - domains = dns.get_domains() + domains = self.dns.get_domains() if domains: for domain in domains: print domain.id, domain.name @@ -104,7 +107,7 @@ class Cli(object): def handle_show_records(self): if self.args.domain: # Check if the given domain name really exists. - domain = dns.get_domain(self.args.domain) + domain = self.dns.get_domain(self.args.domain) if domain: # Get all records and print them. if domain.records: @@ -155,7 +158,7 @@ class Cli(object): def handle_show_all(self): # Get all domains and print them - domains = dns.get_domains() + domains = self.dns.get_domains() if domains: for domain in domains: print domain.name