Пример #1
0
    def run(self):
        # Import it here to avoid circular import
        from indico.web.flask.app import make_app
        self._app = make_app(True)

        self._prepare()
        self._logger.info('Running task {}.. (delay: {})'.format(self._task.id, self._executionDelay))

        try:
            for i, retry in enumerate(transaction.attempts(self._config.task_max_tries)):
                with retry:
                    self._logger.info('Task attempt #{}'.format(i))
                    if i > 0:
                        self._prepare_retry()
                    try:
                        self._process_task()
                        break
                    except ConflictError:
                        transaction.abort()
                    except ClientDisconnected:
                        self._logger.warning("Retrying for the {}th time in {} secs..".format(i + 1, i * 10))
                        transaction.abort()
                        time.sleep(i * 10)
                    except TaskDelayed, e:
                        self._logger.info("{} delayed by {} seconds".format(self._task, e.delaySeconds))
                        self._delayed = True
                        self._executionDelay = 0
                        time.sleep(e.delaySeconds)
            flush_after_commit_queue(True)
            GenericMailer.flushQueue(True)
Пример #2
0
    def run(self):
        # Import it here to avoid circular import
        from indico.web.flask.app import make_app
        self._app = make_app(True)

        self._prepare()
        self._logger.info('Running task {}.. (delay: {})'.format(
            self._task.id, self._executionDelay))

        try:
            for i, retry in enumerate(
                    transaction.attempts(self._config.task_max_tries)):
                with retry:
                    self._logger.info('Task attempt #{}'.format(i))
                    if i > 0:
                        self._prepare_retry()
                    try:
                        self._process_task()
                        break
                    except ConflictError:
                        transaction.abort()
                    except ClientDisconnected:
                        self._logger.warning(
                            "Retrying for the {}th time in {} secs..".format(
                                i + 1, i * 10))
                        transaction.abort()
                        time.sleep(i * 10)
                    except TaskDelayed, e:
                        self._logger.info("{} delayed by {} seconds".format(
                            self._task, e.delaySeconds))
                        self._delayed = True
                        self._executionDelay = 0
                        time.sleep(e.delaySeconds)
            flush_after_commit_queue(True)
            GenericMailer.flushQueue(True)
Пример #3
0
 def _action_make_app_request_context(self, config):
     # XXX: Check if this breaks SA tests. If yes, use an argument for db_setup
     app = make_app(db_setup=False)
     if config:
         for k, v in config.iteritems():
             app.config[k] = v
     env = {'environ_base': {'REMOTE_ADDR': '127.0.0.1'}}
     return app.test_request_context(**env)
Пример #4
0
 def _action_make_app_request_context(self):
     app = make_app()
     env = {
         'environ_base': {
             'REMOTE_ADDR': '127.0.0.1'
         }
     }
     return app.test_request_context(**env)
Пример #5
0
def get_rules(plugins):
    from indico.web.flask.app import make_app
    app = make_app(testing=True,
                   config_override={
                       'BASE_URL': 'http://localhost/',
                       'SECRET_KEY': '*' * 16,
                       'PLUGINS': plugins
                   })
    return dump_url_map(app.url_map)
Пример #6
0
def get_rules():
    from indico.web.flask.app import make_app
    app = make_app(set_path=True,
                   testing=True,
                   config_override={
                       'BASE_URL': 'http://localhost/',
                       'SECRET_KEY': '*' * 16
                   })
    return dump_url_map(app.url_map)
Пример #7
0
 def _action_make_app_request_context(self, config):
     app = make_app()
     if config:
         for k, v in config.iteritems():
             app.config[k] = v
     env = {
         'environ_base': {
             'REMOTE_ADDR': '127.0.0.1'
         }
     }
     return app.test_request_context(**env)
Пример #8
0
    def __init__(self, taskId, configData, delay):
        super(_Worker, self).__init__()

        self._logger = logging.getLogger('worker/%s' % taskId)
        self._taskId = taskId
        self._config = configData
        self._executionDelay = delay

        # Import it here to avoid circular import
        from indico.web.flask.app import make_app
        self._app = make_app(True)
