<s> """<STR_LIT>""" <EOL> import os <EOL> import qisys . error <EOL> import qisys . qixml <EOL> class Profile : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name ) : <EOL> self . name = name <EOL> self . cmake_flags = list ( ) <EOL> def elem ( self ) : <EOL> elem = qisys . qixml . etree . Element ( "<STR_LIT>" ) <EOL> elem . set ( "<STR_LIT:name>" , self . name ) <EOL> if self . cmake_flags : <EOL> cmake_elem = qisys . qixml . etree . Element ( "<STR_LIT>" ) <EOL> flags_elem = qisys . qixml . etree . Element ( "<STR_LIT>" ) <EOL> cmake_elem . append ( flags_elem ) <EOL> for ( key , value ) in self . cmake_flags : <EOL> flag_elem = qisys . qixml . etree . Element ( "<STR_LIT>" ) <EOL> flag_elem . set ( "<STR_LIT:name>" , key ) <EOL> flag_elem . text = value <EOL> flags_elem . append ( flag_elem ) <EOL> elem . append ( cmake_elem ) <EOL> return elem <EOL> def __eq__ ( self , other ) : <EOL> return self . cmake_flags == other . cmake_flags <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> def parse_profiles ( xml_path ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . exists ( xml_path ) : <EOL> with open ( xml_path , "<STR_LIT:w>" ) as fp : <EOL> fp . write ( "<STR_LIT>" ) <EOL> res = dict ( ) <EOL> tree = qisys . qixml . read ( xml_path ) <EOL> root = tree . getroot ( ) <EOL> profile_elems = root . findall ( "<STR_LIT>" ) <EOL> for profile_elem in profile_elems : <EOL> profile_name = qisys . qixml . parse_required_attr ( profile_elem , "<STR_LIT:name>" ) <EOL> profile = Profile ( profile_name ) <EOL> res [ profile_name ] = profile <EOL> cmake_elem = profile_elem . find ( "<STR_LIT>" ) <EOL> if cmake_elem is None : <EOL> continue <EOL> flags_elem = cmake_elem . find ( "<STR_LIT>" ) <EOL> if flags_elem is None : <EOL> continue <EOL> flag_elems = flags_elem . findall ( "<STR_LIT>" ) <EOL> for flag_elem in flag_elems : <EOL> key = qisys . qixml . parse_required_attr ( flag_elem , "<STR_LIT:name>" ) <EOL> value = flag_elem . text . strip ( ) <EOL> to_add = ( ( key , value ) ) <EOL> profile . cmake_flags . append ( to_add ) <EOL> return res <EOL> def configure_build_profile ( xml_path , name , flags ) : <EOL> """<STR_LIT>""" <EOL> profile = Profile ( name ) <EOL> profile . cmake_flags = flags <EOL> tree = qisys . qixml . read ( xml_path ) <EOL> root = tree . getroot ( ) <EOL> profiles_elem = root . find ( "<STR_LIT>" ) <EOL> if profiles_elem is None : <EOL> profiles_elem = qisys . qixml . etree . Element ( "<STR_LIT>" ) <EOL> root . append ( profiles_elem ) <EOL> for profile_elem in profiles_elem . findall ( "<STR_LIT>" ) : <EOL> if profile_elem . get ( "<STR_LIT:name>" ) == name : <EOL> profiles_elem . remove ( profile_elem ) <EOL> profiles_elem . append ( profile . elem ( ) ) <EOL> qisys . qixml . write ( tree , xml_path ) <EOL> def remove_build_profile ( xml_path , name ) : <EOL> """<STR_LIT>""" <EOL> tree = qisys . qixml . read ( xml_path ) <EOL> root = tree . getroot ( ) <EOL> profiles = root . find ( "<STR_LIT>" ) <EOL> if profiles is None : <EOL> mess = "<STR_LIT>" <EOL> mess = mess . format ( name = name , xml_path = xml_path ) <EOL> raise qisys . error . Error ( mess ) <EOL> match_elem = None <EOL> for profile in profiles : <EOL> if profile . get ( "<STR_LIT:name>" ) == name : <EOL> match_elem = profile <EOL> if match_elem is None : <EOL> raise qisys . error . Error ( "<STR_LIT>" + name ) <EOL> profiles . remove ( match_elem ) <EOL> qisys . qixml . write ( tree , xml_path ) </s>
