def to_dict(self):
        """

        Returns: itself as a dictionary

        """

        from pylabcontrol.core.script_iterator import ScriptIterator


        if 'script_iterator' in self.__module__.split('.'):
            # script iterator module is of the form
            # 'pylabcontrol.core.script_iterator.b26_toolkit.dynamic_script_iterator0'
            # and the class name if of the form package.dynamic_script_iterator0
            package = self.__class__.__name__.split('.')[0]
        else:
            # if it is not a script iterator the package is the highest level of the module
            package = self.__module__.split('.')[0]


        dictator = {self.name: {
            'class' : self.__class__.__name__,
            'filepath': inspect.getfile(self.__class__),
            'info': self.__doc__,
            'package': package
        }}

        # todo JG: mayby change path so that it points to b26toolkit and not to PyLabcotnrols
        # if isinstance(self, ScriptIterator):
        #     dictator['filepath'] = inspect.getfile(self.__class__),



        if self.scripts != {}:
            dictator[self.name].update({'scripts': {} })
            for subscript_name, subscript in self.scripts.items():
                dictator[self.name]['scripts'].update(subscript.to_dict() )

        if self.instruments != {}:
            # dictator[self.name].update({'instruments': self.instruments})
            # dictator[self.name].update({'instruments': {} })
            # for instrument_name, instrument in self.instruments.iteritems():
            #     dictator[self.name]['instruments'].update(instrument.to_dict())

            dictator[self.name].update({'instruments': {
                instrument_name: {'class': instrument['instance'].__class__.__name__, 'settings':instrument['settings']}
                for instrument_name, instrument in self.instruments.items()
            }})

        dictator[self.name]['settings'] = self.settings

        return dictator
def to_dict ( self ) : from pylabcontrol . core . script_iterator import ScriptIterator if 'script_iterator' in self . __module__ . split ( '.' ) : package = self . __class__ . __name__ . split ( '.' ) [ 0 ] else : package = self . __module__ . split ( '.' ) [ 0 ] dictator = { self . name : { 'class' : self . __class__ . __name__ , 'filepath' : inspect . getfile ( self . __class__ ) , 'info' : self . __doc__ , 'package' : package } } if self . scripts != { } : dictator [ self . name ] . update ( { 'scripts' : { } } ) for subscript_name , subscript in self . scripts . items ( ) : dictator [ self . name ] [ 'scripts' ] . update ( subscript . to_dict ( ) ) if self . instruments != { } : dictator [ self . name ] . update ( { 'instruments' : { instrument_name : { 'class' : instrument [ 'instance' ] . __class__ . __name__ , 'settings' : instrument [ 'settings' ] } for instrument_name , instrument in self . instruments . items ( ) } } ) dictator [ self . name ] [ 'settings' ] = self . settings return dictator
Returns: itself as a dictionary