Пример #9
0
    def __init__(self, taskId, configData, delay):
        super(_Worker, self).__init__()

        self._logger = logging.getLogger('worker/%s' % taskId)
        self._taskId = taskId
        self._config = configData
        self._executionDelay = delay

        # Import it here to avoid circular import
        from indico.web.flask.app import make_app
        self._app = make_app(True)
Пример #10
0
 def _action_make_app_request_context(self, config):
     # XXX: Check if this breaks SA tests. If yes, use an argument for db_setup
     app = make_app(db_setup=False)
     if config:
         for k, v in config.iteritems():
             app.config[k] = v
     env = {
         'environ_base': {
             'REMOTE_ADDR': '127.0.0.1'
         }
     }
     return app.test_request_context(**env)
Пример #11
0
    def _runFakeWebServer(self):
        """
        Spawn a new refserver-based thread using the test db
        """
        config = TestConfig.getInstance()
        server = WerkzeugServer(make_app(), config.getWebServerHost(), int(config.getWebServerPort()),
                                use_debugger=False)
        server.make_server()

        t = threading.Thread(target=server.run)
        t.setDaemon(True)
        t.start()
        return server.addr
Пример #12
0
def app(request):
    """Create the flask app."""
    config_override = {
        'BASE_URL': 'http://localhost',
        'SMTP_SERVER': ('localhost', 0),  # invalid port - just in case so we NEVER send emails!
        'TEMP_DIR': request.config.indico_temp_dir.strpath,
        'CACHE_DIR': request.config.indico_temp_dir.strpath,
        'STORAGE_BACKENDS': {'default': 'mem:'},
        'PLUGINS': request.config.indico_plugins,
        'ENABLE_ROOMBOOKING': True,
        'SECRET_KEY': os.urandom(16),
        'SMTP_USE_CELERY': False,
    }
    return make_app(set_path=True, testing=True, config_override=config_override)
Пример #13
0
def app(request):
    """Creates the flask app"""
    config_override = {
        'BASE_URL': 'http://localhost',
        'SMTP_SERVER': ('localhost', 0),  # invalid port - just in case so we NEVER send emails!
        'CACHE_BACKEND': 'null',
        'TEMP_DIR': request.config.indico_temp_dir.strpath,
        'CACHE_DIR': request.config.indico_temp_dir.strpath,
        'STORAGE_BACKENDS': {'default': 'mem:'},
        'PLUGINS': request.config.indico_plugins,
        'ENABLE_ROOMBOOKING': True,
        'SECRET_KEY': os.urandom(16)
    }
    return make_app(set_path=True, testing=True, config_override=config_override)
Пример #14
0
    def _runFakeWebServer(self):
        """
        Spawn a new refserver-based thread using the test db
        """
        config = TestConfig.getInstance()
        server = WerkzeugServer(make_app(),
                                config.getWebServerHost(),
                                int(config.getWebServerPort()),
                                use_debugger=False)
        server.make_server()

        t = threading.Thread(target=server.run)
        t.setDaemon(True)
        t.start()
        return server.addr
