Ejemplo n.º 1
0
 def testZopeRunConfigure(self):
     old_config = getConfiguration()
     try:
         os.mkdir(TEMPNAME)
         os.mkdir(TEMPPRODUCTS)
     except OSError as why:
         if why == errno.EEXIST:
             # already exists
             pass
     old_argv = sys.argv
     sys.argv = [sys.argv[0]]
     try:
         fname = os.path.join(TEMPNAME, 'zope.conf')
         from ZServer.Zope2.Startup.run import configure
         f = open(fname, 'w')
         f.write('instancehome %s\nzserver-threads 100\n' % TEMPNAME)
         f.flush()
         f.close()
         configure(fname)
         new_config = getConfiguration()
         self.assertEqual(new_config.zserver_threads, 100)
     finally:
         sys.argv = old_argv
         try:
             os.unlink(fname)
         except Exception:
             pass
         setConfiguration(old_config)
Ejemplo n.º 2
0
    def setUp(self):
        from Products.CMFCore.DirectoryView import _dirreg

        WritableFSDVTest.setUp(self)
        self._registerDirectory(self)
        info = _dirreg.getDirectoryInfo(self.ob.fake_skin._dirpath)
        self.use_dir_mtime = info.use_dir_mtime
        self.saved_cfg_debug_mode = getConfiguration().debug_mode
        getConfiguration().debug_mode = True
Ejemplo n.º 3
0
    def setUpZope(self, app, configurationContext):
        # Load ZCML for this package
        import collective.anonfeedback
        xmlconfig.file('configure.zcml',
                       collective.anonfeedback,
                       context=configurationContext)

        # Temporary vardir
        self.vardir = tempfile.mkdtemp()
        self.oldclienthome = config.getConfiguration().clienthome
        config.getConfiguration().clienthome = os.path.join(self.vardir, 'instance')
Ejemplo n.º 4
0
def install_deferred():
    # Temporarily patch fiveconfigure with findProducts able to see only
    # products under reload paths and execute Five configuration directives
    import sauna.reload
    import Products.Five.fiveconfigure
    setattr(Products.Five.fiveconfigure, "findProducts", findDeferredProducts)
    load_config("fiveconfigure.zcml", sauna.reload)
    setattr(Products.Five.fiveconfigure, "findProducts", findProducts)

    # Five pushes old-style product initializations into
    # Products._packages_to_initialize-list. We must loop through that list
    # for our reloaded packages and try to install them.
    import Products
    from App.config import getConfiguration
    from OFS.Application import install_package
    from Zope2.App.startup import app
    # FIXME: Is this really the only way to get our app-object?
    app = app()  # XXX: Help! Should we use use app._p_jar-stuff around here?
    debug_mode = getConfiguration().debug_mode
    from sauna.reload import reload_paths
    for module, init_func in getattr(Products, "_packages_to_initialize", []):
        if getattr(module, "__file__") in reload_paths:
            install_package(app, module, init_func, raise_exc=debug_mode)
    if hasattr(Products, "_packages_to_initialize"):
        del Products._packages_to_initialize
Ejemplo n.º 5
0
def _getCache():
    config = getConfiguration()
    servers = config.product_config['flashuploader'].get('memcache-address')
    servers = servers.split(',')
    servers = [x.strip() for x in servers]
    client = memcache.Client(servers)
    return client
Ejemplo n.º 6
0
    def init_config(self):
        config = getConfiguration()
        if not hasattr(config, 'product_config'):
            config.product_config = {}

        config.product_config['expired-users'] = self.expired_users_config()
        setConfiguration(config)
Ejemplo n.º 7
0
    def coreVersions(self):
        # Useful core information.
        vars = {}
        get_dist = pkg_resources.get_distribution
        vars['Zope'] = get_dist('Zope').version
        vars['Python'] = sys.version
        vars['Platform'] = sys.platform
        vars['Plone'] = get_dist('Products.CMFPlone').version
        vars['Plone Instance'] = self.getInstanceVersion()
        vars['Plone File System'] = self.getFileSystemVersion()
        vars['CMF'] = get_dist('Products.CMFCore').version
        vars['Debug mode'] = getConfiguration().debug_mode and 'Yes' or 'No'
        try:
            vars['PIL'] = get_dist('PIL').version
        except pkg_resources.DistributionNotFound:
            try:
                vars['PIL'] = get_dist('PILwoTK').version
            except pkg_resources.DistributionNotFound:
                try:
                    vars['PIL'] = "%s (Pillow)" % get_dist('Pillow').version
                except pkg_resources.DistributionNotFound:
                    try:
                        import _imaging
                        _imaging  # pyflakes
                        vars['PIL'] = 'unknown'
                    except ImportError:
                        pass

        return vars
