ACC SHELL

Path : /usr/share/YaST2/modules/
File Upload :
Current File : //usr/share/YaST2/modules/UserSettings.ycp

{
	/**
	 *  Stores User Settings in home directory.
	 **/

	module "UserSettings";

	import "XML";
	import "String";

	string FILENAME = ".y2usersettings";

	map<string,map<string,any> > settings = $[];

	global void UserSettings()
	{
		map<string, any> homedir = (map<string, any>) SCR::Execute(.target.bash_output, "echo $HOME");
		FILENAME = String::FirstChunk(homedir["stdout"]:(((string)SCR::Read (.target.tmpdir))),"\n") + "/" + FILENAME;
		y2debug("Reading UserSettings from %1",FILENAME);
		settings = (map<string,map<string,any> >) XML::XMLToYCPFile(FILENAME);
	}

	/**
	 * Retrieves the specified value.
	 * @param section    The section to find KVP in, could be the module/client name.
	 * @param key        The key used for retreiving value.
	 * @return           The value of this key.
	 */
	global any GetValue(string section, string key)
	{
		return (settings[section]:$[])[key]:nil;
	}

	/**
	 * Retrieves the specified value and casts to a String.
	 */
	global string GetStringValue(string section, string key)
	{
		return (string) GetValue(section,key);
	}

	/**
	 * Retrieves the specified value and casts to an integer.
	 */
	global integer GetIntegerValue(string section, string key)
	{
		return (integer) GetValue(section,key);
	}

	/**
	 * Retrieves the specified value and casts to a boolean.
	 */
	global boolean GetBooleanValue(string section, string key)
	{
		return (boolean) GetValue(section,key);
	}

	/**
	 * Sets up a doctype for YaST's XML serialisation.
	**/
	void SetupXML()
	{
		map doc = $[];
		doc["cdataSections"] = [];
		doc["rootElement"] = "UserSettings";
		doc["systemID"] = "/un/defined";
		doc["nameSpace"] = "http://www.suse.com/1.0/yast2ns";
		doc["typeNamespace"] = "http://www.suse.com/1.0/configns";
		XML::xmlCreateDoc(`UserSettings,doc);
	}


	/**
	 * Writes a key value pair for specified section.
	 * @param section    The section to write KVP in, could be the module/client name.
	 * @param key        The key used for retreiving value later.
	 * @param value      The value to store.
	 * @return           True if the settings were written to disk successfully. False on failure.
	 */
	global boolean SetValue(string section, string key, any value)
	{
		map<string,any> kvps = settings[section]:$[];
		kvps = add(kvps,key,value);
		settings = add(settings,section,kvps);
		SetupXML();
		y2debug("Writing %1:%2 UserSetting to %3",key,value,FILENAME);
		return XML::YCPToXMLFile(`UserSettings,settings,FILENAME);
	}

	
}

ACC SHELL 2018