Пример #15
0
def main():
    """
    Main program cycle
    """

    print console.colored("""\nThis script will migrate your Indico DB to a new version. We recommend that
this operation be executed while the web server is down, in order to avoid
concurrency problems and DB conflicts.\n\n""", 'yellow')

    parser = argparse.ArgumentParser(description='Execute migration')
    parser.add_argument('--dry-run', '-n', dest='dry_run', action='store_true',
                        help='Only show which migration tasks would be executed')
    parser.add_argument('--run-only', dest='specified', default='',
                        help='Specify which step(s) to run (comma-separated)')
    parser.add_argument('--run-from', dest='run_from', default='',
                        help='Specify FROM which step to run (inclusive)')
    parser.add_argument('--prev-version', dest='prevVersion', help='Previous version of Indico (used by DB)', default=__version__)
    parser.add_argument('--profile', dest='profile', help='Use profiling during the migration', action='store_true')

    args = parser.parse_args()

    if args.dry_run or console.yesno("Are you sure you want to execute the migration now?"):
        try:
            if args.profile:
                import profile, random, os
                proffilename = os.path.join(Config.getInstance().getTempDir(), "migration%s.prof" % str(random.random()))
                result = None
                profile.runctx("""result=runMigration(
                                  prevVersion=parse_version(args.prevVersion),
                                  specified=filter(lambda x: x, map(lambda x: x.strip(), args.specified.split(','))),
                                  run_from=args.run_from,
                                  dry_run=args.dry_run)""",
                                  globals(), locals(), proffilename)
                return result
            else:
                with make_app().app_context():
                    return runMigration(prevVersion=parse_version(args.prevVersion),
                                        specified=filter(None, map(str.strip, args.specified.split(','))),
                                        run_from=args.run_from,
                                        dry_run=args.dry_run)
        except ControlledExit:
            return 1
        except (Exception, SystemExit, KeyboardInterrupt):
            print console.colored("\nMigration failed! DB may be in an inconsistent state:", 'red', attrs=['bold'])
            print console.colored(traceback.format_exc(), 'red')
            return -1
    else:
        return 1
Пример #16
0
def main():
    """
    Main program cycle
    """

    print console.colored("""\nThis script will migrate your Indico DB to a new version. We recommend that
this operation be executed while the web server is down, in order to avoid
concurrency problems and DB conflicts.\n\n""", 'yellow')

    parser = argparse.ArgumentParser(description='Execute migration')
    parser.add_argument('--dry-run', '-n', dest='dry_run', action='store_true',
                        help='Only show which migration tasks would be executed')
    parser.add_argument('--run-only', dest='specified', default='',
                        help='Specify which step(s) to run (comma-separated)')
    parser.add_argument('--run-from', dest='run_from', default='',
                        help='Specify FROM which step to run (inclusive)')
    parser.add_argument('--prev-version', dest='prevVersion', help='Previous version of Indico (used by DB)', default=__version__)
    parser.add_argument('--profile', dest='profile', help='Use profiling during the migration', action='store_true')

    args = parser.parse_args()

    if args.dry_run or console.yesno("Are you sure you want to execute the migration now?"):
        try:
            if args.profile:
                import profile, random, os
                proffilename = os.path.join(Config.getInstance().getTempDir(), "migration%s.prof" % str(random.random()))
                result = None
                profile.runctx("""result=runMigration(
                                  prevVersion=parse_version(args.prevVersion),
                                  specified=filter(lambda x: x, map(lambda x: x.strip(), args.specified.split(','))),
                                  run_from=args.run_from,
                                  dry_run=args.dry_run)""",
                                  globals(), locals(), proffilename)
                return result
            else:
                with make_app().app_context():
                    return runMigration(prevVersion=parse_version(args.prevVersion),
                                        specified=filter(None, map(str.strip, args.specified.split(','))),
                                        run_from=args.run_from,
                                        dry_run=args.dry_run)
        except ControlledExit:
            return 1
        except (Exception, SystemExit, KeyboardInterrupt):
            print console.colored("\nMigration failed! DB may be in an inconsistent state:", 'red', attrs=['bold'])
            print console.colored(traceback.format_exc(), 'red')
            return -1
    else:
        return 1
Пример #17
0
def main():
    app = make_app(set_path=True)
    migrate.init_app(app, db, os.path.join(app.root_path, '..', 'migrations'))
    manager = Manager(app, with_default_commands=False)

    manager.add_command('shell', IndicoShell())
    manager.add_command('admin', IndicoAdminManager)
    manager.add_command('db', DatabaseManager)
    manager.add_command('plugindb', PluginDatabaseManager)
    manager.add_command('runserver', IndicoDevServer())
    manager.add_command('i18n', IndicoI18nManager)
    signals.plugin.cli.send(manager)

    try:
        manager.run()
    except KeyboardInterrupt:
        print
        sys.exit(1)
Пример #18
0
def main():
    app = make_app(set_path=True)
    migrate.init_app(app, db, os.path.join(app.root_path, "..", "migrations"))
    manager = Manager(app, with_default_commands=False)

    manager.add_command("shell", IndicoShell())
    manager.add_command("admin", IndicoAdminManager)
    manager.add_command("db", DatabaseManager)
    manager.add_command("plugindb", PluginDatabaseManager)
    manager.add_command("runserver", IndicoDevServer())
    manager.add_command("i18n", IndicoI18nManager)
    manager.add_command("celery", IndicoCeleryCommand)
    signals.plugin.cli.send(manager)

    try:
        manager.run()
    except KeyboardInterrupt:
        print
        sys.exit(1)
Пример #19
0
def _run(args):
    _setup(args)

    formatter = logging.Formatter("%(asctime)s %(name)s - %(levelname)s %(filename)s:%(lineno)s: %(message)s")

    root = logging.getLogger('')
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    root.addHandler(handler)

    dbi = DBMgr.getInstance(max_disconnect_poll=40)
    dbi.startRequest()

    sm = SchedulerModule.getDBInstance()
    t = sm.getTaskById(args.taskid)

    t.plugLogger(logging.getLogger('console.run/%s' % args.taskid))

    with make_app(True).app_context():
        t.run()

    dbi.endRequest()
Пример #20
0
def _run(args):
    _setup(args)

    formatter = logging.Formatter(
        "%(asctime)s %(name)s - %(levelname)s %(filename)s:%(lineno)s: %(message)s"
    )

    root = logging.getLogger('')
    handler = logging.StreamHandler()
    handler.setFormatter(formatter)
    root.addHandler(handler)

    dbi = DBMgr.getInstance(max_disconnect_poll=40)
    dbi.startRequest()

    sm = SchedulerModule.getDBInstance()
    t = sm.getTaskById(args.taskid)

    t.plugLogger(logging.getLogger('console.run/%s' % args.taskid))

    with make_app(True).app_context():
        t.run()

    dbi.endRequest()
Пример #21
0
def app_factory():
    app = make_app()
    migrate.init_app(app, db, os.path.join(app.root_path, '..', 'migrations'))
    return app
Пример #22
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--location', '-l', action='append', dest='locations')
    args = parser.parse_args()
    with make_app().app_context():
        _main(args)
Пример #23
0
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# Indico 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 Indico; if not, see <http://www.gnu.org/licenses/>.

import MaKaC.webinterface.urlHandlers as uhs
from indico.web.flask.app import make_app
import importlib

app = make_app()

with app.test_request_context():
    mod_errors = []
    func_errors = []
    endpoint_errors = []
    for attr in dir(uhs):
        if attr[:2] != 'UH':
            continue
        uh = getattr(uhs, attr)
        if getattr(uh, '_endpoint', None) is None:
            continue
        if uh._endpoint not in app.url_map._rules_by_endpoint:
            if not uh._endpoint.startswith('legacy.'):
                endpoint_errors.append('%s references invalid endpoint %s' %
                                       (uh.__name__, uh._endpoint))
Пример #24
0
 def create_app(self):
     app = make_app(db_setup=False)
     db.init_app(app)
     return app
