Example #1
0
def load_controller_class(path_info):
    """
    Loads appropriate action controller class according to the provided
    path info. Classes selection is based on path_info prefix (e.g. / prefix
    maps to the main action controller actions.py, /fcs maps to a fcs.py
    controller etc.).

    Please note that currently there is no general automatized loading
    (i.e. all the path->class mapping is hardcoded in this function).

    arguments:
    path_info -- a string as found in environment['PATH_INFO']

    returns:
    a class matching provided path_info
    """
    if settings.get_bool('global', 'maintenance'):
        from maintenance import MaintenanceController as ControllerClass
    elif path_info.startswith('/fcs'):
        from actions.fcs import Actions as ControllerClass
    elif path_info.startswith('/user'):
        from actions.user import User as ControllerClass
    elif path_info.startswith('/subcorpus'):
        from actions.subcorpus import Subcorpus as ControllerClass
    elif path_info.startswith('/options'):
        from actions.options import Options as ControllerClass
    elif path_info.startswith('/admin'):
        from actions.admin import Admin as ControllerClass
    elif path_info.startswith('/corpora'):
        from actions.corpora import Corpora as ControllerClass
    else:
        from actions.concordance import Actions as ControllerClass
    return ControllerClass
Example #2
0
    def viewattrs(self):
        """
        attrs, refs, structs form
        """
        from collections import defaultdict

        if len(self.args.q) == 0:
            self.disabled_menu_items = (MainMenu.SAVE, MainMenu.CONCORDANCE, MainMenu.VIEW,
                                        MainMenu.FILTER, MainMenu.FREQUENCY, MainMenu.COLLOCATIONS)

        out = {}
        if self.args.maincorp:
            corp = corplib.manatee.Corpus(self.args.maincorp)
        else:
            corp = self.corp
        out['AttrList'] = [{'label': corp.get_conf(n + '.LABEL') or n, 'n': n}
                           for n in corp.get_conf('ATTRLIST').split(',')
                           if n]
        out['fixed_attr'] = 'word'
        out['attr_allpos'] = self.args.attr_allpos
        out['attr_vmode'] = self.args.attr_vmode
        availstruct = corp.get_conf('STRUCTLIST').split(',')
        structlist = set(self.args.structs.split(',')).union(
            set([x.split('.')[0] for x in self.args.structattrs]))
        out['Availstructs'] = [{'n': n,
                                'sel': 'selected' if n in structlist else '',
                                'label': corp.get_conf(n + '.LABEL')}
                               for n in availstruct if n and n != '#']

        availref = corp.get_conf('STRUCTATTRLIST').split(',')
        structattrs = defaultdict(list)
        reflist = self.args.refs.split(',') if self.args.refs else []

        def ref_is_allowed(r):
            return r and r not in (
                '#', self.get_corpus_info(self.args.corpname).get('speech_segment'))

        for item in availref:
            if ref_is_allowed(item):
                k, v = item.split('.', 1)
                structattrs[k].append(v)
        out['Availrefs'] = [dict(n='#', label=_('Token number'),
                                 sel='selected' if '#' in reflist else '')]
        for n in availref:
            if ref_is_allowed(n):
                out['Availrefs'].append(dict(n='=' + n, sel='selected' if ('=' + n) in reflist else '',
                                             label=(corp.get_conf(n + '.LABEL') or n)))

        doc = corp.get_conf('DOCSTRUCTURE')
        if doc in availstruct:
            out['Availrefs'].insert(1, dict(n=doc, label=_('Document number'),
                                            sel=(doc in reflist and 'selected' or '')))
        out['newctxsize'] = self.args.kwicleftctx[1:]
        out['structattrs'] = structattrs
        out['curr_structattrs'] = self.args.structattrs
        out['query_overview'] = self.concdesc_json().get('Desc', [])
        out['CurrentAttrs'] = self.args.attrs.split(',')
        out['use_conc_toolbar'] = settings.get_bool('global', 'use_conc_toolbar')
        return out
Example #3
0
    def viewattrs(self, _):
        """
        attrs, refs, structs form
        """
        from collections import defaultdict

        out = {}
        if self.args.maincorp:
            corp = self.cm.get_corpus(self.args.maincorp)
        else:
            corp = self.corp
        out['AttrList'] = [{
            'label': corp.get_conf(f'{n}.LABEL') or n,
            'n': n,
            'multisep': corp.get_conf(f'{n}.MULTISEP')
        } for n in corp.get_posattrs() if n]
        out['fixed_attr'] = 'word'
        out['attr_vmode'] = self.args.attr_vmode
        availstruct = corp.get_structs()
        structlist = set(self.args.structs.split(',')).union(
            set([x.split('.')[0] for x in self.args.structattrs]))
        out['Availstructs'] = [{'n': n,
                                'sel': 'selected' if n in structlist else '',
                                'label': corp.get_conf(f'{n}.LABEL')}
                               for n in availstruct if n and n != '#']
        out['base_viewattr'] = self.args.base_viewattr
        availref = corp.get_structattrs()
        reflist = self.args.refs.split(',') if self.args.refs else []
        structattrs = defaultdict(list)
        out['qs_enabled'] = self.args.qs_enabled

        def ref_is_allowed(r):
            return r and r not in (
                '#', self.get_corpus_info(self.args.corpname).speech_segment)

        for item in availref:
            if ref_is_allowed(item):
                k, v = item.split('.', 1)
                structattrs[k].append(v)
        out['Availrefs'] = [dict(n='#', label=translate('Token number'),
                                 sel='selected' if '#' in reflist else '')]
        for n in availref:
            if ref_is_allowed(n):
                out['Availrefs'].append(dict(n='=' + n, sel='selected' if ('=' + n) in reflist else '',
                                             label=(corp.get_conf(f'{n}.LABEL') or n)))

        doc = corp.get_conf('DOCSTRUCTURE')
        if doc in availstruct:
            out['Availrefs'].insert(1, dict(n=doc, label=translate('Document number'),
                                            sel=(doc in reflist and 'selected' or '')))
        out['newctxsize'] = self.args.kwicleftctx[1:]
        out['structattrs'] = structattrs
        out['curr_structattrs'] = self.args.structattrs
        out['query_overview'] = self.concdesc_json().get('Desc', [])
        out['CurrentAttrs'] = self.args.attrs.split(',')
        out['use_conc_toolbar'] = settings.get_bool('global', 'use_conc_toolbar')
        return out
Example #4
0
def smtp_factory():
    """
    Create a new SMTP instance with some predefined stuff
    :return:
    """
    username = settings.get('mailing', 'auth_username')
    password = settings.get('mailing', 'auth_password')
    port = settings.get_int('mailing', 'smtp_port', 25)
    use_tls = settings.get_bool('mailing', 'use_tls', False)
    server = smtplib.SMTP(settings.get('mailing', 'smtp_server'), port=port)
    if use_tls:
        server.starttls()
    if username and password:
        server.login(username, password)
    return server
Example #5
0
def smtp_factory():
    """
    Create a new SMTP instance with some predefined stuff
    :return:
    """
    username = settings.get('mailing', 'auth_username')
    password = settings.get('mailing', 'auth_password')
    port = settings.get_int('mailing', 'smtp_port', 25)
    use_tls = settings.get_bool('mailing', 'use_tls', False)
    server = smtplib.SMTP(settings.get('mailing', 'smtp_server'), port=port)
    if use_tls:
        server.starttls()
    if username and password:
        server.login(username, password)
    return server
Example #6
0
	def __init__(self):
		platform = os.uname()[0]
		self.invocation = [
			os_call_list[platform],
			'--loop',
			'--no-video-title-show',
			'--play-and-exit']
		if settings.get_bool('fullscreen', True):
			self.invocation.append('--fullscreen')
		self.proc = None
		self.quit = threading.Event()
		self.restart_lock = threading.Lock()
		self._harakiri = threading.Event()
		thread = threading.Thread(target=self._poll)
		thread.daemon = True
		thread.start()
Example #7
0
 def test_get_bool(self):
     self.assertEqual(settings.get_bool('global', 'visible'), True)
     self.assertEqual(settings.get_bool('global', 'invisible'), False)
     self.assertEqual(settings.get_bool('global', 'forbidden'), False)
     self.assertEqual(settings.get_bool('global', 'permitted'), True)
Example #8
0
            response.set_cookie(sessions.get_cookie_name(),
                                request.session.sid,
                                path=cookie_path)
        return response(environ, start_response)


settings.load(path=CONF_PATH)

if settings.get('global', 'manatee_path', None):
    sys.path.insert(0, settings.get('global', 'manatee_path'))

# please note that some environments may provide umask setting themselves
if settings.get('global', 'umask', None):
    os.umask(int(settings.get('global', 'umask'), 8))

if not settings.get_bool('global', 'maintenance'):
    application = KonTextWsgiApp()
else:
    application = MaintenanceWsgiApp()

robots_path = os.path.join(os.path.dirname(__file__), 'files/robots.txt')
if os.path.isfile(robots_path):
    from werkzeug.wsgi import SharedDataMiddleware
    application = SharedDataMiddleware(application,
                                       {'/robots.txt': robots_path})

if settings.is_debug_mode():
    from werkzeug.debug import DebuggedApplication
    application = DebuggedApplication(application)
    # profiling
    if settings.debug_level() == settings.DEBUG_AND_PROFILE:
Example #9
0
# dated June, 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

import abc
import logging
from typing import Dict, Optional, Tuple, Any, Union, List, Callable
import settings
if settings.get_bool('global', 'legacy_support', False):
    from legacy.concordance import upgrade_stored_record
else:
    from legacy.concordance import nop_upgrade_stored_record as upgrade_stored_record
from plugins.abstract.query_persistence.error import QueryPersistenceRecNotFound
from controller.plg import PluginCtx
from argmapping.conc import ConcFormArgs


ConcFormArgsFactory = Callable[[PluginCtx, List[str], Dict[str, Any], str], ConcFormArgs]


class AbstractQueryPersistence(abc.ABC):
    """
    Custom query_persistence plug-in implementations should inherit from this class.
Example #10
0
        if request.session.should_save:
            sessions.save(request.session)
            response.set_cookie(sessions.get_cookie_name(), request.session.sid)
        return response(environ, start_response)


settings.load(path=CONF_PATH)

if settings.get('global', 'manatee_path', None):
    sys.path.insert(0, settings.get('global', 'manatee_path'))

# please note that some environments may provide umask setting themselves
if settings.get('global', 'umask', None):
    os.umask(int(settings.get('global', 'umask'), 8))

if not settings.get_bool('global', 'maintenance'):
    application = KonTextWsgiApp()
else:
    application = MaintenanceWsgiApp()

robots_path = os.path.join(os.path.dirname(__file__), 'files/robots.txt')
if os.path.isfile(robots_path):
    from werkzeug.wsgi import SharedDataMiddleware
    application = SharedDataMiddleware(application, {
        '/robots.txt': robots_path
    })

if settings.is_debug_mode():
    from werkzeug.debug import DebuggedApplication
    application = DebuggedApplication(application)
    # profiling
Example #11
0
 def test_get_bool(self):
     self.assertEqual(settings.get_bool('global', 'visible'), True)
     self.assertEqual(settings.get_bool('global', 'invisible'), False)
     self.assertEqual(settings.get_bool('global', 'forbidden'), False)
     self.assertEqual(settings.get_bool('global', 'permitted'), True)
Example #12
0
    def viewattrs(self):
        """
        attrs, refs, structs form
        """
        from collections import defaultdict

        if len(self.args.q) == 0:
            self.disabled_menu_items = (MainMenu.SAVE, MainMenu.CONCORDANCE,
                                        MainMenu.VIEW, MainMenu.FILTER,
                                        MainMenu.FREQUENCY,
                                        MainMenu.COLLOCATIONS)

        out = {}
        if self.args.maincorp:
            corp = corplib.manatee.Corpus(self.args.maincorp)
        else:
            corp = self.corp
        out['AttrList'] = [{
            'label': corp.get_conf(n + '.LABEL') or n,
            'n': n
        } for n in corp.get_conf('ATTRLIST').split(',') if n]
        out['fixed_attr'] = 'word'
        out['attr_allpos'] = self.args.attr_allpos
        out['attr_vmode'] = self.args.attr_vmode
        availstruct = corp.get_conf('STRUCTLIST').split(',')
        structlist = set(self.args.structs.split(',')).union(
            set([x.split('.')[0] for x in self.args.structattrs]))
        out['Availstructs'] = [{
            'n': n,
            'sel': 'selected' if n in structlist else '',
            'label': corp.get_conf(n + '.LABEL')
        } for n in availstruct if n and n != '#']

        availref = corp.get_conf('STRUCTATTRLIST').split(',')
        structattrs = defaultdict(list)
        reflist = self.args.refs.split(',') if self.args.refs else []

        def ref_is_allowed(r):
            return r and r not in ('#', self.get_corpus_info(
                self.args.corpname).get('speech_segment'))

        for item in availref:
            if ref_is_allowed(item):
                k, v = item.split('.', 1)
                structattrs[k].append(v)
        out['Availrefs'] = [
            dict(n='#',
                 label=_('Token number'),
                 sel='selected' if '#' in reflist else '')
        ]
        for n in availref:
            if ref_is_allowed(n):
                out['Availrefs'].append(
                    dict(n='=' + n,
                         sel='selected' if ('=' + n) in reflist else '',
                         label=(corp.get_conf(n + '.LABEL') or n)))

        doc = corp.get_conf('DOCSTRUCTURE')
        if doc in availstruct:
            out['Availrefs'].insert(
                1,
                dict(n=doc,
                     label=_('Document number'),
                     sel=(doc in reflist and 'selected' or '')))
        out['newctxsize'] = self.args.kwicleftctx[1:]
        out['structattrs'] = structattrs
        out['curr_structattrs'] = self.args.structattrs
        out['query_overview'] = self.concdesc_json().get('Desc', [])
        out['CurrentAttrs'] = self.args.attrs.split(',')
        out['use_conc_toolbar'] = settings.get_bool('global',
                                                    'use_conc_toolbar')
        return out
Example #13
0
    if os.path.exists(path):
        try:
            os.remove(path)
        except:
            pass
    f.save(workdir, overwrite=True)
    bottle.response.set_header("Content-Type", "text/plain")
    return bottle.request.url.replace(
        "/saveas", "/fetch") + "/" + f.filename + "?filename=" + filename


# WMS shim for Himawari 8
# Landgate tile servers, round robin
FIREWATCH_SERVICE = "/mapproxy/firewatch/service"
FIREWATCH_GETCAPS = FIREWATCH_SERVICE + "?service=wms&request=getcapabilities"
FIREWATCH_HTTPS_VERIFY = settings.get_bool("FIREWATCH_HTTPS_VERIFY", True)


@bottle.route("/hi8/<target>")
def himawari8(target):
    last_updatetime = bottle.request.query.get("updatetime")
    baseUrl = bottle.request.url[0:bottle.request.url.find("/hi8")]
    key = "himawari8.{}".format(target)
    result = None
    getcaps = None
    if uwsgi.cache_exists("himawari8"):
        if uwsgi.cache_exists(key):
            result = json.loads(uwsgi.cache_get(key))
        else:
            getcaps = uwsgi.cache_get("himawari8")
    else:
Example #14
0
        os.mkdir(workdir)
    path = os.path.join(workdir, f.filename)
    if os.path.exists(path):
        try:
            os.remove(path)
        except:
            pass
    f.save(workdir, overwrite=True)
    bottle.response.set_header("Content-Type", "text/plain")
    return bottle.request.url.replace("/saveas", "/fetch") + "/" + f.filename + "?filename=" + filename

# WMS shim for Himawari 8
# Landgate tile servers, round robin
FIREWATCH_SERVICE = "/mapproxy/firewatch/service"
FIREWATCH_GETCAPS = FIREWATCH_SERVICE + "?service=wms&request=getcapabilities"
FIREWATCH_HTTPS_VERIFY = settings.get_bool("FIREWATCH_HTTPS_VERIFY", True)


@bottle.route("/hi8/<target>")
def himawari8(target):
    last_updatetime = bottle.request.query.get("updatetime")
    baseUrl = bottle.request.url[0:bottle.request.url.find("/hi8")]
    key = "himawari8.{}".format(target)
    result = None
    getcaps = None
    if uwsgi.cache_exists("himawari8"):
        if uwsgi.cache_exists(key):
            result = json.loads(uwsgi.cache_get(key))
        else:
            getcaps = uwsgi.cache_get("himawari8")
    else: