configurationengine/source/plugins/example/ConeExamplePlugin/examplemlplugin/exampleml_impl.py
author terytkon
Thu, 11 Mar 2010 17:04:37 +0200
changeset 0 2e8eeb919028
child 3 e7e0ae78773e
permissions -rw-r--r--
Adding EPL version of configurationengine.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     1
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     2
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     3
# All rights reserved.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     4
# This component and the accompanying materials are made available
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     5
# under the terms of "Eclipse Public License v1.0"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     6
# which accompanies this distribution, and is available
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     8
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     9
# Initial Contributors:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    11
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    12
# Contributors:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    13
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    14
# Description:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    15
#
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    16
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    17
"""
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    18
ExampleML implementation, for use as a template when creating new plug-ins.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    19
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    20
The example implementation language simply writes text data into output files
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    21
using the specified encoding. The text data may contain ConfML setting references
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    22
of the form ${SomeFeature.SomeSetting}.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    23
"""
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    24
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    25
import os
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
import sys
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
import logging
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
from cone.public import plugin
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
class ExamplemlImpl(plugin.ImplBase):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
    IMPL_TYPE_ID = 'exampleml'
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
    def __init__(self, resource_ref, configuration, output_objects):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
        plugin.ImplBase.__init__(self, resource_ref, configuration)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
        self.logger = logging.getLogger('cone.exampleml(%s)' % resource_ref)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    37
        self.output_objects = output_objects
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
        
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
    def generate(self, context=None):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
        for output in self.output_objects:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
            self.logger.debug("Generating '%s'" % output.get_output_file(self.output, self.configuration))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
            output.write_to_file(self.output, self.configuration)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
    def list_output_files(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
        files = []
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
        for output in self.output_objects:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
            files.append(output.get_output_file(self.output, self.configuration))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
        return files
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
    def get_refs(self):
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    51
        refs = []
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    52
        for output in self.output_objects:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    53
            refs.extend(output.get_refs())
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    54
        return refs