コード例 #1
0
ファイル: crawl.py プロジェクト: cmbi/whynot
#!/usr/bin/python

import sys,os,re,shutil

# Must import storage before utils
import update_settings as settings
from storage import storage
storage.uri = settings.MONGODB_URI
storage.db_name = settings.MONGODB_DB_NAME
storage.connect()

from time import time
from ftplib import FTP
from defs import CRAWLTYPE_LINE as LINE, CRAWLTYPE_FILE as FILE
from utils import (download, entries_by_pdbid, get_present_entries,
                   get_missing_entries, read_http, parse_regex, valid_path)

# Each entry has a pdbid and databank_name, this is what makes it unique.
# An entry might also have a file path (present entries) or comment (annotated entries).
# The mtime field tells when the file or comment was added. (number of seconds since january the 1st, 1970, 00:00:00)

# This function is used for file crawling:
def get_pathnames (path):

    if path.startswith ("ftp://"):

        if not path.endswith ('/'):
            path = path + '/'

        host = path.split('/')[2]
        _dir = path [7 + len(host): ]
コード例 #2
0
ファイル: crawl.py プロジェクト: cbaakman/whynot
#!/usr/bin/python

import sys, os, re, shutil

# Must import storage before utils
import update_settings as settings
from storage import storage
storage.uri = settings.MONGODB_URI
storage.db_name = settings.MONGODB_DB_NAME
storage.connect()
storage.authenticate('whynotadmin', 'waivuy8N')

from time import time
from ftplib import FTP
from defs import CRAWLTYPE_LINE as LINE, CRAWLTYPE_FILE as FILE
from utils import (download, entries_by_pdbid, get_present_entries,
                   get_missing_entries, read_http, parse_regex, valid_path)

# Each entry has a pdbid and databank_name, this is what makes it unique.
# An entry might also have a file path (present entries) or comment (annotated entries).
# The mtime field tells when the file or comment was added. (number of seconds since january the 1st, 1970, 00:00:00)


# This function is used for file crawling:
def get_pathnames(path):

    if path.startswith("ftp://"):

        if not path.endswith('/'):
            path = path + '/'
コード例 #3
0
ファイル: factory.py プロジェクト: cmbi/whynot2
def create_app(settings=None):
    _log.info("Creating app")

    app = Flask(__name__,
                static_folder='frontend/static',
                template_folder='frontend/templates')

    app.config.from_object('whynot_web.default_settings')
    if settings:
        app.config.update(settings)
    else:  # pragma: no cover
        app.config.from_envvar('WHYNOT_SETTINGS')  # pragma: no cover

    # Ignore Flask's built-in logging
    # app.logger is accessed here so Flask tries to create it
    app.logger_name = "nowhere"
    app.logger

    whynot_logger = logging.getLogger('whynot_web')

    # Only log to email during production.
    if not app.debug and not app.testing:  # pragma: no cover
        mail_handler = SMTPHandler(
            (app.config["MAIL_SERVER"], app.config["MAIL_SMTP_PORT"]),
            app.config["MAIL_FROM"], app.config["MAIL_TO"], "whynot failed")
        mail_handler.setLevel(logging.ERROR)
        whynot_logger.addHandler(mail_handler)
        mail_handler.setFormatter(
            logging.Formatter("Message type: %(levelname)s\n" +
                              "Location: %(pathname)s:%(lineno)d\n" +
                              "Module: %(module)s\n" +
                              "Function: %(funcName)s\n" +
                              "Time: %(asctime)s\n" + "Message:\n" +
                              "%(message)s"))

    # Only log to the console during development and production, but not during
    # testing.
    if app.testing:
        whynot_logger.setLevel(logging.DEBUG)
    else:
        # This is the formatter used for the Flask app.
        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        sh.setFormatter(formatter)
        whynot_logger.addHandler(sh)

        if app.debug:
            whynot_logger.setLevel(logging.DEBUG)
        else:
            whynot_logger.setLevel(logging.INFO)

    # Configure storage
    from storage import storage
    storage.uri = app.config['MONGODB_URI']
    storage.db_name = app.config['MONGODB_DB_NAME']
    storage.connect()

    # Setup the default databanks if there are none
    if storage.count('databanks', {}) == 0:
        from install import create_databanks
        storage.create_index('databanks', 'name')
        storage.create_index('entries', 'databank_name')
        storage.create_index('entries', 'pdbid')
        storage.create_index('entries', 'comment')
        databanks = create_databanks()
        storage.insert('databanks', databanks)

    # Use ProxyFix to correct URL's when redirecting.
    from whynot_web.middleware import ReverseProxied
    app.wsgi_app = ReverseProxied(app.wsgi_app)

    # Register jinja2 filters
    from whynot_web.frontend.filters import beautify_docstring
    app.jinja_env.filters['beautify_docstring'] = beautify_docstring

    # Register blueprints
    from whynot_web.frontend.dashboard.views import bp as dashboard_bp
    from whynot_web.frontend.rest.rs import bp as rs_bp
    app.register_blueprint(dashboard_bp)
    app.register_blueprint(rs_bp)

    return app
