def test_make_paths_absolute(self):
     pathdict = self.pathdict.copy()
     frontend.make_paths_absolute(pathdict, self.keys, base_path='base')
     self.assertEqual(pathdict['foo'], os.path.abspath('base/hallo'))
     self.assertEqual(pathdict['ham'], os.path.abspath(u'base/h\xE4m'))
     # not touched, because key not in keys:
     self.assertEqual(pathdict['spam'], u'spam')
 def test_make_paths_absolute(self):
     pathdict = self.pathdict.copy()
     frontend.make_paths_absolute(pathdict, self.keys, base_path='base')
     self.assertEqual(pathdict['foo'], os.path.abspath('base/hallo'))
     self.assertEqual(pathdict['ham'], os.path.abspath(u'base/h\xE4m'))
     # not touched, because key not in keys:
     self.assertEqual(pathdict['spam'], u'spam')
Beispiel #3
0
    def setup_publishers(self):
        """
        Manage configurations for individual publishers.

        Each publisher (combination of parser, reader, and writer) may have
        its own configuration defaults, which must be kept separate from those
        of the other publishers.  Setting defaults are combined with the
        config file settings and command-line options by
        `self.get_settings()`.
        """
        for name, publisher in self.publishers.items():
            option_parser = OptionParser(components=publisher.components,
                                         usage=usage,
                                         description=description)
            publisher.option_parser = option_parser
            publisher.setting_defaults = option_parser.get_default_values()
            frontend.make_paths_absolute(publisher.setting_defaults.__dict__,
                                         option_parser.relative_path_settings)
        config_parser = frontend.ConfigParser()
        config_parser.read_standard_files(option_parser)
        self.config_settings = config_parser.get_section('options')
        frontend.make_paths_absolute(
            self.config_settings,
            self.publishers[''].option_parser.relative_path_settings)
        self.settings_spec = self.publishers[''].option_parser.parse_args(
            values=frontend.Values())  # no defaults; just the cmdline opts
        self.initial_settings = self.get_settings('')
Beispiel #4
0
    def setup_publishers(self):
        """
        Manage configurations for individual publishers.

        Each publisher (combination of parser, reader, and writer) may have
        its own configuration defaults, which must be kept separate from those
        of the other publishers.  Setting defaults are combined with the
        config file settings and command-line options by
        `self.get_settings()`.
        """
        for name, publisher in self.publishers.items():
            option_parser = OptionParser(
                components=publisher.components,
                usage=usage, description=description)
            publisher.option_parser = option_parser
            publisher.setting_defaults = option_parser.get_default_values()
            frontend.make_paths_absolute(publisher.setting_defaults.__dict__,
                                         option_parser.relative_path_settings)
        config_parser = frontend.ConfigParser()
        config_parser.read_standard_files(option_parser)
        self.config_settings = config_parser.get_section('options')
        frontend.make_paths_absolute(
            self.config_settings,
            self.publishers[''].option_parser.relative_path_settings)
        self.settings_spec = self.publishers[''].option_parser.parse_args(
            values=frontend.Values())   # no defaults; just the cmdline opts
        self.initial_settings = self.get_settings('')
Beispiel #5
0
 def check_values(self, values, args):
     """Store positional arguments as runtime settings."""
     # Complete a possible switch
     switchOptions(values, bothOption)
     values._old_source, values._new_source, values._destination = self.check_args(args)
     make_paths_absolute(values.__dict__, self.relative_path_settings,
                         os.getcwd())
     values._config_files = self.config_files
     return values
 def check_values(self, values, args):
     """Store positional arguments as runtime settings."""
     # Complete a possible switch
     switchOptions(values, bothOption)
     values._old_source, values._new_source, values._destination = self.check_args(
         args)
     make_paths_absolute(values.__dict__, self.relative_path_settings,
                         os.getcwd())
     values._config_files = self.config_files
     return values
 def test_make_paths_absolute_cwd(self):
     # With base_path None, the cwd is used as base path.
     # Settings values may-be `unicode` instances, therefore
     # os.getcwdu() is used and the converted path is a unicode instance:
     pathdict = self.pathdict.copy()
     frontend.make_paths_absolute(pathdict, self.keys)
     self.assertEqual(pathdict['foo'], os.path.abspath(u'hallo'))
     self.assertEqual(pathdict['ham'], os.path.abspath(u'h\xE4m'))
     # not touched, because key not in keys:
     self.assertEqual(pathdict['spam'], u'spam')
 def test_make_paths_absolute_cwd(self):
     # With base_path None, the cwd is used as base path.
     # Settings values may-be `unicode` instances, therefore
     # os.getcwdu() is used and the converted path is a unicode instance:
     pathdict = self.pathdict.copy()
     frontend.make_paths_absolute(pathdict, self.keys)
     self.assertEqual(pathdict['foo'], os.path.abspath(u'hallo'))
     self.assertEqual(pathdict['ham'], os.path.abspath(u'h\xE4m'))
     # not touched, because key not in keys:
     self.assertEqual(pathdict['spam'], u'spam')
