View | Details | Raw Unified | Return to bug 52270
Collapse All | Expand All

(-)a/management/univention-management-console/src/univention/management/console/category.py (-13 / +13 lines)
 Lines 67-103   must be given in curly braces {VARIABLE}. Link Here 
67
67
68
import os
68
import os
69
import sys
69
import sys
70
import xml.parsers.expat
70
from lxml import etree
71
import xml.etree.cElementTree as ET
72
71
73
from .log import RESOURCES
72
from .log import RESOURCES
74
73
75
74
76
class XML_Definition(ET.ElementTree):
75
class XML_Definition(object):
77
76
78
	"""Represents a category definition."""
77
	"""Represents a category definition."""
79
78
80
	def __init__(self, root=None, filename=None, domain=None):
79
	def __init__(self, root=None, domain=None):
81
		ET.ElementTree.__init__(self, element=root, file=filename)
80
		self.tree = etree.ElementTree(root)
81
		self.root = root
82
		self.domain = domain
82
		self.domain = domain
83
83
84
	@property
84
	@property
85
	def name(self):
85
	def name(self):
86
		"""Returns the descriptive name of the category"""
86
		"""Returns the descriptive name of the category"""
87
		return self.find('name').text
87
		return self.tree.find('name').text
88
88
89
	@property
89
	@property
90
	def id(self):
90
	def id(self):
91
		"""Returns the unique identifier of the category"""
91
		"""Returns the unique identifier of the category"""
92
		return self._root.get('id')
92
		return self.root.get('id')
93
93
94
	@property
94
	@property
95
	def icon(self):
95
	def icon(self):
96
		return self._root.get('icon')
96
		return self.root.get('icon')
97
97
98
	@property
98
	@property
99
	def color(self):
99
	def color(self):
100
		return self._root.get('color')
100
		return self.root.get('color')
101
101
102
	@property
102
	@property
103
	def priority(self):
103
	def priority(self):
 Lines 108-116   class XML_Definition(ET.ElementTree): Link Here 
108
		:rtype: float or None
108
		:rtype: float or None
109
		"""
109
		"""
110
		try:
110
		try:
111
			return float(self._root.get('priority', -1))
111
			return float(self.root.get('priority', -1))
112
		except ValueError:
112
		except ValueError:
113
			RESOURCES.warn('No valid number type for property "priority": %s' % self._root.get('priority'))
113
			RESOURCES.warn('No valid number type for property "priority": %s' % self.root.get('priority'))
114
		return None
114
		return None
115
115
116
	def json(self):
116
	def json(self):
 Lines 148-154   class Manager(dict): Link Here 
148
				RESOURCES.info('Found file %s with wrong suffix' % filename)
148
				RESOURCES.info('Found file %s with wrong suffix' % filename)
149
				continue
149
				continue
150
			try:
150
			try:
151
				definitions = ET.ElementTree(file=os.path.join(Manager.DIRECTORY, filename))
151
				definitions = etree.parse(os.path.join(Manager.DIRECTORY, filename))
152
				categories = definitions.find('categories')
152
				categories = definitions.find('categories')
153
				if categories is None:
153
				if categories is None:
154
					continue
154
					continue
 Lines 157-162   class Manager(dict): Link Here 
157
					category = XML_Definition(root=category_elem, domain=i18nDomain)
157
					category = XML_Definition(root=category_elem, domain=i18nDomain)
158
					self[category.id] = category
158
					self[category.id] = category
159
				RESOURCES.info('Loaded categories from %s' % filename)
159
				RESOURCES.info('Loaded categories from %s' % filename)
160
			except (xml.parsers.expat.ExpatError, ET.ParseError) as exc:
160
			except (etree.XMLSyntaxError,) as exc:
161
				RESOURCES.warn('Failed to parse category file %s: %s' % (filename, exc))
161
				RESOURCES.warn('Failed to parse category file %s: %s' % (filename, exc))
162
				continue
162
				continue
(-)a/management/univention-management-console/src/univention/management/console/module.py (-20 / +19 lines)
 Lines 121-128   import copy Link Here 
121
import os
121
import os
122
import sys
122
import sys
123
import re
123
import re
124
import xml.parsers.expat
124
from lxml import etree
125
import xml.etree.cElementTree as ET
126
125
127
from .tools import JSON_Object, JSON_List
126
from .tools import JSON_Object, JSON_List
128
from .log import RESOURCES
127
from .log import RESOURCES
 Lines 272-288   class Link(Module): Link Here 
272
	pass
271
	pass
273
272
274
273
275
class XML_Definition(ET.ElementTree):
274
class XML_Definition(object):
276
275
277
	'''container for the interface description of a module'''
276
	'''container for the interface description of a module'''
278
277
279
	def __init__(self, root=None, filename=None):
278
	def __init__(self, root=None):
280
		ET.ElementTree.__init__(self, element=root, file=filename)
279
		self.tree = etree.ElementTree(root)
281
		self.root = self.getroot()
280
		self.root = root
282
281
283
	@property
282
	@property
284
	def name(self):
283
	def name(self):
285
		return self.findtext('name')
284
		return self.tree.findtext('name')
