def read_string(self, python_string, description=None, section=None, **kwargs):
        '''Read a serialized description from a Python (.pycfg) string.

        Parameters
        ----------
        python_string : string
            Python string with a serialized description.

        Returns
        -------
        Description
            Configuration object.
        '''

        if description is None:
            description = Description()

        header = kwargs.get('header', '')

        python_string = "%s\n\nallensdk_description = %s" % (
            header, python_string)

        ns = {}
        code = compile(python_string, 'string', 'exec')
        exec(code, ns)
        data = ns['allensdk_description']
        description.unpack(data, section)

        return description
    def read_string(self,
                    json_string,
                    description=None,
                    section=None,
                    **kwargs):
        '''Parse a complete or partial configuration.

        Parameters
        ----------
        json_string : string
            Input to parse.
        description : Description, optional
            Where to put the parsed configuration.  If None a new one is created.
        section : string, optional
            Where to put the parsed configuration within the description.

        Returns
        -------
        Description
            The input description with parsed configuration added.

        Section is only specified for "bare" objects that are to be added to a section array.
        '''
        if description is None:
            description = Description()

        data = JsonComments.read_string(json_string)

        description.unpack(data, section)

        return description
Example #3
0
    def read_string(self,
                    python_string,
                    description=None,
                    section=None,
                    **kwargs):
        '''Read a serialized description from a Python (.pycfg) string.
        
        Parameters
        ----------
        python_string : string
            Python string with a serialized description.
        
        Returns
        -------
        Description
            Configuration object.
        '''

        if description == None:
            description = Description()

        header = kwargs.get('header', '')

        python_string = "%s\n\nallensdk_description = %s" % (header,
                                                             python_string)

        ns = {}
        code = compile(python_string, 'string', 'exec')
        exec(code, ns)
        data = ns['allensdk_description']
        description.unpack(data, section)

        return description
    def read_string(self, json_string, description=None, section=None, **kwargs):
        """Parse a complete or partial configuration.
        
        Parameters
        ----------
        json_string : string
            Input to parse.
        description : Description, optional
            Where to put the parsed configuration.  If None a new one is created.
        section : string, optional
            Where to put the parsed configuration within the description.
        
        Returns
        -------
        Description
            The input description with parsed configuration added.
        
        Section is only specified for "bare" objects that are to be added to a section array.
        """
        if description == None:
            description = Description()

        data = JsonComments.read_string(json_string)

        description.unpack(data, section)

        return description
Example #5
0
    def read(self, file_path, description=None, section=None, **kwargs):
        '''Parse data needed for a simulation.

        Parameters
        ----------
        description : dict
            Configuration from parsing previous files.
        section : string, optional
            What configuration section to read it into if the file does not specify.
        '''
        if description is None:
            description = Description()

        self.reader = self.parser_for_extension(file_path)
        self.reader.read(file_path, description, section, **kwargs)

        return description
Example #6
0
    def read_model_description(self):
        '''parse the model_file field of the application configuration
        and read the files.

        The model_file field of the application configuration is
        first split at commas, since it may list more than one file.

        The files may be uris of the form :samp:`file:filename?section=name`,
        in which case a bare configuration object is read from filename
        into the configuration section with key 'name'.

        A simple filename without a section option
        is treated as a standard multi-section configuration file.

        Returns
        -------
        description : Description
            Configuration object.
        '''
        reader = DescriptionParser()
        description = Description()

        Config._log.info("model file: %s" % self.model_file)

        # TODO: make space aware w/ regex
        for model_file in self.model_file.split(','):
            if not model_file.startswith("file:"):
                model_file = 'file:' + model_file

            file_regex = re.compile(r"^file:([^?]*)(\?(.*)?)?")
            m = file_regex.match(model_file)
            model_file = m.group(1)
            file_url_params = {}
            if m.group(3):
                file_url_params.update(
                    ((x[0], x[1])
                     for x in (y.split('=') for y in m.group(3).split('&'))))
            if 'section' in file_url_params:
                section = file_url_params['section']
            else:
                section = None
            Config._log.info("reading model file %s" % (model_file))
            reader.read(model_file, description, section)

        return description