Example #1
0
 def _mountPathError(self, mount_path):
     from ZConfig import ConfigurationError
     if mount_path == '/':
         raise ConfigurationError("No root database configured")
     else:
         raise ConfigurationError(
             "No database configured for mount point at %s" % mount_path)
Example #2
0
    def setupLocale(self):
        # set a locale if one has been specified in the config
        if not self.cfg.locale:
            return

        # workaround to allow unicode encoding conversions in DTML
        import codecs
        dummy = codecs.lookup('utf-8')  # NOQA

        locale_id = self.cfg.locale

        if locale_id is not None:
            try:
                import locale
            except Exception:
                raise ConfigurationError(
                    'The locale module could not be imported.\n'
                    'To use localization options, you must ensure\n'
                    'that the locale module is compiled into your\n'
                    'Python installation.')
            try:
                locale.setlocale(locale.LC_ALL, locale_id)
            except Exception:
                raise ConfigurationError(
                    'The specified locale "%s" is not supported by your'
                    'system.\nSee your operating system documentation for '
                    'more\ninformation on locale support.' % locale_id)
Example #3
0
def root_config(section):
    from ZConfig import ConfigurationError
    from ZConfig.matcher import SectionValue
    here = os.path.dirname(os.path.abspath(__file__))
    swhome = os.path.dirname(os.path.dirname(here))
    section.softwarehome = swhome
    section.zopehome = os.path.dirname(os.path.dirname(swhome))
    if section.environment is None:
        section.environment = {}
    if section.cgi_environment is None:
        section.cgi_environment = {}
    if section.clienthome is None:
        section.clienthome = os.path.join(section.instancehome, "var")
    # set up defaults for pid_filename and lock_filename if they're
    # not in the config
    if section.pid_filename is None:
        section.pid_filename = os.path.join(section.clienthome, 'Z2.pid')
    if section.lock_filename is None:
        section.lock_filename = os.path.join(section.clienthome, 'Z2.lock')

    if not section.databases:
        section.databases = []

    mount_factories = {}  # { name -> factory}
    mount_points = {}  # { virtual path -> name }
    dup_err = ('Invalid configuration: ZODB databases named "%s" and "%s" are '
               'both configured to use the same mount point, named "%s"')

    for database in section.databases:
        points = database.getVirtualMountPaths()
        name = database.config.getSectionName()
        mount_factories[name] = database
        for point in points:
            if mount_points.has_key(point):
                raise ConfigurationError(dup_err %
                                         (mount_points[point], name, point))
            mount_points[point] = name
    section.dbtab = DBTab(mount_factories, mount_points)
    pconfigs = {}
    for pconfig in section.product_config:
        section_name = pconfig.getSectionName()
        if isinstance(pconfig, SectionValue):
            section_type = pconfig.getSectionType()
            if section_type == 'product-config':
                pconfigs[section_name] = pconfig.mapping
            else:
                pconfigs[section_name] = pconfig
        else:
            pconfigs[section_name] = pconfig

    section.product_config = pconfigs

    return section
Example #4
0
def root_config(section):
    from ZConfig import ConfigurationError
    from ZConfig.matcher import SectionValue
    if section.environment is None:
        section.environment = zdaemonEnvironDict()
    if hasattr(section, 'cgi_environment'):
        if section.cgi_environment is None:
            section.cgi_environment = zdaemonEnvironDict()
    if section.clienthome is None:
        section.clienthome = os.path.join(section.instancehome, "var")

    if hasattr(section, 'pid_filename'):
        if section.pid_filename is None:
            section.pid_filename = os.path.join(section.clienthome, 'Z2.pid')
    if hasattr(section, 'lock_filename'):
        if section.lock_filename is None:
            section.lock_filename = os.path.join(section.clienthome, 'Z2.lock')

    if not section.databases:
        section.databases = []

    mount_factories = {}  # { name -> factory}
    mount_points = {}  # { virtual path -> name }
    dup_err = ('Invalid configuration: ZODB databases named "%s" and "%s" are '
               'both configured to use the same mount point, named "%s"')

    for database in section.databases:
        points = database.getVirtualMountPaths()
        name = database.config.getSectionName()
        mount_factories[name] = database
        for point in points:
            if point in mount_points:
                raise ConfigurationError(dup_err %
                                         (mount_points[point], name, point))
            mount_points[point] = name
    section.dbtab = DBTab(mount_factories, mount_points)
    pconfigs = {}
    for pconfig in section.product_config:
        section_name = pconfig.getSectionName()
        if isinstance(pconfig, SectionValue):
            section_type = pconfig.getSectionType()
            if section_type == 'product-config':
                pconfigs[section_name] = pconfig.mapping
            else:
                pconfigs[section_name] = pconfig
        else:
            pconfigs[section_name] = pconfig

    section.product_config = pconfigs

    return section
Example #5
0
    def setupLocale(self):
        # set a locale if one has been specified in the config, else read from
        # environment.

        # workaround to allow unicode encoding conversions in DTML
        dummy = codecs.lookup('utf-8')  # NOQA

        locale_id = self.cfg.locale

        try:
            locale.setlocale(locale.LC_ALL, locale_id or '')
        except locale.Error:
            raise ConfigurationError(
                'The specified locale "%s" is not supported by your'
                'system.\nSee your operating system documentation for '
                'more\ninformation on locale support.' % locale_id)