<s> from __future__ import print_function <EOL> import os <EOL> import yaml <EOL> from . common import string_type <EOL> catkin_config_path = os . path . join ( os . path . expanduser ( '<STR_LIT>' ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> builtin_verb_aliases_content = """<STR_LIT>""" <EOL> def initialize_verb_aliases ( path = catkin_config_path ) : <EOL> if not os . path . isdir ( path ) : <EOL> raise RuntimeError ( <EOL> "<STR_LIT>" <EOL> . format ( path ) ) <EOL> verb_aliases_path = os . path . join ( path , '<STR_LIT>' ) <EOL> if not os . path . isdir ( verb_aliases_path ) : <EOL> if os . path . isfile ( verb_aliases_path ) : <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> . format ( verb_aliases_path ) ) <EOL> os . makedirs ( verb_aliases_path ) <EOL> builtin_verb_aliases = os . path . join ( verb_aliases_path , '<STR_LIT>' ) <EOL> write_defaults = True <EOL> if os . path . exists ( builtin_verb_aliases ) : <EOL> with open ( builtin_verb_aliases , '<STR_LIT:r>' ) as f : <EOL> if f . read ( ) != builtin_verb_aliases_content : <EOL> print ( "<STR_LIT>" <EOL> . format ( builtin_verb_aliases ) ) <EOL> else : <EOL> write_defaults = False <EOL> if write_defaults : <EOL> with open ( builtin_verb_aliases , '<STR_LIT:w>' ) as f : <EOL> f . write ( builtin_verb_aliases_content ) <EOL> def initialize_config ( path = catkin_config_path ) : <EOL> if not os . path . isdir ( path ) : <EOL> if os . path . isfile ( path ) : <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> . format ( path ) ) <EOL> os . makedirs ( path ) <EOL> initialize_verb_aliases ( path ) <EOL> def get_verb_aliases ( path = catkin_config_path ) : <EOL> if not os . path . isdir ( path ) : <EOL> raise RuntimeError ( <EOL> "<STR_LIT>" <EOL> . format ( path ) ) <EOL> verb_aliases_path = os . path . join ( path , '<STR_LIT>' ) <EOL> if not os . path . isdir ( verb_aliases_path ) : <EOL> raise RuntimeError ( <EOL> "<STR_LIT>" <EOL> . format ( verb_aliases_path ) ) <EOL> verb_aliases = { } <EOL> for file_name in sorted ( os . listdir ( verb_aliases_path ) ) : <EOL> if file_name . endswith ( '<STR_LIT>' ) : <EOL> full_path = os . path . join ( verb_aliases_path , file_name ) <EOL> with open ( full_path , '<STR_LIT:r>' ) as f : <EOL> yaml_dict = yaml . load ( f ) <EOL> if yaml_dict is None : <EOL> continue <EOL> if not isinstance ( yaml_dict , dict ) : <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> . format ( full_path , type ( yaml_dict ) ) ) <EOL> for key , value in yaml_dict . items ( ) : <EOL> if not isinstance ( key , string_type ) : <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> . format ( full_path , key , type ( key ) ) ) <EOL> if not isinstance ( value , string_type ) and not isinstance ( value , type ( None ) ) : <EOL> raise RuntimeError ( <EOL> "<STR_LIT>" <EOL> . format ( full_path , value , type ( value ) ) ) <EOL> verb_aliases . update ( yaml_dict ) <EOL> for alias , value in dict ( verb_aliases ) . items ( ) : <EOL> if not value : <EOL> del verb_aliases [ alias ] <EOL> return verb_aliases </s>
