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):
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
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:
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