Updates

portnov [2009-02-22 21:55:19]
Updates
Filename
test.py
diff --git a/test.py b/test.py
index 5d5e9a0..a2aa3b9 100755
--- a/test.py
+++ b/test.py
@@ -5,8 +5,11 @@ import signal
 from copy import copy

 import discovery
-from templates import do_render
-from configtemplate import read_template
+import templates
+import configtemplate
+
+#####################################
+# Internal section

 def on_sigint(signum, frame):
     print "Got SIGINT"
@@ -15,6 +18,9 @@ def on_sigint(signum, frame):

 signal.signal(signal.SIGINT, on_sigint)

+#####################################
+# Some classes
+
 class Service(object):
     def __init__(self):
         self.ip = ''
@@ -23,7 +29,7 @@ class Service(object):
         self.stype = ''
         self.name = ''

-    def uri(self):
+    def __str__(self):
         if self.port:
             return "%s:%s" % (self.ip, self.port)
         else:
@@ -48,6 +54,9 @@ class ZeroconfListener(object):
         services[sname] = svc
         print "services[%s] = %s" % (sname, svc)

+#####################################
+# Setup
+
 listener = ZeroconfListener()
 browser = discovery.Browser(args=('_ssh._tcp','_pulse-server._tcp','_nameserver._udp'))
 browser.set_listener(listener)
@@ -64,14 +73,25 @@ machine = Host()
 machine.ip = '192.168.1.2'
 machine.hostname = 'portnov'

+templates.services = services
+templates.machine = machine
 time.sleep(5)

-system = read_template('configs/templates/system.xml')
-scfg = system(proxy='{{services.proxy.uri}}')
+# Read template
+system = configtemplate.read_template('configs/templates/system.xml')
+
+#####################################
+# User interface testing
+
+# Create an instance of system config
+scfg = system(proxy='{{services.proxy}}')
 print "First config:"
-print do_render(scfg)
+print templates.do_render(scfg)

+# create a copy of scfg, but with different dns setting
 ncfg = scfg(dns='{{services.dns.ip}}')
+# chage gateway setting
+ncfg.gateway = '{{services.gateway}}'
 print "Second config:"
-print do_render(ncfg)
+print templates.do_render(ncfg)
ViewGit