ACC SHELL
/**
* File: modules/AutoinstCommon.ycp
* Package: Auto-installation/Partition
* Summary: Common partitioning functions module
* Author: Sven Schober (sschober@suse.de)
*
* $Id: AutoinstCommon.ycp 2788 2008-05-13 10:00:17Z sschober $
*/
{
module "AutoinstCommon.ycp";
textdomain "autoinst";
define symbol typeof( any o ){
if( is( o, integer) ){
return `integer;
}
else if( is( o, symbol) ){
return `symbol;
}
else if( is( o, string) ){
return `string;
}
else if( is( o, boolean) ){
return `boolean;
}
return nil;
}
/**
* Predicates
*/
global boolean isValidField( map<string, any> objectDefinition, string field ){
return objectDefinition[field]:nil != nil;
}
global boolean isValidObject( map<string, any> objectDefinition, map<string, any> obj ){
boolean result = true;
foreach(string field, any value, obj, {
result = isValidField( objectDefinition, field );
});
return result;
}
global boolean hasValidType( map<string, any> objectDefinition, string field, any value){
if( isValidField( objectDefinition, field ) ){
return typeof( objectDefinition[field]:nil ) == typeof( value );
}
/* if field doesn't exit in the first place, all types are correct */
return true;
}
global define boolean areEqual( map<string,any> d1, map<string,any> d2 ){
boolean result = true;
foreach( string key, any value, d1, {
any otherValue = d2[key]:nil;
if( value != otherValue ){
y2milestone( "d1['%1']='%2' != d2['%1']='%3'", key, value, otherValue );
result = false;
}
});
return result;
}
/**
* Setter
*/
global define map<string,any>
set( map<string,any> objectDefinition, map<string,any> obj, string field, any value){
if( isValidObject( objectDefinition, obj ) ){
if( isValidField( objectDefinition, field )){
if( hasValidType( objectDefinition, field, value) ){
return add(obj, field, value);
}
else{
y2error("Value '%1' ('%2') is not of correct type '%3'.",
value, typeof(value), typeof(objectDefinition[field]:nil));
}
}
else{
y2error("Not a valid field: '%1'.", field );
}
}
else{
y2error("No valid object: '%1'", obj );
}
return obj;
}
}
ACC SHELL 2018