コード例 #4
0
ファイル: factory.py プロジェクト: cmbi/whynot
def create_app(settings=None):
    _log.info("Creating app")

    app = Flask(__name__, static_folder='frontend/static',
                template_folder='frontend/templates')

    app.config.from_object('whynot_web.default_settings')
    if settings:
        app.config.update(settings)
    else:  # pragma: no cover
        app.config.from_envvar('WHYNOT_SETTINGS')  # pragma: no cover

    # Ignore Flask's built-in logging
    # app.logger is accessed here so Flask tries to create it
    app.logger_name = "nowhere"
    app.logger

    whynot_logger = logging.getLogger('whynot_web')

    # Only log to email during production.
    if not app.debug and not app.testing:  # pragma: no cover
        mail_handler = SMTPHandler((app.config["MAIL_SERVER"],
                                   app.config["MAIL_SMTP_PORT"]),
                                   app.config["MAIL_FROM"],
                                   app.config["MAIL_TO"],
                                   "whynot failed")
        mail_handler.setLevel(logging.ERROR)
        whynot_logger.addHandler(mail_handler)
        mail_handler.setFormatter(
            logging.Formatter("Message type: %(levelname)s\n" +
                              "Location: %(pathname)s:%(lineno)d\n" +
                              "Module: %(module)s\n" +
                              "Function: %(funcName)s\n" +
                              "Time: %(asctime)s\n" +
                              "Message:\n" +
                              "%(message)s"))

    # Only log to the console during development and production, but not during
    # testing.
    if app.testing:
        whynot_logger.setLevel(logging.DEBUG)
    else:
        # This is the formatter used for the Flask app.
        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        sh.setFormatter(formatter)
        whynot_logger.addHandler(sh)

        if app.debug:
            whynot_logger.setLevel(logging.DEBUG)
        else:
            whynot_logger.setLevel(logging.INFO)

    # Configure storage
    from storage import storage
    storage.uri = app.config['MONGODB_URI']
    storage.db_name = app.config['MONGODB_DB_NAME']
    storage.connect()

    # Setup the default databanks if there are none
    if storage.count('databanks', {}) == 0:
        from install import create_databanks
        storage.create_index('databanks', 'name')
        storage.create_index('entries', 'databank_name')
        storage.create_index('entries', 'pdbid')
        storage.create_index('entries', 'comment')
        databanks = create_databanks()
        storage.insert('databanks', databanks)

    # Use ProxyFix to correct URL's when redirecting.
    from whynot_web.middleware import ReverseProxied
    app.wsgi_app = ReverseProxied(app.wsgi_app)

    # Register jinja2 filters
    from whynot_web.frontend.filters import beautify_docstring
    app.jinja_env.filters['beautify_docstring'] = beautify_docstring

    # Register blueprints
    from whynot_web.frontend.dashboard.views import bp as dashboard_bp
    from whynot_web.frontend.rest.rs import bp as rs_bp
    app.register_blueprint(dashboard_bp)
    app.register_blueprint(rs_bp)

    return app