Пример #25
0
def main():
    parser = argparse.ArgumentParser()

    parser.add_argument('--logging', action='store',
                        help='display logging messages for specified level')

    parser.add_argument('--web-server', action='store_true',
                        help='run a standalone WSGI web server with Indico')
    parser.add_argument('--host',
                        help='use a different host than the one in indico.conf')
    parser.add_argument('--port', type=int,
                        help='use a different port than the one in indico.conf')
    parser.add_argument('--keep-base-url', action='store_true',
                        help='do not update the base url with the given host/port')

    parser.add_argument('--with-ssl', action='store_true',
                        help='enable ssl support for web server')
    parser.add_argument('--ssl-key', help='path to the ssl private key file')
    parser.add_argument('--ssl-cert', help='path to the ssl certificate file')
    parser.add_argument('--reload-on-change', action='store_true',
                        help='restart the server whenever a file changes (does not work for legacy code)')


    args, remainingArgs = parser.parse_known_args()

    if 'logging' in args and args.logging:
        setup_logging(args.logging)

    if 'web_server' in args and args.web_server:
        start_web_server(host=args.host,
                         port=args.port,
                         with_ssl=args.with_ssl,
                         keep_base_url=args.keep_base_url,
                         ssl_cert=args.ssl_cert,
                         ssl_key=args.ssl_key,
                         reload_on_change=args.reload_on_change)
    else:
        dbi = DBMgr.getInstance()
        dbi.startRequest()

        namespace = setupNamespace(dbi)

        if HAS_IPYTHON:
            if OLD_IPYTHON:
                ipshell = IPShellEmbed(remainingArgs,
                                       banner=SHELL_BANNER,
                                       exit_msg='Good luck',
                                       user_ns=namespace)
            else:
                config = IPConfig()
                config.TerminalInteractiveShell.confirm_exit = False
                ipshell = InteractiveShellEmbed(config=config,
                                                banner1=SHELL_BANNER,
                                                exit_msg='Good luck',
                                                user_ns=namespace)

            with make_app(True).app_context():
                ipshell()
        else:
            iconsole = code.InteractiveConsole(namespace)
            with make_app(True).app_context():
                iconsole.interact(SHELL_BANNER)

        dbi.abort()
        dbi.endRequest()
            if part.getContribution() is None:
                to_fix[contrib].append(('author', part))
        for part in contrib.getSpeakerList():
            if part.getContribution() is None:
                to_fix[contrib].append(('speaker', part))

    if not to_fix:
        success("No broken contribution links found.")
        return

    DBMgr.getInstance().sync()  # searching takes a long time, sync to prevent conflicts
    for contrib, parts in to_fix.iteritems():
        conference = contrib.getConference()
        conference_title = conference.getTitle() if conference is not None else 'N/A'
        conference_id = conference.getId() if conference is not None else 'N/A'
        print "Event {} (id {})".format(conference_title, conference_id)
        print "  Contribution {} (id {}):".format(contrib.getTitle(), contrib.getId())
        print "  {}".format(UHContributionDisplay.getURL(contrib))
        for part_type, part in parts:
            if part.getContribution() is not None:  # already fixed
                info("  - link already restored for {} {} (id {})".format(part_type, part.getFullName(), part.getId()))
                continue
            part._contrib = contrib
            success("  - restored link for {} {} (id {})".format(part_type, part.getFullName(), part.getId()))
    DBMgr.getInstance().commit()

if __name__ == '__main__':
    with make_app(set_path=True).app_context():
        with DBMgr.getInstance().global_connection(commit=False):
            main()
Пример #27
0
def _create_app():
    from indico.web.flask.app import make_app
    return make_app()
Пример #28
0
def get_rules(plugin):
    from indico.web.flask.app import make_app
    app = make_app(set_path=True, testing=True, config_override={'BASE_URL': 'http://localhost/',
                                                                 'SECRET_KEY': '*' * 16,
                                                                 'PLUGINS': {plugin} if plugin else set()})
    return dump_url_map(app.url_map)
Пример #29
0
def app():
    """Creates the flask app"""
    return make_app(set_path=True, testing=True)
Пример #30
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--location', '-l', action='append', dest='locations')
    args = parser.parse_args()
    with make_app().app_context():
        _main(args)
Пример #31
0
def _create_app(info):
    from indico.web.flask.app import make_app
    return make_app(set_path=True)
Пример #32
0
def main(location):
    with make_app().app_context():
        _main(location)
