<s> import pygtk <EOL> from hudson_feed_setting import HudsonFeedSetting <EOL> pygtk . require ( '<STR_LIT>' ) <EOL> class SettingsRepository ( ) : <EOL> def __init__ ( self , file ) : <EOL> self . __file = file <EOL> def get ( self ) : <EOL> settings = [ ] <EOL> try : <EOL> fileHandle = open ( self . __file ) <EOL> file_lines = fileHandle . readlines ( ) <EOL> for line in file_lines : <EOL> setting = self . __get_setting ( line ) <EOL> settings . append ( setting ) <EOL> fileHandle . close ( ) <EOL> except IOError : <EOL> pass <EOL> finally : <EOL> return settings <EOL> def save ( self , settings ) : <EOL> fileHandle = open ( self . __file , '<STR_LIT:w>' ) <EOL> for feed_setting in settings : <EOL> self . __save_setting ( fileHandle , feed_setting ) <EOL> fileHandle . close ( ) <EOL> def __get_setting ( self , line ) : <EOL> line = line . replace ( '<STR_LIT:\n>' , '<STR_LIT>' ) <EOL> if ( line == "<STR_LIT>" ) : <EOL> return <EOL> return self . _setting_from_format ( line ) <EOL> def __save_setting ( self , fileHandle , feed_setting ) : <EOL> fileHandle . write ( self . _format_setting ( feed_setting ) ) <EOL> fileHandle . write ( '<STR_LIT:\n>' ) <EOL> def _format_setting ( self , feed_setting ) : <EOL> return ( "<STR_LIT:True>" if feed_setting . enabled else "<STR_LIT:False>" ) + '<STR_LIT:|>' + feed_setting . url <EOL> def _setting_from_format ( self , formatted ) : <EOL> bar = formatted . find ( "<STR_LIT:|>" ) <EOL> enabled = formatted [ <NUM_LIT:0> : bar ] == '<STR_LIT:True>' <EOL> url = formatted [ bar + <NUM_LIT:1> : ] <EOL> setting = HudsonFeedSetting ( url ) <EOL> setting . enabled = enabled <EOL> return setting </s>
