Пример #1
0
 def get_settings_file_data(self):
     """
     Creates a dictionary from the settings stored in a file.
     :return: A dictionary with all the options and values from the settings
              file (sections are ignored during parsing).
     """
     settings_dict = {}
     settings_parser = configparser.ConfigParser()
     try:
         settings_parser.readfp(
             codecs.open(self.__settings_path, 'r', 'utf8'))
         settings_dict['arduino_exec_path'] =\
             settings_parser.get('Arduino_IDE', 'arduino_exec_path')
         settings_dict['arduino_board'] =\
             settings_parser.get('Arduino_IDE', 'arduino_board')
         settings_dict['arduino_serial_port'] =\
             settings_parser.get('Arduino_IDE', 'arduino_serial_port')
         settings_dict['sketch_name'] =\
             settings_parser.get('Arduino_Sketch', 'sketch_name')
         settings_dict['sketch_directory'] =\
             settings_parser.get('Arduino_Sketch', 'sketch_directory')
         settings_dict['ide_load'] =\
             settings_parser.get('Ardublockly', 'ide_load')
         print('\nSettings loaded from:')
     except Exception as e:
         print('\nSettings file corrupted or not found in:')
         settings_dict = None
     print('\t %s' % self.__settings_path)
     return settings_dict
Пример #2
0
    def save_settings(self):
        """ Saves all the settings into a configuration file """
        settings_parser = configparser.ConfigParser()
        # IDE Section
        settings_parser.add_section('Arduino_IDE')
        settings_parser.set('Arduino_IDE', 'arduino_exec_path',
                            '%s' % self.compiler_dir)
        settings_parser.set('Arduino_IDE', 'arduino_board',
                            '%s' % self.arduino_board)
        settings_parser.set('Arduino_IDE', 'arduino_serial_port',
                            '%s' % self.__serial_port_value)
        # Sketch section
        settings_parser.add_section('Arduino_Sketch')
        settings_parser.set('Arduino_Sketch', 'sketch_name',
                            '%s' % self.sketch_name)
        settings_parser.set('Arduino_Sketch', 'sketch_directory',
                            '%s' % self.sketch_dir)
        # Ardublockly section
        settings_parser.add_section('Ardublockly')
        settings_parser.set('Ardublockly', 'ide_load',
                            '%s' % self.load_ide_option)

        # Set the path and create/overwrite the file
        try:
            settings_file = codecs.open(self.__settings_path,
                                        'wb+',
                                        encoding='utf-8')
            try:
                settings_parser.write(settings_file)
                print('Settings file saved to:\n\t%s' % self.__settings_path)
                sys.stdout.flush()
            finally:
                settings_file.close()
        except Exception as e:
            print(e)
            print('Unable to write the settings file to:\n\t%s' %
                  self.__settings_path)