Пример #33
0
    if not to_fix:
        success("No broken contribution links found.")
        return

    DBMgr.getInstance().sync(
    )  # searching takes a long time, sync to prevent conflicts
    for contrib, parts in to_fix.iteritems():
        conference = contrib.getConference()
        conference_title = conference.getTitle(
        ) if conference is not None else 'N/A'
        conference_id = conference.getId() if conference is not None else 'N/A'
        print "Event {} (id {})".format(conference_title, conference_id)
        print "  Contribution {} (id {}):".format(contrib.getTitle(),
                                                  contrib.getId())
        print "  {}".format(UHContributionDisplay.getURL(contrib))
        for part_type, part in parts:
            if part.getContribution() is not None:  # already fixed
                info("  - link already restored for {} {} (id {})".format(
                    part_type, part.getFullName(), part.getId()))
                continue
            part._contrib = contrib
            success("  - restored link for {} {} (id {})".format(
                part_type, part.getFullName(), part.getId()))
    DBMgr.getInstance().commit()


if __name__ == '__main__':
    with make_app(set_path=True).app_context():
        with DBMgr.getInstance().global_connection(commit=False):
            main()
Пример #34
0
    def run(self):
        from indico.web.flask.app import make_app

        app = make_app()
        with app.test_request_context():
            self._run()
Пример #35
0
import MaKaC.webinterface.urlHandlers as uhs
from indico.web.flask.app import make_app
import importlib

app = make_app()

with app.test_request_context():
    mod_errors = []
    func_errors = []
    for attr in dir(uhs):
        if attr[:2] != 'UH':
            continue
        uh = getattr(uhs, attr)
        if getattr(uh, '_endpoint', None) is None:
            if getattr(uh, '_relativeURL', None) is None:
                pass  # print 'UH with no ep/ru: %r' % uh
            continue
        if uh._endpoint not in app.url_map._rules_by_endpoint:
            #print 'UH with invalid endpoint: %r' % uh
            try:
                assert uh._endpoint.startswith('legacy.')
            except AssertionError:
                print uh._endpoint
                raise
            ep = uh._endpoint.split('.', 1)[1]
            module_name, _, funcname = ep.partition('-')
            if not funcname:
                funcname = 'index'

            try:
                module = importlib.import_module('indico.htdocs.' + module_name)
Пример #36
0
def main(location):
    with make_app().app_context():
        _main(location)
Пример #37
0
def main():
    with make_app().app_context():
        cli(obj={})
Пример #38
0
    elif category:
        contribs = contribs.join(db.m.Event).filter(
            db.m.Event.category_chain.contains([category]))

    if log:
        log.write('<table style="width: 100%;">')
    for contrib in contribs:
        if '<html>' in unicode(contrib.description):
            click.echo(
                click.style('[HTML DOCUMENT] ', fg='red', bold=True) +
                repr(contrib))
        else:
            migrate_description(contrib, verbose, log)

    if log:
        log.write('</table>')

    if html_log:
        log.seek(0)
        html_log.write(HTML_TPL.format(log.read()))

    if not dry_run:
        db.session.commit()


if __name__ == '__main__':
    update_session_options(db)
    with make_app().app_context():
        with DBMgr.getInstance().global_connection():
            main()
Пример #39
0
def cli():
    with make_app().app_context():
        main()
