0
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
|
|
18 |
import zipfile,os,re,zlib
|
|
19 |
from cone.public.api import Resource
|
|
20 |
|
|
21 |
class CpfRootResource(Resource):
|
|
22 |
"""
|
|
23 |
Parses a single CPF configuration project root confml file. Parses the XInclude statements to
|
|
24 |
find out the layers inside the project
|
|
25 |
"""
|
|
26 |
def __init__(self):
|
|
27 |
self.configuration_namespace = "http://www.s60.com/xml/confml/1"
|
|
28 |
self.include_namespace = "http://www.w3.org/2001/xinclude"
|
|
29 |
self.desc = ""
|
|
30 |
self.includes = []
|
|
31 |
self.meta = {}
|
|
32 |
self.filename = "defaultroot.confml"
|
|
33 |
return
|
|
34 |
|
|
35 |
def parse_file(self, xmlfile):
|
|
36 |
self.filename = xmlfile
|
|
37 |
self.etree = ElementTree.parse(xmlfile)
|
|
38 |
self.parse_includes()
|
|
39 |
self.parse_meta()
|
|
40 |
self.parse_desc()
|
|
41 |
return
|
|
42 |
|
|
43 |
def parse_str(self, xml_as_string):
|
|
44 |
self.etree = ElementTree.fromstring(xml_as_string)
|
|
45 |
self.parse_includes()
|
|
46 |
self.parse_meta()
|
|
47 |
self.parse_desc()
|
|
48 |
return
|
|
49 |
|
|
50 |
def parse_includes(self):
|
|
51 |
includes = self.etree.getiterator("{%s}include" % self.include_namespace)
|
|
52 |
for inc in includes:
|
|
53 |
self.includes.append(inc.get('href'))
|
|
54 |
|
|
55 |
def parse_meta(self):
|
|
56 |
meta = self.etree.find("{%s}meta" % self.configuration_namespace)
|
|
57 |
if meta:
|
|
58 |
for elem in meta.getiterator():
|
|
59 |
m = re.match("{.*}(?P<tagname>.*)",elem.tag)
|
|
60 |
if m:
|
|
61 |
self.meta[m.group('tagname')] = elem.text
|
|
62 |
|
|
63 |
def parse_desc(self):
|
|
64 |
desc_elem = self.etree.find("{%s}desc" % self.configuration_namespace)
|
|
65 |
if desc_elem != None:
|
|
66 |
self.desc = desc_elem.text
|
|
67 |
|
|
68 |
def get_layers(self):
|
|
69 |
return self.includes
|
|
70 |
|
|
71 |
def get_meta(self):
|
|
72 |
return self.meta
|
|
73 |
|
|
74 |
def get_desc(self):
|
|
75 |
return self.desc
|
|
76 |
|
|
77 |
def get_configuration(self):
|
|
78 |
configuration = CpfConfiguration(self.filename)
|
|
79 |
for inc in self.includes:
|
|
80 |
configuration.add_layer(CpfLayer(inc))
|
|
81 |
return configuration
|
|
82 |
|