Ejemplo n.º 8
0
    def __init__(self, event):
        config = getConfiguration()
        config.servers
        zserver = [
            server for server in config.servers
            if isinstance(server, zhttp_server)
        ][0]
        time.sleep(5)

        warmup_bin = os.environ.get('WARMUP_BIN', False)
        warmup_ini = os.environ.get('WARMUP_INI', False)
        if not warmup_bin:
            logger.error('WARMUP_BIN not set')
        if not warmup_ini:
            logger.error('WARMUP_INI not set')

        if warmup_bin and warmup_ini:
            logger.info('Executing intances warmup')
            proc = subprocess.Popen(
                [
                    "%s %s -p %d" % (
                        warmup_bin, warmup_ini, zserver.port
                    )
                ],
                shell=True
            )
Ejemplo n.º 9
0
 def _cook_check(self):
     if self._v_last_read and not getConfiguration().debug_mode:
         return
     __traceback_info__ = self.filename
     try:
         mtime = os.path.getmtime(self.filename)
     except OSError:
         mtime = 0
     if self._v_program is not None and mtime == self._v_last_read:
         return
     f = open(self.filename, "rb")
     try:
         text = f.read(XML_PREFIX_MAX_LENGTH)
     except:
         f.close()
         raise
     t = sniff_type(text)
     if t != "text/xml":
         # For HTML, we really want the file read in text mode:
         f.close()
         f = open(self.filename, 'U')
         text = ''
     text += f.read()
     f.close()
     self.pt_edit(text, t)
     self._cook()
     if self._v_errors:
         LOG.error('Error in template %s' % '\n'.join(self._v_errors))
         return
     self._v_last_read = mtime
Ejemplo n.º 10
0
 def __init__(self, name, storage=None, **kw):
     ZopeDatabase.__init__(self, SectionValue({"container_class": None, "mount_points": []}, name, None))
     if storage is not None:
         self.open = lambda database_name, databases: ZODB.DB(
             storage, database_name=database_name, databases=databases, **kw
         )
     getConfiguration().dbtab.db_factories[name] = self
Ejemplo n.º 11
0
def is_enabled():
    try:
        from App.config import getConfiguration
        debug_mode = getConfiguration().debug_mode
    except Exception:
        debug_mode = False
    return debug_mode
Ejemplo n.º 12
0
    def version_list(self):
        # Return a list of currently installed products/versions
        path_join=os.path.join
        isdir=os.path.isdir
        exists=os.path.exists

        cfg = getConfiguration()
        product_dir=path_join(cfg.softwarehome,'Products')
        product_names=os.listdir(product_dir)
        product_names.sort()
        info=[]
        for product_name in product_names:
            package_dir=path_join(product_dir, product_name)
            if not isdir(package_dir):
                continue
            version_txt = None
            for name in ('VERSION.TXT', 'VERSION.txt', 'version.txt'):
                v = path_join(package_dir, name)
                if exists(v):
                    version_txt = v
                    break
            if version_txt is not None:
                file=open(version_txt, 'r')
                data=file.readline()
                file.close()
                info.append(data.strip())
        return info
Ejemplo n.º 13
0
    def test_getBookmarkableURLs(self):
        saved_state = getattr(getConfiguration(),
                              'zmi_bookmarkable_urls',
                              True)
        om = self._makeOne()

        # Configuration flag OFF
        getConfiguration().zmi_bookmarkable_urls = False
        self.assertFalse(om.getBookmarkableURLs())

        # Configuration flag ON
        getConfiguration().zmi_bookmarkable_urls = True
        self.assertTrue(om.getBookmarkableURLs())

        # Cleanup
        getConfiguration().zmi_bookmarkable_urls = saved_state
 def setUp(self):
     global original_config
     if original_config is None:
         original_config = getConfiguration()
     self.schema = getSchema()
     os.makedirs(TEMPNAME)
     os.makedirs(TEMPPRODUCTS)
Ejemplo n.º 15
0
def is_enabled():
    try:
        from App.config import getConfiguration
        debug_mode = getConfiguration().debug_mode
    except:
        debug_mode = False
    if debug_mode:
        return True

    try:
        from zope import testrunner
        from zope.testrunner import options
    except ImportError:
        from zope.testing import testrunner
        from zope.testing.testrunner import options
    frame = sys._getframe(2)
    while frame is not None and frame.f_code is not testrunner.run.func_code:
        frame = frame.f_back
    if frame is not None:
        try:
            pm = options.get_options().post_mortem
            return bool(pm)
        except:
            # options not recognized by test runnergiven
            pass

    return False
