configurationengine/doc/api/howto.rst
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
How to use cone APIs
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     2
====================
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     3
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     4
The ConE public usage is described here with few common use cases as HowTo guides. 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     5
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     6
How to open a Configuration project
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     7
-----------------------------------
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     8
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
     9
To open a project with ConE the api offers a Storage and Project classes. The Storage is the storage 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    10
agostic implemenetation for cpf/zip, filestorage and soon also a webstorage. To access anything in ConE 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    11
you must a project open. 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    12
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    13
.. code-block:: python 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    14
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    15
    from cone.public import api,exceptions
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    16
    """ 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    17
    The Storage access can be given as a extra parameter. It can have values r=read|w=write|a=append. 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    18
    The default Storage access is read, which will fail if the storage does not exist.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    19
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    20
    The Storage.open method will try which of the storage implementations can open that particular path.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    21
    So for example the path can be 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    22
    'foo/bar'  => Opened with FileStorage
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    23
    'test.cpf' => Opened with ZipStorage
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    24
    'test.zip' => Opened with ZipStorage 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    25
    """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    26
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    27
    """ Open a storage to current path and give it to the project. """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    28
    prj = api.Project(api.Storage.open('.'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    29
    """ Create a new storage to a cpf file and give it to the project. """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    30
    prj = api.Project(api.Storage.open('test.cpf', 'w'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    31
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    32
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    33
How to access and manipulate Configurations
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    34
-------------------------------------------
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    35
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    36
A Configuration normally is presented inside the Configuration project as a .confml file. So when you
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    37
are accessing configurations your are actually accessing confml files. The project offers funtionality to 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    38
get,add, remove configurations, which acts on root configurations inside the given project.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    39
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    40
How to List configuration's
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    41
^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    42
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    43
.. code-block:: python 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    44
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    45
    from cone.public import api,exceptions
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    46
    """ Create a storage to current path and give it to the project """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    47
    prj = api.Project(api.Storage.open('.'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    48
    """ list and print all root configurations  """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    49
    configlist = prj.list_configurations()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    50
    for config in configlist:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    51
        print config
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    52
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    53
How to Open configuration
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    54
^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    55
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    56
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    57
.. code-block:: python 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    58
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    59
    from cone.public import api,exceptions
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    60
    """ Create a storage to current path and give it to the project """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    61
    prj = api.Project(api.Storage.open('.'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    62
    """ open a with name """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    63
    """ 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    64
    get_configuration raises a NotFound exception if the given configuration resource 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    65
    is not found from Storage
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    66
    """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    67
    try:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    68
        myconfig = prj.get_configuration('myconfig.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    69
    except exceptions.NotFound:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    70
        print "myconfml is not found from project!"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    71
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    72
How to remove Configuration
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    73
^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    74
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    75
To remove a Configuration call  ``remove_configuration`` method of Configuration.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    76
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    77
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    78
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    79
    myconfig = prj.get_configuration('myconfig.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    80
    myconfig.remove_configuration('my_remove.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    81
    """ finally save and close project """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    82
    prj.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    83
    prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    84
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    85
How to include a one Configuration to an other Configuration
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    86
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    87
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    88
To include a one Configuration to an other call ``include_configuration()`` method of Configuration and pass the filename of Configuration as a parameter.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    89
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    90
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    91
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    92
    myconfig = prj.get_configuration('myconfig.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    93
    myconfig.include_configuration('../data.confml')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    94
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    95
Feature Access and manipulation
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    96
-------------------------------
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    97
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    98
How to add a Feature to Configuration
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
    99
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   100
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   101
To add a Feature to Configuration ``add_feature()`` method can be used.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   102
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   103
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   104
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   105
    conf = api.Configuration("myconf.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   106
    conf.add_feature(api.Feature("feature1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   107
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   108
How to add a child Feature to Feature
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   109
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   110
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   111
Childs can be added under Feature by ``add_feature()`` method and passing the parent Feature as a second paremeter:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   112
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   113
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   114
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   115
    conf = api.Configuration("myconf.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   116
    conf.add_feature(api.Feature("feature1"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   117
    conf.add_feature(api.Feature("feature11"),'feature1')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   118
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   119
How to remove Feature from Configuration
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   120
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   121
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   122
Features can be removed from Configuration by a following way:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   123
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   124
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   125
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   126
    conf1 = api.Configuration("myconf.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   127
    conf1.add_feature('feature1.feature12') # Add feature to Configuration
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   128
    conf1.remove_feature('feature1.feature12') # and then remove it
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   129
    """ finally save and close project """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   130
    prj.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   131
    prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   132
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   133
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   134
How to get a Feature from Configuration
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   135
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   136
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   137
Features can be accessed through View:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   138
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   139
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   140
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   141
    from cone.public import api
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   142
    """ Create a storage to current path and give it to the project """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   143
    prj = api.Project(api.Storage.open('.'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   144
    """ open the first configuration from the list """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   145
    firstconfig = prj.get_configuration(configlist[0])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   146
    """ get default view of first configuration """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   147
    default_view = firstconfig.get_default_view()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   148
    """ fetch example_feature1 from default view """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   149
    feature = default_view.get_feature('example_feature1')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   150
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   151
Feature can be accessed also by a property:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   152
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   153
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   154
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   155
    from cone.public import api
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   156
    """ Create a storage to current path and give it to the project """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   157
    prj = api.Project(api.Storage.open('.'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   158
    """ open the first configuration from the list """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   159
    firstconfig = prj.get_configuration(configlist[0])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   160
    """ get default view of first configuration """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   161
    default_view = firstconfig.get_default_view()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   162
    """ fetch example_feature1 from default view """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   163
    feature = default_view.example_feature1
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   164
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   165
How to list all Features inside a certain View
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   166
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   167
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   168
All Features can listed by calling ``list_all_features()`` method of View. Default view returns always 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   169
the view from the Root configuration point of view.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   170
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   171
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   172
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   173
    from cone.public import api
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   174
    """ Create a storage to current path and give it to the project """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   175
    prj = api.Project(api.Storage.open('.'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   176
    """ open the first configuration from the list """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   177
    firstconfig = prj.get_configuration(configlist[0])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   178
    """ get default view of first configuration """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   179
    default_view = firstconfig.get_default_view()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   180
    """ get all features in list from default view """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   181
    features = default_view.list_all_features()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   182
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   183
All features can be listed also using some custom View:
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   184
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   185
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   186
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   187
    from cone.public import api
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   188
    """ Create a storage to current path and give it to the project """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   189
    prj = api.Project(api.Storage.open('.'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   190
    """ open the first configuration from the list """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   191
    firstconfig = prj.get_configuration(configlist[0])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   192
    """ get my_view view to first configuration """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   193
    view = firstconfig.get_view("my_view")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   194
    """ fetch example_feature1 from my_view view """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   195
    features = view.list_all_features()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   196
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   197
How to list Features inside a certain View
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   198
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   199
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   200
To list immediate Features found under the certain View can be done by calling ``list_features()`` method.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   201
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   202
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   203
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   204
    myconfig = api.Configuration("root.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   205
    view = myconfig.get_view("my_view")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   206
    features = view.list_features()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   207
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   208
How to list all Features inside a certain Configuration
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   209
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   210
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   211
To list all Features found under a certain Configuration can be done by calling ``list_all_features()`` method of Configuration.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   212
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   213
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   214
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   215
    from cone.public import api
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   216
    """ Create a storage to current path and give it to the project """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   217
    prj = api.Project(api.Storage.open('.'))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   218
    """ open the first configuration from the list """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   219
    firstconfig = prj.get_configuration(configlist[0])
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   220
    """ get all features in list from configuration """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   221
    features = firstconfig.list_all_features()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   222
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   223
How to read a value for a specific Feature
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   224
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   225
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   226
The a value of specific Feature can be read by calling ``get_value()`` method or using value property.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   227
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   228
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   229
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   230
    value1 = my_feature1.get_value()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   231
    value2 = my_feature2.value
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   232
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   233
How to read a possible options of selection Feature
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   234
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   235
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   236
To list possible options of selection Feature can be done by calling ``get_valueset()`` method of Feature.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   237
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   238
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   239
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   240
    feature = api.Feature('my_selection_feature',type='selection')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   241
    feature.add_option('one', '1')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   242
    feature.add_option('two', '2')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   243
    value_set = feature.get_valueset()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   244
    feature.get_option('1').get_name() #returns  'one'
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   245
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   246
How to read a type of specific Feature
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   247
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   248
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   249
To read a specific type on Feature ``get_type()`` method or type property can be used. 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   250
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   251
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   252
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   253
    feature = dview.get_feature('my_feature')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   254
    feature.get_type() # returns type of the Feature
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   255
    feature.type # returns type of the Feature
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   256
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   257
How to set a value for a specific Feature
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   258
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   259
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   260
To set value for a specific Feature can be done by calling ``set_value()`` method or ``value`` property.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   261
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   262
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   263
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   264
    feature1 = dview.get_feature('my_feature1')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   265
    feature2 = dview.get_feature('my_feature2')
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   266
    feature1.set_value(123)
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   267
    feature2.value = "my_value"
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   268
    """ finally save and close project """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   269
    prj.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   270
    prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   271
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   272
Data access and manipulation
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   273
----------------------------
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   274
The data access inside a configuration is possible, but basically this can be avoided by manipulating the values 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   275
of features, which actually modify the data elements inside the configuration.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   276
However if direct data element access is needed, here's how you can do it.
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   277
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   278
How to add Data to Configuration
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   279
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   280
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   281
To add Data to Configuration can be done by calling ``add_data()`` method of Configuration: 
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   282
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   283
.. code-block:: python
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   284
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   285
    conf = api.Configuration("data.confml")
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   286
    conf.add_data(api.Data(ref='feature1', value=123))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   287
    conf.add_data(api.Data(fqn='feature1.feature12', value="test"))
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   288
    """ finally save and close project """
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   289
    prj.save()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   290
    prj.close()
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   291
    
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   292
2e8eeb919028 Adding EPL version of configurationengine.
terytkon
parents:
diff changeset
   293