Пример #1
0
    def _setFakeConfig(self, custom):
        """
        Sets a fake configuration for the current process, using a temporary directory
        """
        config = Config.getInstance()
        test_config = TestConfig.getInstance()

        temp = tempfile.mkdtemp(prefix="indico_")
        self._info('Using %s as temporary dir' % temp)

        os.mkdir(os.path.join(temp, 'log'))
        os.mkdir(os.path.join(temp, 'archive'))

        indicoDist = pkg_resources.get_distribution('indico')
        htdocsDir = indicoDist.get_resource_filename('indico', 'indico/htdocs')
        etcDir = indicoDist.get_resource_filename('indico', 'etc')

        # minimal defaults
        defaults = {
            'BaseURL':
            'http://localhost:8000/indico',
            'BaseSecureURL':
            '',
            'UseXSendFile':
            False,
            'AuthenticatorList': ['Local'],
            'SmtpServer': ('localhost', 58025),
            'SmtpUseTLS':
            'no',
            'DBConnectionParams':
            ('localhost', TestConfig.getInstance().getFakeDBPort()),
            'LogDir':
            os.path.join(temp, 'log'),
            'XMLCacheDir':
            os.path.join(temp, 'cache'),
            'HtdocsDir':
            htdocsDir,
            'ArchiveDir':
            os.path.join(temp, 'archive'),
            'UploadedFilesTempDir':
            os.path.join(temp, 'tmp'),
            'ConfigurationDir':
            etcDir
        }

        defaults.update(custom)

        # set defaults
        config.reset(defaults)

        Config.setInstance(config)
        self._cfg = config

        # re-configure logging and template generator, so that paths are updated
        from MaKaC.common import TemplateExec
        from MaKaC.common.logger import Logger
        TemplateExec.mako = TemplateExec._define_lookup()
        Logger.reset()
Пример #2
0
    def _setFakeConfig(self, custom):
        """
        Sets a fake configuration for the current process, using a temporary directory
        """
        config = Config.getInstance()

        temp = tempfile.mkdtemp(prefix="indico_")
        self._info('Using %s as temporary dir' % temp)

        os.mkdir(os.path.join(temp, 'log'))
        os.mkdir(os.path.join(temp, 'archive'))

        indicoDist = pkg_resources.get_distribution('indico')
        htdocsDir = indicoDist.get_resource_filename('indico', 'indico/htdocs')
        etcDir = indicoDist.get_resource_filename('indico', 'etc')

        # minimal defaults
        defaults = {
            'Debug': True,
            'BaseURL': 'http://localhost:8000',
            'BaseSecureURL': '',
            'AuthenticatorList': [('Local', {})],
            'SmtpServer': ('localhost', 58025),
            'SmtpUseTLS': 'no',
            'DBConnectionParams': ('127.0.0.1', TestConfig.getInstance().getFakeDBPort()),
            'LogDir': os.path.join(temp, 'log'),
            'XMLCacheDir': os.path.join(temp, 'cache'),
            'HtdocsDir': htdocsDir,
            'ArchiveDir': os.path.join(temp, 'archive'),
            'UploadedFilesTempDir': os.path.join(temp, 'tmp'),
            'ConfigurationDir': etcDir
        }

        defaults.update(custom)

        # set defaults
        config.reset(defaults)

        Config.setInstance(config)
        self._cfg = config

        # Update assets environment
        core_env.directory = core_env.directory.replace('/opt/indico/htdocs', config.getHtdocsDir())
        core_env.load_path = [path.replace('/opt/indico/htdocs', config.getHtdocsDir()) for path in core_env.load_path]
        core_env.url_mapping = {path.replace('/opt/indico/htdocs', config.getHtdocsDir()): url for path, url in
                                core_env.url_mapping.iteritems()}
        core_env.config['PYSCSS_LOAD_PATHS'] = [x.replace('/opt/indico/htdocs', config.getHtdocsDir()) for x in
                                                core_env.config['PYSCSS_LOAD_PATHS']]

        # re-configure logging and template generator, so that paths are updated
        from MaKaC.common import TemplateExec
        from MaKaC.common.logger import Logger
        TemplateExec.mako = TemplateExec._define_lookup()
        Logger.reset()
Пример #3
0
    def _process(self):
        try:
            # regenerate file is needed
            self._dict["__rh__"] = self
            self._dict["user"] = None

            data = templateEngine.render(self._tplFile, self._dict).strip()
            with open(self._cacheFile, "w") as fp:
                fp.write(data)

        except Exception:
            Logger.get('vars_js').exception('Problem generating vars.js')
            raise
Пример #4
0
    def _process(self):
        try:
            # regenerate file is needed
            self._dict["__rh__"] = self
            self._dict["user"] = None

            data = templateEngine.render(self._tplFile, self._dict).strip()
            with open(self._cacheFile, "w") as fp:
                fp.write(data)

        except Exception:
            Logger.get('vars_js').exception('Problem generating vars.js')
            raise
Пример #5
0
    def _process(self):
        try:
            # regenerate file is needed
            self._dict["__rh__"] = self
            self._dict["user"] = None

            self._htmlData = templateEngine.render(self._tplFile, self._dict)
            fh = open(self._htmlPath, "w")
            fh.write(self._htmlData)
            fh.close()

            self._setHeaders()

        except Exception, e:
            Logger.get('vars_js').exception('Problem generating vars.js')
            return 'indicoError: %s' % e
Пример #6
0
    def _process( self ):
        try:
            # regenerate file is needed
            self._dict["__rh__"] = self
            self._dict["user"] = None

            self._htmlData = templateEngine.render(self._tplFile, self._dict)
            fh = open(self._htmlPath, "w")
            fh.write(self._htmlData)
            fh.close()

            self._setHeaders()

        except Exception, e:
            Logger.get('vars_js').exception('Problem generating vars.js')
            return 'indicoError: %s' % e
Пример #7
0
    def _setFakeConfig(self, custom):
        """
        Sets a fake configuration for the current process, using a temporary directory
        """
        config = Config.getInstance()
        test_config = TestConfig.getInstance()

        temp = tempfile.mkdtemp(prefix="indico_")
        self._info('Using %s as temporary dir' % temp)

        os.mkdir(os.path.join(temp, 'log'))
        os.mkdir(os.path.join(temp, 'archive'))

        indicoDist = pkg_resources.get_distribution('indico')
        htdocsDir = indicoDist.get_resource_filename('indico', 'indico/htdocs')
        etcDir = indicoDist.get_resource_filename('indico', 'etc')

        # minimal defaults
        defaults = {
            'BaseURL': 'http://localhost:8000/indico',
            'BaseSecureURL': '',
            'UseXSendFile': False,
            'AuthenticatorList': ['Local'],
            'SmtpServer': ('localhost', 58025),
            'SmtpUseTLS': 'no',
            'DBConnectionParams': ('localhost', TestConfig.getInstance().getFakeDBPort()),
            'LogDir': os.path.join(temp, 'log'),
            'XMLCacheDir': os.path.join(temp, 'cache'),
            'HtdocsDir': htdocsDir,
            'ArchiveDir': os.path.join(temp, 'archive'),
            'UploadedFilesTempDir': os.path.join(temp, 'tmp'),
            'ConfigurationDir': etcDir
            }

        defaults.update(custom)

        # set defaults
        config.reset(defaults)

        Config.setInstance(config)
        self._cfg = config

        # re-configure logging and template generator, so that paths are updated
        from MaKaC.common import TemplateExec
        from MaKaC.common.logger import Logger
        TemplateExec.mako = TemplateExec._define_lookup()
        Logger.reset()
Пример #8
0
    def getHTML(self, params=None):
        """Returns the HTML resulting of formating the text contained in
            the corresponding TPL file with the variables returned by the
            getVars method.
            Params:
                params -- additional paramters received from the caller
        """

        self._rh = ContextManager.get('currentRH', None)
        if self.tplId == None:
            self.tplId = self.__class__.__name__[1:]
        self._setTPLFile()
        self.__params = {}
        if params != None:
            self.__params = params

        # include context help info, if it exists
        helpText = None
        if os.path.exists(self.helpFile):
            try:
                fh = open(self.helpFile, "r")
                helpText = fh.read()
                fh.close()
            except exceptions.IOError:
                pass

        vars = self.getVars()

        vars['__rh__'] = self._rh
        vars['self_'] = self

        tempHTML = templateEngine.render(self.tplFile, vars, self)

        if helpText == None:
            return tempHTML
        else:
            try:
                return ContextHelp().merge(self.tplId, tempHTML, helpText)
            except etree.LxmlError, e:
                if tempHTML.strip() == '':
                    raise MaKaCError(
                        _("Template " + str(self.tplId) +
                          " produced empty output, and it has a .wohl file. Error: "
                          + str(e)))
                else:
                    raise
Пример #9
0
    def getHTML( self, params=None ):
        """Returns the HTML resulting of formating the text contained in
            the corresponding TPL file with the variables returned by the
            getVars method.
            Params:
                params -- additional paramters received from the caller
        """

        self._rh = ContextManager.get('currentRH', None)
        if self.tplId == None:
            self.tplId = self.__class__.__name__[1:]
        self._setTPLFile()
        self.__params = {}
        if params != None:
            self.__params = params

        # include context help info, if it exists
        helpText = None
        if os.path.exists(self.helpFile):
            try:
                fh = open( self.helpFile, "r")
                helpText = fh.read()
                fh.close()
            except exceptions.IOError:
                pass

        vars = self.getVars()

        vars['__rh__'] = self._rh
        vars['self_'] = self

        tempHTML = templateEngine.render(self.tplFile, vars, self)

        if helpText == None:
            return tempHTML
        else:
            try:
                return ContextHelp().merge(self.tplId, tempHTML, helpText)
            except etree.LxmlError, e:
                if tempHTML.strip() == '':
                    raise MaKaCError(_("Template " + str(self.tplId) + " produced empty output, and it has a .wohl file. Error: " + str(e)))
                else:
                    raise
Пример #10
0
    def _setFakeConfig(self, custom):
        """
        Sets a fake configuration for the current process, using a temporary directory
        """
        config = Config.getInstance()

        temp = tempfile.mkdtemp(prefix="indico_")
        self._info('Using %s as temporary dir' % temp)

        os.mkdir(os.path.join(temp, 'log'))
        os.mkdir(os.path.join(temp, 'archive'))

        indicoDist = pkg_resources.get_distribution('indico')
        htdocsDir = indicoDist.get_resource_filename('indico', 'indico/htdocs')
        etcDir = indicoDist.get_resource_filename('indico', 'etc')

        # minimal defaults
        defaults = {
            'Debug':
            True,
            'BaseURL':
            'http://localhost:8000',
            'BaseSecureURL':
            '',
            'AuthenticatorList': [('Local', {})],
            'SmtpServer': ('localhost', 58025),
            'SmtpUseTLS':
            'no',
            'DBConnectionParams':
            ('127.0.0.1', TestConfig.getInstance().getFakeDBPort()),
            'LogDir':
            os.path.join(temp, 'log'),
            'XMLCacheDir':
            os.path.join(temp, 'cache'),
            'HtdocsDir':
            htdocsDir,
            'ArchiveDir':
            os.path.join(temp, 'archive'),
            'UploadedFilesTempDir':
            os.path.join(temp, 'tmp'),
            'ConfigurationDir':
            etcDir
        }

        defaults.update(custom)

        # set defaults
        config.reset(defaults)

        Config.setInstance(config)
        self._cfg = config

        # Update assets environment
        core_env.directory = core_env.directory.replace(
            '/opt/indico/htdocs', config.getHtdocsDir())
        core_env.load_path = [
            path.replace('/opt/indico/htdocs', config.getHtdocsDir())
            for path in core_env.load_path
        ]
        core_env.url_mapping = {
            path.replace('/opt/indico/htdocs', config.getHtdocsDir()): url
            for path, url in core_env.url_mapping.iteritems()
        }
        core_env.config['PYSCSS_LOAD_PATHS'] = [
            x.replace('/opt/indico/htdocs', config.getHtdocsDir())
            for x in core_env.config['PYSCSS_LOAD_PATHS']
        ]

        # re-configure logging and template generator, so that paths are updated
        from MaKaC.common import TemplateExec
        from MaKaC.common.logger import Logger
        TemplateExec.mako = TemplateExec._define_lookup()
        Logger.reset()