Ejemplo n.º 16
0
    def setUp(self):
        import collective.taskqueue
        xmlconfig.file('configure.zcml', collective.taskqueue,
                       context=self['configurationContext'])

        # Configure
        config = getConfiguration()
        config.product_config = {'collective.taskqueue': {'queue': self.queue}}
        taskqueue.reset()

        # Define logging request handler to replace ZPublisher
        def logging_handler(app, request, response):
            logger.info(request.getURL() + request.get("PATH_INFO"))
            response.stdout.write('HTTP/1.1 204\r\n')
            response.stdout.close()

        # Define ZPublisher-based request handler to be used with zserver
        def zserver_handler(app, request, response):
            from ZPublisher import publish_module
            publish_module(app, request=request, response=response)

        # Create TaskQueueServer
        from collective.taskqueue.server import TaskQueueServer
        if not self.zserver_enabled:
            self['server'] = TaskQueueServer(queue=self.queue,
                                             handler=logging_handler)
        else:
            self['server'] = TaskQueueServer(queue=self.queue,
                                             handler=zserver_handler,
                                             concurrent_limit=0)
Ejemplo n.º 17
0
def install_products(app):
    # Install a list of products into the basic folder class, so
    # that all folders know about top-level objects, aka products

    folder_permissions = get_folder_permissions()
    meta_types=[]
    done={}

    debug_mode = getConfiguration().debug_mode

    transaction.get().note('Prior to product installs')
    transaction.commit()

    products = get_products()

    for priority, product_name, index, product_dir in products:
        # For each product, we will import it and try to call the
        # intialize() method in the product __init__ module. If
        # the method doesnt exist, we put the old-style information
        # together and do a default initialization.
        if done.has_key(product_name):
            continue
        done[product_name]=1
        install_product(app, product_dir, product_name, meta_types,
                        folder_permissions, raise_exc=debug_mode)

    # Delayed install of packages-as-products
    for module, init_func in tuple(get_packages_to_initialize()):
        install_package(app, module, init_func, raise_exc=debug_mode)

    Products.meta_types=Products.meta_types+tuple(meta_types)
    InitializeClass(Folder.Folder)
Ejemplo n.º 18
0
def get_view(name=None, context=None, request=None):
    """Get a BrowserView object.

    :param name: [required] Name of the view.
    :type name: string
    :param context: [required] Context on which to get view.
    :type context: context object
    :param request: [required] Request on which to get view.
    :type request: request object
    :raises:
        :class:`~plone.api.exc.MissingParameterError`,
        :class:`~plone.api.exc.InvalidParameterError`
    :Example: :ref:`content_get_view_example`
    """
    # It happens sometimes that ACTUAL_URL is not set in tests. To be nice
    # and not throw strange errors, we set it to be the same as URL.
    # TODO: if/when we have api.env.test_mode() boolean in the future, use that
    config = getConfiguration()
    if config.dbtab.__module__ == "plone.testing.z2":
        request["ACTUAL_URL"] = request["URL"]

    try:
        return getMultiAdapter((context, request), name=name)
    except:
        # get a list of all views so we can display their names in the error
        # msg
        sm = getSiteManager()
        views = sm.adapters.lookupAll(required=(providedBy(context), providedBy(request)), provided=Interface)
        views_names = [view[0] for view in views]

        raise InvalidParameterError(
            "Cannot find a view with name '{0}'.\n"
            "Available views are:\n"
            "{1}".format(name, "\n".join(sorted(views_names)))
        )
Ejemplo n.º 19
0
def main(argv=sys.argv):
    if len(sys.argv) < 3:
        raise Exception("must specify a zope config file and a celery command")
    argv = argv
    filepath = sys.argv[2]
    os.environ['ZOPE_CONFIG'] = filepath
    sys.argv = ['']
    from Zope2.Startup.run import configure
    configure(os.environ['ZOPE_CONFIG'])

    # Fix for setuptools generated scripts, so that it will
    # work with multiprocessing fork emulation.
    # (see multiprocessing.forking.get_preparation_data())
    if __name__ != "__main__":
        sys.modules["__main__"] = sys.modules[__name__]

    # load tasks up
    tasks = dict([(i.name, i.load()) for i in iter_entry_points(
                  group='celery_tasks', name=None)])

    tasks = getConfiguration().environment.get('CELERY_TASKS')
    if tasks:
        try:
            __import__(tasks)
        except ImportError:
            logger.warn('error importing tasks: ' + tasks)
    argv.remove(argv[2])
    # restore argv
    sys.argv = argv
    Worker(app=getCelery()).execute_from_commandline()
