Example #1
0
def search_adapter_helper(adapter):
    settings = {'srcdir': rootdir / 'roots' / 'test-searchadapters',
                'builddir': tempdir / 'websupport',
                'status': StringIO(),
                'warning': StringIO(),
                'search': adapter}
    support = WebSupport(**settings)
    support.build()

    s = support.search

    # Test the adapters query method. A search for "Epigraph" should return
    # one result.
    results = s.query(u'Epigraph')
    assert len(results) == 1, \
        '%s search adapter returned %s search result(s), should have been 1'\
        % (adapter, len(results))

    # Make sure documents are properly updated by the search adapter.
    s.init_indexing(changed=['markup'])
    s.add_document(u'markup', u'filename', u'title', u'SomeLongRandomWord')
    s.finish_indexing()
    # Now a search for "Epigraph" should return zero results.
    results = s.query(u'Epigraph')
    assert len(results) == 0, \
        '%s search adapter returned %s search result(s), should have been 0'\
        % (adapter, len(results))
    # A search for "SomeLongRandomWord" should return one result.
    results = s.query(u'SomeLongRandomWord')
    assert len(results) == 1, \
        '%s search adapter returned %s search result(s), should have been 1'\
        % (adapter, len(results))
    # Make sure it works through the WebSupport API
    support.get_search_results(u'SomeLongRandomWord')
def build_sphinx_data(settings, quiet=True):
    sphinx_dst = settings['sphinx_build']
    if not os.path.exists(sphinx_dst):
        os.makedirs(sphinx_dst)
    sphinx = WebSupport(srcdir=settings['sphinx_src'], builddir=sphinx_dst,
                        status=None)
    sphinx.build()
Example #3
0
def main():
    init_db()

    support = WebSupport(srcdir=app.config['SOURCE_DIR'],
                         builddir=app.config['BUILD_DIR'],
                         search=app.config['SEARCH'],
                         storage=app.config['DATABASE_URI'])
    support.build()
Example #4
0
 def support(self):
     """Return an instance of Sphinx ``WebSupport``."""
     builddir = os.path.abspath(
         os.path.join(current_app.instance_path, 'docs'))
     return WebSupport(srcdir=self.documentation_package.__path__[0],
                       builddir=builddir,
                       staticroot=os.path.join(blueprint.url_prefix,
                                               'static'),
                       docroot=blueprint.url_prefix)
Example #5
0
def test_build(request, rootdir, sphinx_test_tempdir):
    settings = {
        'srcdir': rootdir / 'test-basic',
        # to use same directory for 'builddir' in each 'support' fixture, using
        # 'sphinx_test_tempdir' (static) value instead of 'tempdir' fixture value.
        # each test expect result of db value at previous test case.
        'builddir': sphinx_test_tempdir / 'websupport'
    }
    marker = request.node.get_marker('support')
    if marker:
        settings.update(marker.kwargs)

    support = WebSupport(**settings)
    support.build()
Example #6
0
def support(request):
    settings = {
        'srcdir': rootdir / 'root',
        # to use same directory for 'builddir' in each 'support' fixture, using
        # 'tempdir' (static) value instead of 'tempdir' fixture value.
        # each test expect result of db value at previous test case.
        'builddir': tempdir / 'websupport'
    }
    marker = request.node.get_marker('support')
    if marker:
        settings.update(marker.kwargs)

    support = WebSupport(**settings)
    yield support
Example #7
0
def get_support(force=False, quiet=False):
    if not hasattr(current_app, 'docs_websupport') or force:
        builddir = get_builddir()
        # this is where files installed by setup.py's data_files go..
        srcdir = os.path.join(sys.prefix, 'relengapi-docs')
        kwargs = {}
        if quiet:
            kwargs['status'] = StringIO.StringIO()
        current_app.docs_websupport = WebSupport(srcdir=srcdir,
                                                 builddir=builddir,
                                                 staticroot='/docs/static',
                                                 docroot='/docs',
                                                 **kwargs)
    return current_app.docs_websupport
def get_support(force=False, quiet=False):
    if not hasattr(current_app, 'docs_websupport') or force:
        builddir = get_builddir()
        # this is where files installed by setup.py's data_files go..
        srcdir = pkg_resources.resource_filename('relengapi', 'docs')
        kwargs = {}
        if quiet:
            kwargs['status'] = StringIO.StringIO()
        current_app.docs_websupport = WebSupport(srcdir=srcdir,
                                                 builddir=builddir,
                                                 staticroot='/docs/static',
                                                 docroot='/docs',
                                                 storage=NullStorageBackend(),
                                                 **kwargs)
    return current_app.docs_websupport
Example #9
0
 def new_func(*args2, **kwargs2):
     support = WebSupport(**settings)
     func(support, *args2, **kwargs2)
Example #10
0
                                         DocumentCommentSerializer,
                                         DocumentNode, DocumentNodeSerializer,
                                         ModerationActionSerializer,
                                         NodeSnapshot)
from readthedocs.projects.models import Project
from readthedocs.restapi.permissions import CommentModeratorOrReadOnly

from .backend import DjangoStorage
from .session import UnsafeSessionAuthentication

storage = DjangoStorage()

support = WebSupport(
    srcdir='/Users/eric/projects/readthedocs.org/docs',
    builddir='/Users/eric/projects/readthedocs.org/docs/_build/websupport',
    datadir='/Users/eric/projects/readthedocs.org/docs/_build/websupport/data',
    storage=storage,
    docroot='websupport',
)

########
# called by javascript
########


@api_view(['GET'])
@permission_classes([permissions.IsAuthenticatedOrReadOnly])
@renderer_classes((JSONRenderer, ))
def get_options(request):  # pylint: disable=unused-argument
    base_opts = support.base_comment_opts
    base_opts['addCommentURL'] = '/api/v2/comments/'
Example #11
0
#!/usr/bin/env python2.6
# -*- coding: utf8 -*-
#### sphinx part. same as build.py

import sphinx
from sphinx.websupport import WebSupport
from sphinx.websupport.errors import DocumentNotFoundError
import serveconf
import logging
import os, sys

support = WebSupport(serveconf.SRCDIR, serveconf.BUILDDIR)

#### flask part

from flask import Flask, render_template, abort, g, request, jsonify, redirect, url_for
from jinja2 import Environment, FileSystemLoader

app = Flask(__name__)
app.debug = True  # デバッグ用フラグ
app.jinja_env = Environment(
    loader=FileSystemLoader(os.path.abspath(serveconf.TEMPLATE_DIR) + '/'),
    extensions=['jinja2.ext.i18n'])
app.root_path = serveconf.BUILDDIR


# Via bzrlib.tests
class StringIOWrapper(object):
    """A wrapper around cStringIO which just adds an encoding attribute.

	Internally we can check sys.stdout to see what the output encoding
 def __init__(self, request):
     self.request = request
     self.support = WebSupport(
         datadir=request.registry.settings['rebecca.sphinxweb.datadir'])
def make_support(args):
    support = WebSupport(srcdir=args.srcdir, builddir=args.builddir)
    return support
Example #14
0
    msg.body = NEW_COMMENT_MAIL % {
        'document': comment['document'],
        'username': comment['username'],
        'text': comment['original_text'],
        'proposal': comment['proposal_diff_text'],
        'url': moderate_url,
    }
    try:
        mail.send(msg)
    except Exception, err:
        print >> sys.stderr, 'mail not sent:', err  # for now


support = WebSupport(datadir=path.join(app.config['BUILD_DIR'], 'data'),
                     search=app.config['SEARCH'],
                     docroot='',
                     storage=app.config['DATABASE_URI'],
                     moderation_callback=moderation_callback)


@app.context_processor
def inject_globalcontext():
    """Inject "sg", the global context."""
    return dict(sg=support.get_globalcontext())


@app.before_request
def before_request():
    g.user = None
    if 'openid' in session:
        g.user = User.query.filter_by(openid=session['openid']).first()
BUILDDIR = os.path.join(ROOT, 'build', 'web')
INDEXDIR = os.path.join(BUILDDIR, "data", "db")

print("SRC:{0}, BUILD:{1}, INDEX:{2}".format(SRCDIR, BUILDDIR, INDEXDIR))

uri = os.environ.get('DATABASE_URL')  # DATABSE_URL is given
storage = SQLAlchemyStorage(uri)

whoosh = whooshsearch.WhooshSearch
whoosh.schema = Schema(path=ID(stored=True, unique=True),
                       title=TEXT(field_boost=2.0, stored=True),
                       text=NGRAM(stored=True))
search = whoosh(INDEXDIR)

support = WebSupport(srcdir=SRCDIR,
                     builddir=BUILDDIR,
                     search=search,
                     storage=storage)

#### flask part

from flask import Flask, render_template, abort, g, request, jsonify, url_for
from jinja2 import Environment, FileSystemLoader

app = Flask(__name__)

#app.debug = True #

app.jinja_env = Environment(loader=FileSystemLoader(
    os.path.join(ROOT, "_templates/")),
                            extensions=['jinja2.ext.i18n'])
Example #16
0
 def __init__(self, settings):
     self.settings = settings
     sphinx_data = settings['sphinx_data']
     SphinxDocument.__init__(self, WebSupport(datadir=sphinx_data), '')