Пример #40
0
def start_web_server(host='localhost', port=0, with_ssl=False, keep_base_url=True, ssl_cert=None, ssl_key=None,
                     reload_on_change=False):
    """
    Sets up a Werkzeug-based web server based on the parameters provided
    """

    config = Config.getInstance()
    # Let Indico know that we are using the embedded server. This causes it to re-raise exceptions so they
    # end up in the Werkzeug debugger.
    config._configVars['EmbeddedWebserver'] = True
    # We obviously do not have X-Sendfile or X-Accel-Redirect support in the embedded server
    config._configVars['StaticFileMethod'] = None

    # Get appropriate base url and defaults
    base_url = config.getBaseSecureURL() if with_ssl else config.getBaseURL()
    if not base_url:
        base_url = config.getBaseURL() or 'http://localhost'
        if with_ssl:
            port = 443
        console.warning(' * You should set {0}; retrieving host information from {1}'.format(
            'BaseSecureURL' if with_ssl else 'BaseURL',
            base_url))
    default_port = 443 if with_ssl else 80
    url_data = urlparse.urlparse(base_url)

    # commandline data has priority, fallback to data from base url (or default in case of port)
    host = host or url_data.netloc.partition(':')[0]
    requested_port = used_port = port or url_data.port or default_port

    # Don't let people bind on a port they cannot use.
    if used_port < 1024 and not _can_bind_port(used_port):
        used_port += 8000
        console.warning(' * You cannot open a socket on port {0}, using {1} instead.'.format(requested_port, used_port))

    # By default we update the base URL with the actual host/port. The user has the option to
    # disable this though in case he wants different values, e.g. to use iptables to make his
    # development server available via port 443 while listening on a non-privileged port:
    # iptables -t nat -A PREROUTING -d YOURIP/32 -p tcp -m tcp --dport 443 -j REDIRECT --to-port 8443
    if not keep_base_url:
        scheme = 'https' if with_ssl else 'http'
        netloc = host
        if used_port != default_port:
            netloc += ':%d' % used_port
        base_url = '{0}://{1}{2}'.format(scheme, netloc, url_data.path)
    # However, if we had to change the port to avoid a permission issue we always rewrite BaseURL.
    # In this case it is somewhat safe to assume that the user is not actually trying to use the iptables hack
    # mentioned above but simply did not consider using a non-privileged port.
    elif requested_port != used_port:
        netloc = '{0}:{1}'.format(url_data.netloc.partition(':')[0], used_port)
        base_url = '{0}://{1}{2}'.format(url_data.scheme, netloc, url_data.path)

    # If we need to perform internal requests for some reason we want to use the true host:port
    server_netloc = '{0}:{1}'.format(host, port) if port != default_port else host
    config._configVars['EmbeddedWebserverBaseURL'] = urlparse.urlunsplit(
        urlparse.urlsplit(base_url)._replace(netloc=server_netloc))

    # We update both BaseURL and BaseSecureURL to something that actually works.
    # In case of SSL-only we need both URLs to be set to the same SSL url to prevent some stuff being "loaded"
    # from an URL that is not available.
    # In case of not using SSL we clear the BaseSecureURL so the user does not need to update the config during
    # development if he needs to disable SSL for some reason.
    if with_ssl:
        config._configVars['BaseURL'] = base_url
        config._configVars['BaseSecureURL'] = base_url
    else:
        config._configVars['BaseURL'] = base_url
        config._configVars['BaseSecureURL'] = ''
    config._deriveOptions()
    # Regenerate JSVars to account for the updated URLs
    RHGetVarsJs.removeTmpVarsFile()

    console.info(' * Using BaseURL {0}'.format(base_url))
    app = make_indico_dispatcher(make_app())
    server = WerkzeugServer(app, host, used_port, reload_on_change=reload_on_change,
                            enable_ssl=with_ssl, ssl_cert=ssl_cert, ssl_key=ssl_key)
    signal.signal(signal.SIGINT, _sigint)
    server.run()
Пример #41
0
def _create_app(info):
    from indico.web.flask.app import make_app
    return make_app(set_path=True)
Пример #42
0
    if event:
        contribs = contribs.filter(db.m.Contribution.event_id == event)
    elif category:
        contribs = contribs.join(db.m.Event).filter(db.m.Event.category_chain_overlaps(category))

    if log:
        log.write('<table style="width: 100%;">')
    for contrib in contribs:
        if '<html>' in unicode(contrib.description):
            click.echo(click.style('[HTML DOCUMENT] ', fg='red', bold=True) + repr(contrib))
        else:
            migrate_description(contrib, verbose, log)

    if log:
        log.write('</table>')

    if html_log:
        log.seek(0)
        html_log.write(HTML_TPL.format(log.read()))

    if not dry_run:
        db.session.commit()


if __name__ == '__main__':
    update_session_options(db)
    with make_app().app_context():
        with DBMgr.getInstance().global_connection():
            main()
Пример #43
0
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    </head>

    <body>

    <h1>Indico offline mirror</h1>
    <h2>%s</h2>

    <ul>
    %s
    </ul>

    <small>Last update: %s</small>

    </body>
    </html>

    """ % (fDayDate, fDayDate, ''.join(liItems),  fLastUpdateDate)

    f = open(os.path.join(dest, 'index.html'), 'w')
    f.write(html)
    f.close()

    print "done!"

if __name__ == '__main__':
    appplication = make_app(True)
    with appplication.app_context():
        main()
Пример #44
0
def cli():
    with make_app().app_context():
        main()
Пример #45
0
def main(quiet=False):
    keep_inactive = len(sys.argv) > 1 and sys.argv[1] == '--keep-inactive'
    app = make_app()

    # Rules which we need to skip because a legacy blueprint already defines them (with a redirect)
    modernized_rules = set(legacy_rule_from_endpoint(rule['endpoint'])
                           for blueprint in COMPAT_BLUEPRINTS
                           for rule in iter_blueprint_rules(blueprint))

    routes = []
    legacy_endpoints = set()
    for path in sorted(glob.iglob(os.path.join(app.config['INDICO_HTDOCS'], '*.py'))):
        name = os.path.basename(path)
        module_globals = {}
        execfile(path, module_globals)
        functions = filter(lambda x: isinstance(x[1], types.FunctionType), module_globals.iteritems())
        for func_name, func in functions:
            w = Walker(func_name)
            w.visit(ast.parse(inspect.getsource(func)))
            module_name = module_globals[w.data['global']].__name__
            rh = getattr(module_globals[w.data['global']], w.data['rh_name'])
            base_url = '/' + name
            if func_name == 'index':
                rule = base_url
                endpoint = re.sub(r'\.py$', '', name)
            else:
                rule = base_url + '/' + func_name
                endpoint = '{0}-{1}'.format(re.sub(r'\.py$', '', name), func_name)
            inactive = rule in modernized_rules
            legacy_endpoints.add(endpoint)
            if inactive:
                if not quiet:
                    print 'Skipping rule (found in compat blueprint): ' + rule
                if not keep_inactive:
                    continue
            routes.append({
                'rule': rule,
                'endpoint': endpoint,
                'pyfile': name,
                'module': module_name,
                'module_alias': 'mod_rh_' + module_name.split('.')[-1],
                'rh': rh.__name__,
                'inactive': inactive
            })

    if not routes:
        print 'No rules, aborting'
        sys.exit(1)

    with open('indico/web/flask/blueprints/legacy.py', 'w') as f:
        f.write(textwrap.dedent('''
            # -*- coding: utf-8 -*-
            ##
            ##
            ## This file is part of Indico.
            ## Copyright (C) 2002 - 2013 European Organization for Nuclear Research (CERN).
            ##
            ## Indico is free software; you can redistribute it and/or
            ## modify it under the terms of the GNU General Public License as
            ## published by the Free Software Foundation; either version 3 of the
            ## License, or (at your option) any later version.
            ##
            ## Indico 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 Indico. If not, see <http://www.gnu.org/licenses/>.

            from indico.web.flask.wrappers import IndicoBlueprint
        ''').lstrip('\n'))
        f.write('\n')
        f.writelines(line + '\n' for line in generate_imports(routes))
        f.write('\n')
        f.write(textwrap.dedent('''
            legacy = IndicoBlueprint('legacy', __name__)
        '''))
        f.write('\n\n')
        f.writelines(line + '\n' for line in generate_routes(routes))
        f.write('\n\n')
        f.write('# Legacy endpoints defined in htdocs/*.py files (which need compatibility routes)\n')
        f.write('legacy_endpoints = set([')
        f.write('\n')
        f.write('\n'.join(generate_list_lines(sorted(legacy_endpoints, key=str.lower), indent='    ')))
        f.write('\n')
        f.write('])\n')