Ejemplo n.º 20
0
  def _tailFile(self, file_name, line_number=10):
    """
    Do a 'tail -f -n line_number filename'
    """
    log_file = os.path.join(getConfiguration().instancehome, file_name)
    if not os.path.exists(log_file):
      raise IOError, 'The file: %s does not exist.' % log_file

    char_per_line = 75

    with open(log_file,'r') as tailed_file:
      while 1:
        try:
          tailed_file.seek(-1 * char_per_line * line_number, 2)
        except IOError:
          tailed_file.seek(0)
        pos = tailed_file.tell()

        lines = tailed_file.read().split("\n")
        if len(lines) > (line_number + 1) or not pos:
          break
        # The lines are bigger than we thought
        char_per_line *= 1.3  # Inc for retry

    start = max(len(lines) - line_number - 1, 0)
    return "\n".join(lines[start:len(lines)])
Ejemplo n.º 21
0
    def get_zope_config():
        '''Try and figure out where the groupserver config is, using Zope

:returns: The location of the config file from Zope.
:rtype: str
:raises gs.config.errors.ConfigFileError: The configration file failed to
    be read.

The location of the configration file should either be the
``$ZOPE_HOME/etc/gsconfig.ini`` or ``$INSTANCE_HOME/etc/gsconfig.ini``, with
the latter preferred for backwards compatibility, but the former being more
typical. This normally equates to ``etc/gsconfig.ini`` within what the
installation documentation refers to as *the GroupServer directory*.
'''
        cfg = getConfiguration()
        # The old location. May go AWOL.
        iConfigPath = path_join(cfg.instancehome, 'etc/gsconfig.ini')
        # The better location.
        zConfigPath = path_join(cfg.zopehome, 'etc/gsconfig.ini')

        if ((not isfile(iConfigPath)) and (not isfile(zConfigPath))):
            m = 'Could not read the configuration, as neither "{0}" nor '\
                '"{1}" exist.'
            msg = m.format(iConfigPath, zConfigPath)
            raise ConfigFileError(msg)

        retval = iConfigPath if isfile(iConfigPath) else zConfigPath
        return retval
Ejemplo n.º 22
0
    def __init__(self, **kwargs):
        self.redis = redis.StrictRedis(**kwargs)
        self.pubsub = self.redis.pubsub()  # Create pubsub for notifications
        self._requeued_processing = False  # Requeue old processing on start

        if getattr(getConfiguration(), 'debug_mode', False):
            self.redis.ping()  # Ensure Zope startup to crash when Redis down
Ejemplo n.º 23
0
 def getDatabaseNames(self, quote=False):
     configuration = getConfiguration()
     names = configuration.dbtab.listDatabaseNames()
     names.sort()
     if quote:
         return [(name, parse.quote(name)) for name in names]
     return names
Ejemplo n.º 24
0
 def prepare(self):
     self.setupInitialLogging()
     self.setupLocale()
     self.setupSecurityOptions()
     self.setupPublisher()
     # Start ZServer servers before we drop privileges so we can bind to
     # "low" ports:
     self.setupZServer()
     self.setupServers()
     # drop privileges after setting up servers
     self.dropPrivileges()
     self.setupFinalLogging()
     self.makeLockFile()
     self.makePidFile()
     self.setupInterpreter()
     self.startZope()
     self.serverListen()
     from App.config import getConfiguration
     config = getConfiguration()
     self.registerSignals()
     # emit a "ready" message in order to prevent the kinds of emails
     # to the Zope maillist in which people claim that Zope has "frozen"
     # after it has emitted ZServer messages.
     
     logger.info('Ready to handle requests')
     self.sendEvents()
Ejemplo n.º 25
0
def cacheKey(func, rules_url, theme_node):
    if getConfiguration().debug_mode:
        raise DontCache()
    key = md5()
    key.update(rules_url)
    key.update(html.tostring(theme_node))
    return key.hexdigest()
def readZopeConf():
    """Overriding default values with the ones from zope.conf
    """
    global SITE_CHARSET, DOWNLOAD_BUFFER_SIZE

    if SITE_CHARSET is not None:
        # We run this only once
        return

    default_pdfbook_config = {
        'site-charset': 'utf-8',
        'download-buffer-size': '40000'
        }

    from App.config import getConfiguration
    try:
        pdfbook_config = getConfiguration().product_config[PROJECTNAME.lower()]
    except (KeyError, AttributeError):
        # Zope 2.10 raises a KeyError when Zope 2.12 raises an AttributeError
        # if the <product-config ...> is missing in zope.conf
        pdfbook_config =  default_pdfbook_config
    getConfData = lambda key: pdfbook_config.get(key, default_pdfbook_config[key])
    SITE_CHARSET = getConfData('site-charset')
    DOWNLOAD_BUFFER_SIZE = int(getConfData('download-buffer-size'))
    return