286
285
287
	@property
286
	@property
288
	def version(self):
287
	def version(self):
 Lines 290-304   class XML_Definition(ET.ElementTree): Link Here 
290
289
291
	@property
290
	@property
292
	def url(self):
291
	def url(self):
293
		return self.findtext('url')
292
		return self.tree.findtext('url')
294
293
295
	@property
294
	@property
296
	def description(self):
295
	def description(self):
297
		return self.findtext('description')
296
		return self.tree.findtext('description')
298
297
299
	@property
298
	@property
300
	def keywords(self):
299
	def keywords(self):
301
		return KEYWORD_PATTERN.split(self.findtext('keywords', '')) + [self.name]
300
		return KEYWORD_PATTERN.split(self.tree.findtext('keywords', '')) + [self.name]
302
301
303
	@property
302
	@property
304
	def id(self):
303
	def id(self):
 Lines 338-344   class XML_Definition(ET.ElementTree): Link Here 
338
	@property
337
	@property
339
	def flavors(self):
338
	def flavors(self):
340
		'''Retrieve list of flavor objects'''
339
		'''Retrieve list of flavor objects'''
341
		for elem in self.findall('flavor'):
340
		for elem in self.tree.findall('flavor'):
342
			name = elem.findtext('name')
341
			name = elem.findtext('name')
343
			priority = None
342
			priority = None
344
			try:
343
			try:
 Lines 366-376   class XML_Definition(ET.ElementTree): Link Here 
366
365
367
	@property
366
	@property
368
	def categories(self):
367
	def categories(self):
369
		return [elem.get('name') for elem in self.findall('categories/category')]
368
		return [elem.get('name') for elem in self.tree.findall('categories/category')]
370
369
371
	def commands(self):
370
	def commands(self):
372
		'''Generator to iterate over the commands'''
371
		'''Generator to iterate over the commands'''
373
		for command in self.findall('command'):
372
		for command in self.tree.findall('command'):
374
			yield command.get('name')
373
			yield command.get('name')
375
374
376
	def get_module(self):
375
	def get_module(self):
 Lines 383-389   class XML_Definition(ET.ElementTree): Link Here 
383
			priority=self.priority,
382
			priority=self.priority,
384
			keywords=self.keywords,
383
			keywords=self.keywords,
385
			translationId=self.translationId,
384
			translationId=self.translationId,
386
			required_commands=[cat.get('name') for cat in self.findall('requiredCommands/requiredCommand')],
385
			required_commands=[cat.get('name') for cat in self.tree.findall('requiredCommands/requiredCommand')],
387
			version=self.version,
386
			version=self.version,
388
		)
387
		)
389
388
 Lines 395-406   class XML_Definition(ET.ElementTree): Link Here 
395
394
396
	def get_command(self, name):
395
	def get_command(self, name):
397
		'''Retrieves details of a command'''
396
		'''Retrieves details of a command'''
398
		for command in self.findall('command'):
397
		for command in self.tree.findall('command'):
399
			if command.get('name') == name:
398
			if command.get('name') == name:
400
				return Command(name, command.get('function'), command.get('allow_anonymous', '0').lower() in ('yes', 'true', '1'))
399
				return Command(name, command.get('function'), command.get('allow_anonymous', '0').lower() in ('yes', 'true', '1'))
401
400
402
	def __bool__(self):
401
	def __bool__(self):
403
		module = self.find('module')
402
		module = self.tree.find('module')
404
		return module is not None and len(module) != 0
403
		return module is not None and len(module) != 0
405
	__nonzero__ = __bool__
404
	__nonzero__ = __bool__
406
405
 Lines 433-448   class Manager(dict): Link Here 
433
			if not filename.endswith('.xml'):
432
			if not filename.endswith('.xml'):
434
				continue
433
				continue
435
			try:
434
			try:
436
				parsed_xml = ET.parse(os.path.join(Manager.DIRECTORY, filename))
435
				parsed_xml = etree.parse(os.path.join(Manager.DIRECTORY, filename))
437
				RESOURCES.info('Loaded module %s' % filename)
436
				RESOURCES.info('Loaded module %s' % filename)
438
				for mod_tree in parsed_xml.getroot():
437
				for mod_element in parsed_xml.getroot().iterchildren(tag=etree.Element):
439
					mod = XML_Definition(root=mod_tree)
438
					mod = XML_Definition(root=mod_element)
440
					if mod.deactivated:
439
					if mod.deactivated:
441
						RESOURCES.info('Module is deactivated: %s' % filename)
440
						RESOURCES.info('Module is deactivated: %s' % filename)
442
						continue
441
						continue
443
					# save list of definitions in self
442
					# save list of definitions in self
444
					self.setdefault(mod.id, []).append(mod)
443
					self.setdefault(mod.id, []).append(mod)
445
			except (xml.parsers.expat.ExpatError, ET.ParseError) as exc:
444
			except (etree.XMLSyntaxError,) as exc:
446
				RESOURCES.warn('Failed to load module %s: %s' % (filename, exc))
445
				RESOURCES.warn('Failed to load module %s: %s' % (filename, exc))
447
				continue
446
				continue
448
447

Return to bug 52270