|
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 # @author Teemu Rytkonen |
|
18 import re |
|
19 import logging |
|
20 |
|
21 class CarbonResourceMapper(object): |
|
22 def __init__(self): |
|
23 self.CARBON_RESOURCE_TYPE_MAP = {'configurationroot' : self.map_carbon_configurationroot, |
|
24 'configurationlayer' : self.map_carbon_configurationlayer, |
|
25 'featurelist' : self.map_carbon_featurelist} |
|
26 self.CONFML_RESOURCE_TYPE_MAP = {'configurationroot' : self.map_confml_configurationroot, |
|
27 'configurationlayer' : self.map_confml_configurationlayer, |
|
28 'featurelist' : self.map_confml_featurelist} |
|
29 |
|
30 def map_carbon_resource(self, resourcepath): |
|
31 for resourceext in self.CARBON_RESOURCE_TYPE_MAP: |
|
32 if resourcepath.endswith(resourceext): |
|
33 return self.CARBON_RESOURCE_TYPE_MAP[resourceext](resourcepath) |
|
34 return resourcepath |
|
35 |
|
36 def map_confml_resource(self, resourcetype, resourcepath): |
|
37 return self.CONFML_RESOURCE_TYPE_MAP[resourcetype](resourcepath) |
|
38 |
|
39 def map_carbon_configurationroot(self, resourcepath): |
|
40 return resourcepath.replace('.configurationroot', '.confml') |
|
41 |
|
42 def map_carbon_configurationlayer(self, resourcepath): |
|
43 return resourcepath.replace('.configurationlayer', '/root.confml') |
|
44 |
|
45 def map_carbon_featurelist(self, resourcepath): |
|
46 return "featurelists/%s" % resourcepath.replace('.featurelist', '.confml') |
|
47 |
|
48 def map_confml_configurationroot(self, resourcepath): |
|
49 return resourcepath.replace('.confml', '.configurationroot') |
|
50 |
|
51 def map_confml_configurationlayer(self, resourcepath): |
|
52 return resourcepath.replace('/root.confml', '.configurationlayer') |
|
53 |
|
54 def map_confml_featurelist(self, resourcepath): |
|
55 path = resourcepath.replace('featurelists/','').replace('.confml', '') |
|
56 version_identifier = 'working' |
|
57 m = re.match('^(.*) \((.*)\)', path) |
|
58 # if the resourcepath does not have version information |
|
59 # use default WORKING |
|
60 if m: |
|
61 path = m.group(1) |
|
62 version_identifier = m.group(2) |
|
63 return '%s (%s).featurelist' % (path, version_identifier) |