Ejemplo n.º 27
0
    def getContentUri(self, context):
        #1. determine subject uri for context
        # FIXME: use property, attribute, context absolute url
        from Products.ZCatalog.interfaces import ICatalogBrain
        if ICatalogBrain.providedBy(context):
            uuid = context.UID
        else:
            context = aq_base(context)
            uuid = IUUID(context, None)
        if uuid is None:
            # we probably deal with a new contet object that does not have an
            # uuid yet let's generate one
            from plone.uuid.interfaces import IMutableUUID, IUUIDGenerator
            generator = queryUtility(IUUIDGenerator)
            if generator is None:
                return  # TODO: raise error
            uuid = generator()
            if not uuid:
                return  # TODO: raise error
            IMutableUUID(context).set(uuid)

        #url = base_uri + /@@redirect-to-uuid/<uuid>
        #uri = context.subjecturi

        # FIXME: shouldn't consult config here, IORDF does this.
        try:
            settings = getConfiguration().product_config.get('gu.plone.rdf', dict())
            baseuri = settings['baseuri']
        except Exception as e:
            # FIXME: be specific about exceptions
            baseuri = 'urn:plone:'
            LOG.warn("No baseuri configured: using %s (%s)", baseuri, e)
        contenturi = "%s%s" % (baseuri, uuid)
        return contenturi
Ejemplo n.º 28
0
    def base_dir(self):
        """
        Return the beginning of the source file path determined by
        the path_origin (including a trailing path seperator).

        If path_origin is 'root' it returns '', because the file_path
        is supposed to be absolute.

        If the file_path() is absolute already it will return '',
        too.
        """
        if os.path.isabs(self.file_path()):
            return ""
        elif self.path_origin() == "root":
            return os.path.sep
        elif self.path_origin() == "module":
            tpl = os.path.split(self.module().__file__)
            module_path = tpl[0]

            return module_path + os.path.sep
        elif self.path_origin() == "instance":
            cfg = getConfiguration()
            if cfg.instancehome[-1] == os.path.sep:
                return cfg.instancehome
            else:
                return cfg.instancehome + os.path.sep
Ejemplo n.º 29
0
    def getInstanceMetadata(self):
        """ return instance metadata"""

        pm = getattr(self.context, 'portal_migration')
        result = {} 
        versions = {}
        versions = pm.coreVersions()      
        result['python_version'] = versions['Python']
        result['zope_version'] = versions['Zope']
        result['plone_version'] = versions['Plone'] 
        if versions['Debug mode'] == 'Yes':
            result['debug_mode'] = True
        else:
            result['debug_mode'] = False

        result['instance_home'] = getConfiguration().instancehome
        result['http_port'] = self.getPort()
        result['uptime'] = self.process_time(_when=None)
        result['etasp_version'] = self.getETASPVersion()

        result_json = json.dumps(result)

        response = self.request.RESPONSE
        setheader = response.setHeader
        setheader('Content-Length', 1)
        setheader('Content-Type', 'application/json; charset=utf-8')

        
        return result_json
Ejemplo n.º 30
0
 def __getitem__(self, name):
     configuration = getConfiguration()
     db = configuration.dbtab.getDatabase(name=name)
     m = AltDatabaseManager()
     m.id = name
     m._p_jar = FakeConnection(db, self.getPhysicalRoot()._p_jar)
     return m.__of__(self)
Ejemplo n.º 31
0
 def run(self):
     # the mainloop.
     try:
         from App.config import getConfiguration
         config = getConfiguration()  # NOQA
         import Lifetime
         Lifetime.loop()
         from ZServer.Zope2.Startup.config import ZSERVER_EXIT_CODE
         sys.exit(ZSERVER_EXIT_CODE)
     finally:
         self.shutdown()
 def resetCredentials(self, request, response):
     """ resetCredential by expiring auth cookie
     """
     config = getConfiguration()
     cookie_domain = self._get_cookie_domain(config)
     if cookie_domain:
         response.expireCookie(self.cookie_name,
                               path=self.path,
                               domain=cookie_domain)
     else:
         response.expireCookie(self.cookie_name, path=self.path)
Ejemplo n.º 33
0
 def _getImportPaths(self):
     cfg = getConfiguration()
     paths = []
     zopehome = getattr(cfg, 'zopehome', None)
     if zopehome is not None and cfg.zopehome is not None:
         paths.append(zopehome)
     if not cfg.instancehome in paths:
         paths.append(cfg.instancehome)
     if not cfg.clienthome in paths:
         paths.append(cfg.clienthome)
     return paths
Ejemplo n.º 34
0
def set_db_config(host=None, port=None):
    # Modify the database configuration manually
    from App.config import getConfiguration
    for serverConfig in getConfiguration().databases:
        adapterConfig= serverConfig.config.storage.config.adapter.config
        xhost, xport = adapterConfig.host, adapterConfig.port
        if host: 
            xhost = host
        if port: 
            xport = port
        adapterConfig.host, adapterConfig.port = xhost, xport
Ejemplo n.º 35
0
 def run(self):
     # the mainloop.
     try:
         from App.config import getConfiguration
         config = getConfiguration()
         import ZServer
         import Lifetime
         Lifetime.loop()
         sys.exit(ZServer.exit_code)
     finally:
         self.shutdown()
Ejemplo n.º 36
0
Archivo: Zope.py Proyecto: kenara/Zope
def _default_encoding():
    ''' Retrieve default encoding from config '''
    global _DEFAULT_ENCODING
    if _DEFAULT_ENCODING is None:
        from App.config import getConfiguration
        config = getConfiguration()
        try:
            _DEFAULT_ENCODING = config.zpublisher_default_encoding
        except AttributeError:
            _DEFAULT_ENCODING = 'utf8'
    return _DEFAULT_ENCODING
Ejemplo n.º 37
0
def start_successlogging(unused):
    """start successlogging if configured."""
    from App.config import getConfiguration
    config = getConfiguration().product_config.get('successlogging')
    if config is None: return # not configured
    global _log_good, _log_bad
    _log_good = Rotator(config['filebase'] + '_good', lock=True)
    _log_bad = Rotator(config['filebase'] + '_bad', lock=True)
    # register publication observers
    provideHandler(handle_request_success)
    provideHandler(handle_request_failure)
Ejemplo n.º 38
0
def readZopeConf():
    """Read custom config from zope.conf or use defaults
    """
    global SITE_CHARSET, BATCH_SIZE
    from App.config import getConfiguration
    import codecs
    default_config = {'charset': 'UTF-8', 'batch-size': 30}
    try:
        pg_config = getConfiguration().product_config['ploneglossary']
    except KeyError, e:
        pg_config = default_config
Ejemplo n.º 39
0
def _default_encoding():
    '''get default encoding from configuration
       if zpublisher_default_encoding is not set, use utf8
    '''
    # avoid doing this at module scope!
    from App.config import getConfiguration
    global _DEFAULT_ENCODING
    if _DEFAULT_ENCODING is None:
        config = getConfiguration()
        _DEFAULT_ENCODING = getattr(config, 'zpublisher_default_encoding',
                                    'utf8')
Ejemplo n.º 40
0
 def logConflicts(self, v, REQUEST):
     self.conflict_errors += 1
     level = getattr(getConfiguration(), 'conflict_error_log_level', 0)
     if not self.conflict_logger.isEnabledFor(level):
         return False
     self.conflict_logger.log(
         level, "%s at %s: %s (%d conflicts (%d unresolved) "
         "since startup at %s)", v.__class__.__name__,
         REQUEST.get('PATH_INFO', '<unknown>'), v, self.conflict_errors,
         self.unresolved_conflict_errors, startup_time)
     return True
Ejemplo n.º 41
0
 def develop_theme(self):
     ''' Check if the theme should be recompiled
     every time the transform is applied
     '''
     if not getConfiguration().debug_mode:
         return False
     if self.debug_theme():
         return True
     if environ.get('DIAZO_ALWAYS_CACHE_RULES'):
         return False
     return True
Ejemplo n.º 42
0
def start_monitor(unused):
    """start the request monitor if configured."""
    from App.config import getConfiguration
    config = getConfiguration().product_config.get('requestmonitor')
    if config is None:
        return  # not configured
    # register publication observers
    provideHandler(handle_request_start)
    provideHandler(handle_request_end)
    monitor = _Monitor(config)
    start_new_thread(monitor.run, ())
Ejemplo n.º 43
0
    def setUpZope(self, app, configurationContext):

        cfg = getConfiguration()
        cfg.product_config = {'beaker': self.zconfigData}

        import cs.auth.googleplus
        xmlconfig.file('configure.zcml', cs.auth.googleplus,
                       context=configurationContext)

        import cs.auth.googleplus.tests
        xmlconfig.file('tests.zcml', cs.auth.googleplus.tests,
                       context=configurationContext)
Ejemplo n.º 44
0
def initialize():
    try:
        from raven.contrib.zope import ZopeSentryHandler
    except ImportError:
        return
    else:
        from App.config import getConfiguration
        env = getattr(getConfiguration(), 'environment', {})
        sentry_dsn = env.get('SENTRY_DSN')
        if sentry_dsn:
            sentry_handler = ZopeSentryHandler(sentry_dsn)
            publish_error_log.addHandler(sentry_handler)
