Calling YCP from Python

1. Basic instructions
=====================

There is simple YCP module (example)
------------------------------------

{


module "test";

global integer suma(integer a, integer b) {

    return a + b;
}

//y2milestone ("suma: %1", suma(1,1));

global list<any> print_list(string a, integer b) {
    list <any> any_list = [];
    any_list = add(any_list, a);
    any_list = add(any_list, b);

    return any_list;

}

global map<string, any> print_map(string key, any value) {
    map<string, any> result = $[];
    result[key] = value;
    return result;

}


}

Calling this module from python
-------------------------------

Python 2.5.1 (r251:54863, Aug 17 2007, 22:45:43)
[GCC 4.2.1 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import ycp
>>>
>>> ycp.import_module('test')
True
>>>
>>> ycp.test.suma(2,3)
5
>>>    


2. How to call UI from YaST in Python
=====================================
- there is important function: ycp.init_ui('qt')
that initialize UI from YaST

Python 2.5.1 (r251:54863, Aug 17 2007, 22:45:43)
[GCC 4.2.1 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import ycp
>>>
>>> ycp.init_ui('qt')
True
>>>
>>> ycp.import_module('Popup')
True
>>>
>>> ycp.Popup.Message('Example text')
>>> 


3. How to call SCR from python
==============================
- there are 4 functions for working with SCR
SCR_Dir, SCR_Read, SCR_Write and SCR_Execute
- first argument of function is ycp path as string
e.g. ".target.bash_output"

Python 2.5.1 (r251:54863, Aug 17 2007, 22:45:43)
[GCC 4.2.1 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import ycp
>>>
>>> ycp.SCR.Execute(ycp.Path('.target.bash_output'),'pwd')
{'exit': 0, 'stderr': '', 'stdout': '/home/user\n'}
>>>  


4. Symbol, Path and Term in python
==================================
- after importing ycp python has 3 classes
for building ycp type such as symbol, path or term


>>>
>>> path = Path('.my.path')
>>>  


>>>
>>> symbol = Symbol('Enabled')
>>>  

>>>
>>> term = Term('VBox',Term('Label','&Example Label'), Term('PushButton', '&So What'))
>>>   

5. Calling python module from YCP
=================================
- it works such as standart ycp module
just write "import name_module_without_postfix_py"
and you are able to call only function from python's module
via "name_module_without_postfix_py::name_function(arg1, arg2..)"
