]> git.ipfire.org Git - people/stevee/pypdns.git/commitdiff
Only initialize the backend, if necessary.
authorStefan Schantl <stefan.schantl@ipfire.org>
Sun, 7 Oct 2012 21:58:53 +0000 (21:58 +0000)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 7 Oct 2012 21:58:53 +0000 (21:58 +0000)
In the past the backend always has been initialzied and the database connection
has been established, except it will be used or not.

cli.py

diff --git a/cli.py b/cli.py
index 699d75553bd735625290146f62366df153bc2d96..8bd1cf4a1d7b2dd456764808a5935be9d52e9aaa 100644 (file)
--- 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