def getRedirectFromConfiguration():
    config = getConfiguration()
    if not hasattr(config, 'product_config'):
        return False
    product_config = config.product_config
    if config is None:
        return False
    configuration = product_config.get('collective.redirectacquired', None)
    if configuration is not None:
        return configuration.get('redirect', 'False') == 'True'
    else:
        return False
Ejemplo n.º 46
0
                def _installBusinessTemplateList(
                        self,
                        bt_list,
                        update_repository_bt_list=True,
                        *args,
                        **kwargs):
                    """
          Before installing BTs by calling the original method:

          1/ Get filesystem BT repositories and set them to Template Tool
          2/ Update BT repositories
          3/ Resolve dependencies:
             * dependency_list: recursive.
             * test_dependency_list: non-recursive.
          4/ Install BTs as before
          """
                    template_tool = self.portal.portal_templates

                    from Products.ERP5.ERP5Site import getBootstrapDirectory
                    bt5_path_list = [
                        os.environ.get('erp5_tests_bootstrap_path')
                        or getBootstrapDirectory()
                    ]

                    bt5_path = os.environ.get('erp5_tests_bt5_path')
                    if bt5_path:
                        bt5_path_list.extend([
                            bt5_path.replace('*', '')
                            for bt5_path in bt5_path.split(',')
                        ])
                    else:
                        from App.config import getConfiguration
                        instancehome = getConfiguration().instancehome
                        bt5_path_list.append(os.path.join(instancehome, 'bt5'))

                    bt5_path_list = [
                        bt5_path for bt5_path in bt5_path_list
                        if os.path.exists(bt5_path)
                    ]

                    template_tool.updateRepositoryBusinessTemplateList(
                        bt5_path_list)

                    url_bt_tuple_list = [
                        ('%s/%s' % (repository, bt_title), bt_title)
                        for repository, bt_title in
                        template_tool.resolveBusinessTemplateListDependency(
                            bt_list, with_test_dependency_list=True)
                    ]

                    return super(_ZodbTestComponentBootstrapOnly,
                                 self)._installBusinessTemplateList(
                                     url_bt_tuple_list, *args, **kwargs)
Ejemplo n.º 47
0
def prepareReportDirectory(self, expected_filename):
    """
  Remove existing report with the given filename if any. This must be called
  before a report button is clicked
  """
    filename_path = os.path.join(getConfiguration().instancehome, 'var',
                                 expected_filename)

    if os.path.exists(filename_path):
        os.remove(filename_path)

    return 'Done'
Ejemplo n.º 48
0
def structured_text(v, name='(Unknown name)', md={}):

    if isinstance(v, str):
        txt = v
    elif aq_base(v).meta_type in ['DTML Document', 'DTML Method']:
        txt = aq_base(v).read_raw()
    else:
        txt = str(v)

    level = getConfiguration().structured_text_header_level
    doc = DocumentWithImages()(txt)
    return HTML()(doc, level, header=False)
Ejemplo n.º 49
0
def PropertiedUser__init__(self, id, login=None):
    orig_PropertiedUser__init__(self, id, login)
    if id in getattr(
            getattr(
                getConfiguration(),
                'product_config',
                {},
            ).get('erp5'),
            'developer_list',
        (),
    ):
        self._roles[DEVELOPER_ROLE_ID] = 1
Ejemplo n.º 50
0
def start_timelogging(unused):
    """start timelogging if configured."""
    from App.config import getConfiguration
    config = getConfiguration().product_config.get('timelogging')
    if config is None: return # not configured
    global _logfile
    _logfile = Rotator(config['filebase'], lock=True)
    # indicate restart
    _log('0', info='restarted')
    # register publication observers
    provideHandler(handle_request_start)
    provideHandler(handle_request_success)
    provideHandler(handle_request_failure)
Ejemplo n.º 51
0
    def get_token(self):
        configuration = getConfiguration()
        conf = configuration.product_config.get('collective.converse')

        otp_service = pyotp.TOTP(conf.get('otp_seed'),
                                 digits=collective.converse.OTP_DIGITS,
                                 interval=collective.converse.OTP_INTERVAL)
        otp = otp_service.generate_otp(otp_service.timecode(datetime.utcnow()))
        nonce = ''.join([str(random.randint(0, 9)) for i in range(32)])
        string_to_sign = otp + nonce + self.jid
        signature = hmac.new(conf.get('token_secret'), string_to_sign,
                             hashlib.sha256).digest()
        return u"{} {}".format(otp + nonce, base64.b64encode(signature))
Ejemplo n.º 52
0
    def setUp(self):
        from Products.CMFCore.DirectoryView import _dirreg

        WritableFSDVTest.setUp(self)
        self.saved_cfg_debug_mode = getConfiguration().debug_mode
        getConfiguration().debug_mode = True

        # initialise skins
        self._registerDirectory(self)

        # add a method to the fake skin folder
        self._writeFile('test2.py', "return 'test2'")

        # edit the test1 method
        self._writeFile('test1.py', "return 'new test1'")

        # add a new folder
        mkdir(join(self.skin_path_name, 'test3'))

        info = _dirreg.getDirectoryInfo(self.ob.fake_skin._dirpath)
        info.reload()
        self.use_dir_mtime = info.use_dir_mtime
Ejemplo n.º 53
0
def _get_handlebars_template_cache_key(method, path):
    """Calculate cache key for get_handlebars_template for a specific template.

    In development, the template is cached until the template file is modified.
    In production, the template is cached for the process duration.
    Especially while deploying (updating), it is important that a production
    process does not reload components from the file system in order to keep
    code and resources in sync.
    """
    if not getConfiguration().debug_mode:
        return str(path)
    else:
        return '{0!s}-{0.mtime}'.format(Path(path))
def _getZopeConfigurationFile(relative_path="", mode="r"):
  """
   Get a configuration file from the instance using relative path
  """
  if ".." in relative_path or relative_path.startswith("/"):
    raise Unauthorized("In Relative Path, you cannot use .. or startwith / for security reason.")

  instance_home = getConfiguration().instancehome
  file_path = os.path.join(instance_home, relative_path)
  if not os.path.exists(file_path):
    raise IOError, 'The file: %s does not exist.' % file_path

  return open(file_path, mode)
Ejemplo n.º 55
0
 def _setCookie(self, cookie, response):
     cookie = binascii.b2a_base64(cookie).rstrip()
     # disable secure cookie in development mode, to ease local testing
     if getConfiguration().debug_mode:
         secure = False
     else:
         secure = self.secure
     options = dict(path=self.path, secure=secure, http_only=True)
     if self.cookie_domain:
         options['domain'] = self.cookie_domain
     if self.cookie_lifetime:
         options['expires'] = cookie_expiration_date(self.cookie_lifetime)
     response.setCookie(self.cookie_name, cookie, **options)
Ejemplo n.º 56
0
 def _updateFromFS(self):
     parsed = self._parsed
     if not parsed or getConfiguration().debug_mode:
         try:
             mtime = os.stat(self._filepath).st_mtime
         except:
             mtime = 0.0
         if not parsed or mtime != self._file_mod_time:
             self._readFile(1)
             if mtime != self._file_mod_time or mtime == 0.0:
                 self.ZCacheable_invalidate()
                 self._file_mod_time = mtime
             self._parsed = 1
Ejemplo n.º 57
0
 def setUpZCML(self):
     super(MuninZopeFixture, self).setUpZCML()
     from zope.configuration import xmlconfig
     import munin.zope
     cfg = getConfiguration()
     cfg.product_config = {'munin.zope': {'secret': 'muninsecret'}}
     # load zcml & install package
     context = self['configurationContext']
     fiveconfigure.debug_mode = True
     xmlconfig.file('configure.zcml', munin.zope, context=context)
     # load our holder_view for the 'threads.txt' test
     xmlconfig.file('tests.zcml', munin.zope, context=context)
     fiveconfigure.debug_mode = False
Ejemplo n.º 58
0
    def _listFilesystemObjects(self):
        """ Return a mapping of any filesystem objects we "hold".
        """
        if (self._v_filesystem_objects is not None
                and not getConfiguration().debug_mode):
            return self._v_filesystem_objects

        if not self.filesystem_path:
            return {'testcases': (), 'subdirs': {}}

        path = os.path.abspath(self.filesystem_path)

        self._v_filesystem_objects = self._grubFilesystem(path)
        return self._v_filesystem_objects
Ejemplo n.º 59
0
Archivo: serve.py Proyecto: kenara/Zope
    def makePidFile(self):
        options = getConfiguration()
        try:
            IO_ERRORS = (IOError, OSError, WindowsError)
        except NameError:
            IO_ERRORS = (IOError, OSError)

        try:
            if os.path.exists(options.pid_filename):
                os.unlink(options.pid_filename)
            with open(options.pid_filename, 'w') as fp:
                fp.write(str(os.getpid()))
        except IO_ERRORS:
            pass
Ejemplo n.º 60
0
 def __init__(self, name, storage=None, **kw):
     ZopeDatabase.__init__(
         self,
         SectionValue({
             'container_class': None,
             'mount_points': [],
         }, name, None))
     if storage is not None:
         self.open = lambda database_name, databases: ZODB.DB(
             storage,
             database_name=database_name,
             databases=databases,
             **kw)
     getConfiguration().dbtab.db_factories[name] = self