Beispiel #9
0
    def get_settings(self, publisher_name, directory=None):
        """Return a settings object, from multiple sources.

        Copy the setting defaults, overlay the startup config file settings,
        then the local config file settings, then the command-line options.
        Assumes the current directory has been set.

        """
        publisher = self.publishers[publisher_name]
        settings = frontend.Values(publisher.setting_defaults.__dict__)
        settings.update(publisher.config_settings, publisher.option_parser)
        if directory:
            local_config = publisher.option_parser.get_config_file_settings(os.path.join(directory, "docutils.conf"))
            frontend.make_paths_absolute(local_config, publisher.option_parser.relative_path_settings, directory)
            settings.update(local_config, publisher.option_parser)
        settings.update(self.settings_spec.__dict__, publisher.option_parser)
        return settings
Beispiel #10
0
    def get_settings(self, publisher_name, directory=None):
        """
        Return a settings object, from multiple sources.

        Copy the setting defaults, overlay the startup config file settings,
        then the local config file settings, then the command-line options.
        Assumes the current directory has been set.
        """
        publisher = self.publishers[publisher_name]
        settings = frontend.Values(publisher.setting_defaults.__dict__)
        settings.update(publisher.config_settings, publisher.option_parser)
        if directory:
            local_config = publisher.option_parser.get_config_file_settings(
                os.path.join(directory, 'docutils.conf'))
            frontend.make_paths_absolute(
                local_config, publisher.option_parser.relative_path_settings,
                directory)
            settings.update(local_config, publisher.option_parser)
        settings.update(self.settings_spec.__dict__, publisher.option_parser)
        return settings
Beispiel #11
0
    def get_settings(self, publisher_name, directory=None):
        """
        Return a settings object, from multiple sources.

        Copy the setting defaults, overlay the startup config file settings,
        then the local config file settings, then the command-line options.
        Assumes the current directory has been set.
        """
        publisher = self.publishers[publisher_name]
        settings = copy.deepcopy(publisher.setting_defaults)
        settings.__dict__.update(self.config_settings)
        if directory:
            config_parser = frontend.ConfigParser()
            config_parser.read(os.path.join(directory, 'docutils.conf'),
                               publisher.option_parser)
            local_config = config_parser.get_section('options')
            frontend.make_paths_absolute(
                local_config, publisher.option_parser.relative_path_settings,
                directory)
            settings.__dict__.update(local_config)
        settings.__dict__.update(self.settings_spec.__dict__)
        return settings
Beispiel #12
0
    def get_settings(self, publisher_name, directory=None):
        """
        Return a settings object, from multiple sources.

        Copy the setting defaults, overlay the startup config file settings,
        then the local config file settings, then the command-line options.
        Assumes the current directory has been set.
        """
        publisher = self.publishers[publisher_name]
        settings = copy.deepcopy(publisher.setting_defaults)
        settings.__dict__.update(self.config_settings)
        if directory:
            config_parser = frontend.ConfigParser()
            config_parser.read(os.path.join(directory, 'docutils.conf'),
                               publisher.option_parser)
            local_config = config_parser.get_section('options')
            frontend.make_paths_absolute(
                local_config, publisher.option_parser.relative_path_settings,
                directory)
            settings.__dict__.update(local_config)
        settings.__dict__.update(self.settings_spec.__dict__)
        return settings