Author: dmeyer
Date: Wed Feb 7 19:19:16 2007
New Revision: 9170
Modified:
trunk/core/src/conf.py
Log:
add xmlconfig function for cxml merging/compiling
Modified: trunk/core/src/conf.py
==============================================================================
--- trunk/core/src/conf.py (original)
+++ trunk/core/src/conf.py Wed Feb 7 19:19:16 2007
@@ -54,10 +54,12 @@
# That's it, you shouldn't need to make changes after this point
-__all__ = [ 'datafile', 'SHAREDIR', 'cfgfilepath' ]
+__all__ = [ 'datafile', 'SHAREDIR', 'cfgfilepath', 'xmlconfig' ]
# Python imports
import os
+import stat
+import md5
import sys
import locale
import logging
@@ -93,6 +95,106 @@
return msg + KaaConfig._cfg_string(self, prefix, print_desc)
+def xmlconfig(configfile, sources):
+ import kaa.distribution.xmlconfig
+ import kaa.xml
+
+ def get_parent(tree, name, position=''):
+ for child in tree:
+ if child.name == 'group':
+ # print 'have', child.getattr('name')
+ if position + child.name == name:
+ raise RuntimeError('bad tree')
+ if name.startswith(position + child.getattr('name')):
+ # print 'deeper'
+ return get_parent(child, name, position +
child.getattr('name'))
+ for name in name[len(position):].strip(' .').split('.'):
+ # print 'create', name
+ node = kaa.xml.Node('group', name=name)
+ tree.add_child(node)
+ tree = node
+ return tree
+
+ hashkey = [ f+str(os.stat(f)[stat.ST_MTIME]) for f in sources ]
+ hashkey = md5.new(''.join(hashkey)).hexdigest()
+
+ if os.path.isfile(configfile):
+ fd = open(configfile)
+ fd.readline()
+ if fd.readline() == '# -*- hash: %s\n' % hashkey:
+ fd.close()
+ return True
+ fd.close()
+
+ modules = []
+ for cfg in sources:
+ # load cxml file
+ m = kaa.xml.Document(cfg, 'config')
+ # FIXME: ugly hack
+ if m.getattr('name'):
+ m._doc._doc = True
+ if not m.getattr('name').endswith('plugin'):
+ modules.append(m)
+ continue
+ # list of plugins
+ for plugin in m.children:
+ if plugin.name == 'group':
+ name = '%s.%s' % (m.getattr('name'), plugin.getattr('name'))
+ plugin.setattr('name', name)
+ modules.append(plugin)
+
+ def valfunc(node):
+ name = node.getattr('name')
+ if name.startswith('plugin'):
+ return '2%s' % name
+ if node.hasattr('plugin') or '.plugin.' in name:
+ return '1%s' % name
+ if 'gui' in name:
+ return '3%s' % name
+ return '0%s' % name
+
+ # sort modules somehow
+ modules.sort(lambda x,y: cmp(valfunc(x), valfunc(y)))
+
+ if modules[0].getattr('name') == '':
+ tree = modules.pop(0)
+ else:
+ doc = '<?xml version="1.0"?><config name=""></config>'
+ tree = kaa.xml.Document(doc, 'config')
+ for m in modules:
+ parent = get_parent(tree, m.getattr('name'))
+ if m.hasattr('plugin'):
+ node = kaa.xml.Node('var')
+ node.setattr('name', 'activate')
+ node.setattr('default', m.getattr('plugin'))
+ parent.add_child(node)
+ parent.setattr('is_plugin', 'yes')
+ for child in m:
+ parent.add_child(child)
+
+ if configfile.endswith('.cxml'):
+ return tree.save(configfile)
+ out = open(configfile, 'w')
+ out.write('# -*- coding: iso-8859-1 -*-\n')
+ out.write('# -*- hash: %s\n' % hashkey)
+ out.write('# auto generated file\n\n')
+ out.write('from kaa.config import Var, Group, Dict, List, Config\n\n')
+ out.write('config = ')
+ kaa.distribution.xmlconfig.Parser().parse(tree, out)
+
+ def find_plugins(node, position=''):
+ for child in node:
+ if child.hasattr('is_plugin'):
+ out.write('"%s%s", ' % (position, child.getattr('name')))
+ if child.name == 'group':
+ find_plugins(child, position + child.getattr('name') + '.')
+
+ out.write('\nplugins = [')
+ find_plugins(tree)
+ out.write(']\n')
+ out.close()
+
+
# set basic env variables
if not os.environ.has_key('HOME') or not os.environ['HOME'] or
os.environ['HOME'] == '/':
os.environ['HOME'] = '/root'
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog