def __init__(self):
        self.__dict__ = self.__shared_state
        if self.__shared_state: return
        self.allura_templates = pkg_resources.resource_filename(
            'allura', 'templates')

        # Setup SOLR
        self.solr_server = aslist(config.get('solr.server'), ',')
        # skip empty strings in case of extra commas
        self.solr_server = [s for s in self.solr_server if s]
        self.solr_query_server = config.get('solr.query_server')
        if asbool(config.get('solr.mock')):
            self.solr = self.solr_short_timeout = MockSOLR()
        elif self.solr_server:
            self.solr = make_solr_from_config(self.solr_server,
                                              self.solr_query_server)
            self.solr_short_timeout = make_solr_from_config(
                self.solr_server,
                self.solr_query_server,
                timeout=int(config.get('solr.short_timeout', 10)))
        else:  # pragma no cover
            self.solr = None
            self.solr_short_timeout = None
        self.use_queue = asbool(config.get('use_queue', False))

        # Load login/logout urls; only used for SFX logins
        self.login_url = config.get('auth.login_url', '/auth/')
        self.logout_url = config.get('auth.logout_url', '/auth/logout')
        self.login_fragment_url = config.get('auth.login_fragment_url',
                                             '/auth/login_fragment')

        # Setup Gravatar
        self.gravatar = gravatar.url

        self.oid_store = M.OpenIdStore()

        # Setup pygments
        self.pygments_formatter = utils.LineAnchorCodeHtmlFormatter(
            cssclass='codehilite', linenos='table')

        # Setup Pypeline
        self.pypeline_markup = pypeline_markup

        # Setup analytics
        accounts = config.get('ga.account', 'UA-XXXXX-X')
        accounts = accounts.split(' ')
        self.analytics = analytics.GoogleAnalytics(accounts=accounts)

        self.icons = dict(
            admin=Icon('x', 'ico-admin'),
            pencil=Icon('p', 'ico-pencil'),
            help=Icon('h', 'ico-help'),
            search=Icon('s', 'ico-search'),
            history=Icon('N', 'ico-history'),
            feed=Icon('f', 'ico-feed'),
            mail=Icon('M', 'ico-mail'),
            reply=Icon('w', 'ico-reply'),
            tag=Icon('z', 'ico-tag'),
            flag=Icon('^', 'ico-flag'),
            undelete=Icon('+', 'ico-undelete'),
            delete=Icon('#', 'ico-delete'),
            close=Icon('D', 'ico-close'),
            table=Icon('n', 'ico-table'),
            stats=Icon('Y', 'ico-stats'),
            pin=Icon('@', 'ico-pin'),
            folder=Icon('o', 'ico-folder'),
            fork=Icon('R', 'ico-fork'),
            merge=Icon('J', 'ico-merge'),
            plus=Icon('+', 'ico-plus'),
            conversation=Icon('q', 'ico-conversation'),
            group=Icon('g', 'ico-group'),
            user=Icon('U', 'ico-user'),
            secure=Icon('(', 'ico-lock'),
            unsecure=Icon(')', 'ico-unlock'),
            star=Icon('S', 'ico-star'),
            watch=Icon('E', 'ico-watch'),
            expand=Icon('`', 'ico-expand'),
            restore=Icon('J', 'ico-restore'),
            # Permissions
            perm_read=Icon('E', 'ico-focus'),
            perm_update=Icon('0', 'ico-sync'),
            perm_create=Icon('e', 'ico-config'),
            perm_register=Icon('e', 'ico-config'),
            perm_delete=Icon('-', 'ico-minuscirc'),
            perm_tool=Icon('x', 'ico-config'),
            perm_admin=Icon('(', 'ico-lock'),
            perm_has_yes=Icon('3', 'ico-check'),
            perm_has_no=Icon('d', 'ico-noentry'),
            perm_has_inherit=Icon('2', 'ico-checkcircle'),
        )

        # Cache some loaded entry points
        def _cache_eps(section_name, dict_cls=dict):
            d = dict_cls()
            for ep in h.iter_entry_points(section_name):
                value = ep.load()
                d[ep.name] = value
            return d

        class entry_point_loading_dict(dict):
            def __missing__(self, key):
                self[key] = _cache_eps(key)
                return self[key]

        self.entry_points = entry_point_loading_dict(
            tool=_cache_eps('allura', dict_cls=utils.CaseInsensitiveDict),
            auth=_cache_eps('allura.auth'),
            registration=_cache_eps('allura.project_registration'),
            theme=_cache_eps('allura.theme'),
            user_prefs=_cache_eps('allura.user_prefs'),
            spam=_cache_eps('allura.spam'),
            stats=_cache_eps('allura.stats'),
            site_stats=_cache_eps('allura.site_stats'),
            admin=_cache_eps('allura.admin'),
        )

        # Zarkov logger
        self._zarkov = None

        # Set listeners to update stats
        statslisteners = []
        for name, ep in self.entry_points['stats'].iteritems():
            statslisteners.append(ep())
        self.statsUpdater = PostEvent(statslisteners)

        self.tmpdir = os.getenv('TMPDIR', '/tmp')
Esempio n. 2
0
    def __init__(self):
        self.__dict__ = self.__shared_state
        if self.__shared_state:
            return
        self.allura_templates = pkg_resources.resource_filename(
            'allura', 'templates')
        # Setup SOLR
        self.solr_server = aslist(config.get('solr.server'), ',')
        # skip empty strings in case of extra commas
        self.solr_server = [s for s in self.solr_server if s]
        self.solr_query_server = config.get('solr.query_server')
        if self.solr_server:
            self.solr = make_solr_from_config(self.solr_server,
                                              self.solr_query_server)
            self.solr_short_timeout = make_solr_from_config(
                self.solr_server,
                self.solr_query_server,
                timeout=int(config.get('solr.short_timeout', 10)))
        else:  # pragma no cover
            log.warning('Solr config not set; using in-memory MockSOLR')
            self.solr = self.solr_short_timeout = MockSOLR()

        # Load login/logout urls; only used for customized logins
        self.login_url = config.get('auth.login_url', '/auth/')
        self.logout_url = config.get('auth.logout_url', '/auth/logout')
        self.login_fragment_url = config.get('auth.login_fragment_url',
                                             '/auth/login_fragment/')

        # Setup Gravatar
        self.gravatar = gravatar.url

        # Setup pygments
        self.pygments_formatter = utils.LineAnchorCodeHtmlFormatter(
            cssclass='codehilite', linenos='table')

        # Setup Pypeline
        self.pypeline_markup = pypeline_markup

        # Setup analytics
        accounts = config.get('ga.account', 'UA-XXXXX-X')
        accounts = accounts.split(' ')
        self.analytics = analytics.GoogleAnalytics(accounts=accounts)

        self.icons = dict(
            move=Icon('fa fa-arrows', 'Move'),
            edit=Icon('fa fa-edit', 'Edit'),
            admin=Icon('fa fa-gear', 'Admin'),
            send=Icon('fa fa-send-o', 'Send'),
            add=Icon('fa fa-plus-circle', 'Add'),
            moderate=Icon('fa fa-hand-stop-o', 'Moderate'),
            pencil=Icon('fa fa-pencil', 'Edit'),
            help=Icon('fa fa-question-circle', 'Help'),
            eye=Icon('fa fa-eye', 'View'),
            search=Icon('fa fa-search', 'Search'),
            history=Icon('fa fa-calendar', 'History'),
            feed=Icon('fa fa-rss', 'Feed'),
            mail=Icon('fa fa-envelope-o', 'Subscribe'),
            reply=Icon('fa fa-reply', 'Reply'),
            tag=Icon('fa fa-tag', 'Tag'),
            flag=Icon('fa fa-flag-o', 'Flag'),
            undelete=Icon('fa fa-undo', 'Undelete'),
            delete=Icon('fa fa-trash-o', 'Delete'),
            close=Icon('fa fa-close', 'Close'),
            table=Icon('fa fa-table', 'Table'),
            stats=Icon('fa fa-line-chart', 'Stats'),
            pin=Icon('fa fa-mail-pin', 'Pin'),
            folder=Icon('fa fa-folder', 'Folder'),
            fork=Icon('fa fa-code-fork', 'Fork'),
            merge=Icon('fa fa-code-fork upside-down', 'Merge'),
            conversation=Icon('fa fa-comments', 'Conversation'),
            group=Icon('fa fa-group', 'Group'),
            user=Icon('fa fa-user', 'User'),
            secure=Icon('fa fa-lock', 'Lock'),
            unsecure=Icon('fa fa-unlock', 'Unlock'),
            star=Icon('fa fa-star', 'Star'),
            expand=Icon('fa fa-expand', 'Maximize'),
            restore=Icon('fa fa-compress', 'Restore'),
            check=Icon('fa fa-check-circle', 'Check'),
            caution=Icon('fa fa-ban', 'Caution'),
            vote_up=Icon('fa fa-plus', 'Vote Up'),
            vote_down=Icon('fa fa-minus', 'Vote Down'),
            download=Icon('fa fa-download', 'Download'),
            revert=Icon('fa fa-history', 'Revert'),
            browse_commits=Icon('fa fa-list', 'Browse Commits'),
            file=Icon('fa fa-file-o', 'File'),
            # Permissions
            perm_read=Icon('fa fa-eye', 'Read'),
            perm_update=Icon('fa fa-rotate-left', 'Update'),
            perm_create=Icon('fa fa-flash', 'Create'),
            perm_register=Icon('fa fa-gear', 'Config'),
            perm_delete=Icon('fa fa-minus-circle', 'Remove'),
            perm_tool=Icon('fa fa-gear', 'Tool'),
            perm_admin=Icon('fa fa-gear', 'Admin'),
            perm_has_yes=Icon('fa fa-check', 'Check'),
            perm_has_no=Icon('fa fa-ban', 'No entry'),
            perm_has_inherit=Icon('fa fa-check-circle', 'Has inherit'),
        )

        # Cache some loaded entry points
        def _cache_eps(section_name, dict_cls=dict):
            d = dict_cls()
            for ep in h.iter_entry_points(section_name):
                try:
                    value = ep.load()
                except Exception:
                    log.exception('Could not load entry point [%s] %s',
                                  section_name, ep)
                else:
                    d[ep.name] = value
            return d

        class entry_point_loading_dict(dict):
            def __missing__(self, key):
                self[key] = _cache_eps(key)
                return self[key]

        self.entry_points = entry_point_loading_dict(
            tool=_cache_eps('allura', dict_cls=utils.CaseInsensitiveDict),
            auth=_cache_eps('allura.auth'),
            registration=_cache_eps('allura.project_registration'),
            theme=_cache_eps('allura.theme'),
            user_prefs=_cache_eps('allura.user_prefs'),
            spam=_cache_eps('allura.spam'),
            phone=_cache_eps('allura.phone'),
            stats=_cache_eps('allura.stats'),
            site_stats=_cache_eps('allura.site_stats'),
            admin=_cache_eps('allura.admin'),
            site_admin=_cache_eps('allura.site_admin'),
            # macro eps are used solely for ensuring that external macros are
            # imported (after load, the ep itself is not used)
            macros=_cache_eps('allura.macros'),
            webhooks=_cache_eps('allura.webhooks'),
            multifactor_totp=_cache_eps('allura.multifactor.totp'),
            multifactor_recovery_code=_cache_eps(
                'allura.multifactor.recovery_code'),
        )

        # Set listeners to update stats
        statslisteners = []
        for name, ep in self.entry_points['stats'].iteritems():
            statslisteners.append(ep())
        self.statsUpdater = PostEvent(statslisteners)

        self.tmpdir = os.getenv('TMPDIR', '/tmp')