Commit c96f1d7e authored by Michael Weinrich's avatar Michael Weinrich
Browse files

Device specific test files is optional, no more error if it doesn't exist

Removed/Replaced several print debug statements
Fixed the display method for the device tree in the GUI
parent ec223678
......@@ -16,12 +16,17 @@ from twisted.python.filepath import FilePath
import gtk, gtk.glade, gobject
from coherence import log
from upntest.base import UPnT
import upntest
import louie
class UPnTGUI:
class UPnTGUI(log.Loggable):
logCategory = 'UPnT_GUI'
"""Debug category for the GUI class."""
UPnT = None
"""Class variable for a single instance of UPnT."""
......@@ -31,13 +36,17 @@ class UPnTGUI:
Create the window and setup the underlying UPnT instance.
"""
# get all the signals
louie.connect(self.updateMessageBox, 'UPnT.infoMessage', louie.Any, weak=False)
louie.connect(self.updateMessageBox, 'UPnT.errorMessag', louie.Any, weak=False)
louie.connect(self.updateUpnpDevices, 'UPnT.host_discovery_end', louie.Any, weak=False)
# Try to locate the glade file
gladefile = "upntest.glade"
tryfiles = [gladefile,
os.path.join(os.path.dirname(sys.argv[0]), gladefile),
config.get('glade_dir', '') + gladefile,
FilePath(__file__).parent().child('upntest.glade').path]
print FilePath(__file__).parent().child('upntest.glade').path
for file in tryfiles:
if os.access(file, os.F_OK):
gladefile = file
......@@ -55,7 +64,9 @@ class UPnTGUI:
self.wTree.signal_autoconnect(dic)
# TreView for the devices
gfx_dir = config.get('gfx_dir', '');
gfx_dir = config.get('gfx_dir', FilePath(__file__).parent().parent().path);
if not gfx_dir.endswith('/'):
gfx_dir += '/'
self.device_icon = gtk.gdk.pixbuf_new_from_file_at_size(gfx_dir + 'gnome-fs-client.svg', 24, 24)
self.service_icon = gtk.gdk.pixbuf_new_from_file_at_size(gfx_dir + 'icon_webservice.gif', 24, 24)
self.getWidget("treeviewDeviceTree").set_headers_visible(False)
......@@ -104,10 +115,6 @@ class UPnTGUI:
# we are in GUI mode
config['GUI'] = True
# get all the signals
louie.connect(self.updateMessageBox, 'UPnT.infoMessage', louie.Any, weak=False)
louie.connect(self.updateUpnpDevices, 'UPnT.host_discovery_end', louie.Any, weak=False)
# initialize UPnT
self.UPnT = UPnT(config)
......@@ -127,14 +134,21 @@ class UPnTGUI:
"""
Update the device tree after inserting a new device or service node.
"""
#print 'Updating tree...'
self.debug('Updating tree...')
# no root_device -> don't update
if not root_device.isRootDevice():
return
model = self.getWidget("treeviewDeviceTree").get_model()
if model is None:
return
iter = model.get_iter_first()
current_parent = None
while iter is not None:
cur_dev = model.get_value(iter, 2)
if cur_dev._host.ip == ip:
if cur_dev.ip == root_device.host.ip:
current_parent = iter
break
iter = model.iter_next(iter)
......@@ -148,14 +162,16 @@ class UPnTGUI:
result = model.remove(children_iter)
for uuid, device in root_device.host._serverDevices.items():
device_iter = model.append(current_parent, [self.device_icon, device.deviceType + ':' + device.deviceVersion, device])
self.addSubDevicesToTree(model, device_iter, device)
self.addServicesToTree(model, device_iter, device)
if device.isRootDevice():
device_iter = model.append(current_parent, [self.device_icon, device.deviceType + ':' + device.deviceVersion, device])
self.addSubDevicesToTree(model, device_iter, device)
self.addServicesToTree(model, device_iter, device)
def addSubDevicesToTree(self, model, device_iter, device):
"""
Add all subdevices and their services to the tree
"""
self.debug('addSubdeviceToTree')
for uuid, subdevice in device.subDevices.items():
subdevice_iter = model.append(device_iter, [self.device_icon, subdevice.deviceType + ':' + subdevice.deviceVersion, subdevice])
self.addSubDevicesToTree(model, subdevice_iter, subdevice)
......@@ -166,6 +182,7 @@ class UPnTGUI:
"""
Add all services of a device to the tree
"""
self.debug('addServicesToTree')
for uuid, service in device._services.items():
model.append(device_iter, [self.service_icon, service.serviceType + ':' + service.serviceVersion, service])
......@@ -173,15 +190,18 @@ class UPnTGUI:
"""
Run the control test on a device.
"""
self.debug('executeTests')
if self.serviceToTest is not None:
self.debug('startControlTesting')
self.serviceToTest.startControlTesting(None, defer.succeed(None))
def updateMessageBox(self, message):
"""
Add the received message to the text box.
"""
self.messageTextBuffer.insert(self.messageTextBuffer.get_end_iter(), message + '\n')
self.refreshUI()
if self.messageTextBuffer:
self.messageTextBuffer.insert(self.messageTextBuffer.get_end_iter(), message + '\n')
self.refreshUI()
def showDetails(self, treeview):
"""
......
......@@ -77,11 +77,13 @@ class ServerControl(log.Loggable):
except IOError, error:
self.info('Specific file for %s:%s on uuid:%s not found' % (service_type, service_version, uuid))
self.info(error)
self._ready = False
#self._ready = False
self._uuidXml = None
except etree.XMLSyntaxError, error:
self.info('Specific file for %s:%s on uuid:%s cannot be parsed' % (service_type, service_version, uuid))
self.info(error)
self._ready = False
#self._ready = False
self._uuidXml = None
except IOError, error:
self.warning('Common file for %s:%s not found' % (service_type, service_version))
self.warning(error)
......@@ -129,29 +131,30 @@ class ServerControl(log.Loggable):
# read the device specific file and make according changes
#self.debug(etree.tostring(self._uuidXml, pretty_print=True))
specific_changes = self._uuidXml.xpath('/ServiceControlSyntaxTestCases/TestCaseList/TestCase')
for change in specific_changes:
id = change.findtext('Id')
if self._testcases.has_key(id):
self.debug('change.get = ' + change.get('delete', 'no'))
if change.get('delete', 'no') == 'yes':
del self._testcases[id]
else:
category = change.findtext('Category')
action_name = change.findtext('ActionName')
in_args = change.findall('./InArgs/*')
expected_return_code = change.findtext('ExpectedReturnCode')
bool1 = self._testcases[id].has_key('InArgs') and len(in_args) == len(self._testcases[id]['InArgs'])
bool2 = not self._testcases[id].has_key('InArgs') and len(in_args) == 0
if category != "" and action_name != "" and expected_return_code != "" and \
((bool1 and not bool2) or (not bool1 and bool2)):
self._testcases[id]['Category'] = category
self._testcases[id]['ActionName'] = action_name
self._testcases[id]['ExpectedReturnCode'] = expected_return_code
if bool1:
for argument in in_args:
self._testcases[id]['InArgs'][argument.tag] = argument.text
if self._uuidXml is not None:
specific_changes = self._uuidXml.xpath('/ServiceControlSyntaxTestCases/TestCaseList/TestCase')
for change in specific_changes:
id = change.findtext('Id')
if self._testcases.has_key(id):
self.debug('change.get = ' + change.get('delete', 'no'))
if change.get('delete', 'no') == 'yes':
del self._testcases[id]
else:
category = change.findtext('Category')
action_name = change.findtext('ActionName')
in_args = change.findall('./InArgs/*')
expected_return_code = change.findtext('ExpectedReturnCode')
bool1 = self._testcases[id].has_key('InArgs') and len(in_args) == len(self._testcases[id]['InArgs'])
bool2 = not self._testcases[id].has_key('InArgs') and len(in_args) == 0
if category != "" and action_name != "" and expected_return_code != "" and \
((bool1 and not bool2) or (not bool1 and bool2)):
self._testcases[id]['Category'] = category
self._testcases[id]['ActionName'] = action_name
self._testcases[id]['ExpectedReturnCode'] = expected_return_code
if bool1:
for argument in in_args:
self._testcases[id]['InArgs'][argument.tag] = argument.text
def startTesting(self, loop_tests=False):
"""
......@@ -164,13 +167,15 @@ class ServerControl(log.Loggable):
finished. If L{_ready} is still C{False}, an already activated C{Deferred}
is returned.
"""
self.debug('startTesting')
if not self._ready:
self.debug('Device not ready')
return defer.succeed(False)
self.loop_tests = loop_tests
self.test_deferred = defer.Deferred()
#self.test_deferred = defer.Deferred()
reactor.callLater(1, self.doTesting)
return self.test_deferred
#return self.test_deferred
def doTesting(self):
"""
......@@ -203,7 +208,7 @@ class ServerControl(log.Loggable):
is_looped = self.loop_tests
self.test_deferred.callback(test_result)
#self.test_deferred.callback(test_result)
def stopTesting(self):
"""
......
......@@ -535,7 +535,7 @@ class ServerDevice(log.Loggable):
device_object.addService(service_list[usn], usn)
try:
print 'checking service %s' % usn
self.debug('checking service %s' % usn)
device_object._services[usn].checkDescriptions()
except MissingUrlException, error:
self.info(error)
......@@ -582,8 +582,11 @@ class ServerDevice(log.Loggable):
"""The main UPnP namespace used to filter tags of other namespaces
(like DLNA)."""
unknown_elements = [MAIN_NS+'INMPR03']
"""Other non-standard elements known for being send by certain devices."""
for el in xmldoc.getiterator('*'):
if not el.tag.startswith(MAIN_NS):
if not el.tag.startswith(MAIN_NS) or el.tag in unknown_elements:
parent = el.getparent()
if parent is not None: # not the root element
parent.remove(el)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment