Exemple #1
0
def start_logging():
    global logfocus, file_handler
    from lmfdb.utils.config import Configuration
    config = Configuration()
    logging_options = config.get_logging()

    file_handler = FileHandler(logging_options['logfile'])
    file_handler.setLevel(WARNING)

    if 'logfocus' in logging_options:
        logfocus = logging_options['logfocus']
        getLogger(logfocus).setLevel(DEBUG)

    root_logger = getLogger()
    root_logger.setLevel(INFO)
    root_logger.name = "LMFDB"

    formatter = Formatter(LmfdbFormatter.fmtString.split(r'[')[0])
    ch = StreamHandler()
    ch.setFormatter(formatter)
    root_logger.addHandler(ch)

    cfg = config.get_all()
    if "postgresql_options" and "password" in cfg["postgresql_options"]:
        cfg["postgresql_options"]["password"] = "******"
    info("Configuration = {}".format(cfg) )
    check_sage_version()
Exemple #2
0
def start_logging():
    global logfocus, file_handler
    from lmfdb.utils.config import Configuration
    config = Configuration()
    logging_options = config.get_logging()

    file_handler = FileHandler(logging_options['logfile'])
    file_handler.setLevel(WARNING)

    if 'logfocus' in logging_options:
        logfocus = logging_options['logfocus']
        getLogger(logfocus).setLevel(DEBUG)

    root_logger = getLogger()
    root_logger.setLevel(INFO)
    root_logger.name = "LMFDB"

    formatter = Formatter(LmfdbFormatter.fmtString.split(r'[')[0])
    ch = StreamHandler()
    ch.setFormatter(formatter)
    root_logger.addHandler(ch)

    cfg = config.get_all()
    if "postgresql_options" and "password" in cfg["postgresql_options"]:
        cfg["postgresql_options"]["password"] = "******"
    info("Configuration = {}".format(cfg))
    check_sage_version()
Exemple #3
0
def main():
    info("main: ...done.")
    from lmfdb.utils.config import Configuration

    flask_options = Configuration().get_flask()

    if "profiler" in flask_options and flask_options["profiler"]:
        info("Profiling!")
        from werkzeug.contrib.profiler import ProfilerMiddleware

        app.wsgi_app = ProfilerMiddleware(app.wsgi_app,
                                          restrictions=[30],
                                          sort_by=("cumulative", "time",
                                                   "calls"))
        del flask_options["profiler"]

    if "COCALC_PROJECT_ID" in os.environ:
        from lmfdb.utils.cocalcwrap import CocalcWrap
        # we must accept external connections
        flask_options["host"] = "0.0.0.0"
        app.wsgi_app = CocalcWrap(app.wsgi_app)
        stars = "\n" + "*" * 80
        info(stars + "\n\033[1mCocalc\033[0m environment detected!\n" +
             "Visit" + "\n  \033[1m https://cocalc.com" +
             app.wsgi_app.app_root + " \033[0m" +
             "\nto access this LMFDB instance" + stars)

    set_running()
    app.run(**flask_options)
Exemple #4
0
def add_colors():
    # FIXME:
    # - the template should use global variable g.color
    # - try to get the color from
    #       - the cookie
    #       - from the config file
    # - remove cookie at logout (see line 307 of users/main)
    # - add cookie at login or when a color change happens (see line 175 of users/main)
    from lmfdb.utils.color import all_color_schemes
    color = request.args.get('color')
    if color and color.isdigit():
        color = int(color)
    if color not in all_color_schemes:
        color = None
    if color is None:
        from flask_login import current_user
        userid = current_user.get_id()
        if userid is not None:
            from lmfdb.users.pwdmanager import userdb
            color = userdb.lookup(userid).get('color_scheme')
        if color not in all_color_schemes:
            color = None
        if color is None:
            from lmfdb.utils.config import Configuration
            color = Configuration().get_color()
    return dict(color=all_color_schemes[color].dict())
Exemple #5
0
def knowl_url_prefix():
    """
    why is this function needed?
    if you're running lmfdb in cocalc, front-end javascript (see: lmfdb.js) doesn't know your prefix isn't just a website domain.
    """
    flask_options = Configuration().get_flask()
    if "COCALC_PROJECT_ID" in os.environ:
        return 'https://cocalc.com/' + os.environ['COCALC_PROJECT_ID'] + "/server/" + str(flask_options['port'])
    else:
        return ""
Exemple #6
0
def main():
    info("main: ...done.")
    from lmfdb.utils.config import Configuration
    flask_options = Configuration().get_flask()

    if "profiler" in flask_options and flask_options["profiler"]:
        print "Profiling!"
        from werkzeug.contrib.profiler import ProfilerMiddleware
        app.wsgi_app = ProfilerMiddleware(app.wsgi_app,
                                          restrictions=[30],
                                          sort_by=('cumulative', 'time',
                                                   'calls'))
        del flask_options["profiler"]

    lmfdb.app.set_running()
    app.run(**flask_options)
Exemple #7
0
    def __init__(self, loggername, db):
        # Have to record this object in the db so that we can reset the connection if necessary.
        # This function also sets self.conn
        db.register_object(self)
        self._db = db
        from lmfdb.utils.config import Configuration

        logging_options = Configuration().get_logging()
        self.slow_cutoff = logging_options["slowcutoff"]
        handler = logging.FileHandler(logging_options["slowlogfile"])
        formatter = logging.Formatter("%(asctime)s - %(message)s")
        filt = QueryLogFilter()
        handler.setFormatter(formatter)
        handler.addFilter(filt)
        self.logger = make_logger(loggername,
                                  hl=False,
                                  extraHandlers=[handler])
Exemple #8
0
def main():
    info("main: ...done.")
    from lmfdb.utils.config import Configuration

    flask_options = Configuration().get_flask()

    if "profiler" in flask_options and flask_options["profiler"]:
        info("Profiling!")
        from werkzeug.middleware.profiler import ProfilerMiddleware

        app.wsgi_app = ProfilerMiddleware(app.wsgi_app,
                                          restrictions=[30],
                                          sort_by=("cumulative", "time",
                                                   "calls"))
        del flask_options["profiler"]
    #/from werkzeug.middleware.profiler import ProfilerMiddleware
    #/app.wsgi_app = ProfilerMiddleware(
    #/    app.wsgi_app, restrictions=[30], sort_by=("cumulative", "time", "calls")
    #/    )

    set_running()
    app.run(**flask_options)
Exemple #9
0
 def __init__(self, **kwargs):
     # This will write the default configuration file if needed
     config = Configuration()
     PostgresDatabase.__init__(self, config, **kwargs)
     self.is_verifying = False  # set to true when importing lmfdb.verify
     self.__editor = config.logging_options["editor"]
Exemple #10
0
from __future__ import absolute_import

__version__ = "0.1"

import os
import sys

sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../lmfdb"))

# from .website import main
# assert main
from lmfdb.backend.database import PostgresDatabase
import __main__
startQ =  getattr(__main__, '__file__').endswith("start-seminars.py") if hasattr(__main__, '__file__') else False
from lmfdb.utils.config import Configuration
db = PostgresDatabase(config=Configuration(writeargstofile=startQ, readargs=startQ))
from lmfdb.backend.searchtable import PostgresSearchTable

# Have to make sure that changes aren't logged using the LMFDB's logging mechanism.
def nothing(self, *args, **kwds):
    pass


def are_you_REALLY_sure(func):
    def call(*args, **kwargs):
        ok = input(
            "Are you REALLY sure you want to do call %s?\nYou will most likely break the website if you don't change the code first!! (yes/no)"
            % (func)
        )
        if not (ok and ok.lower() == "yes"):
            return