Exemplo n.º 1
0
def build_static_site(static_site):
    static_site.state = StaticSiteState.running
    db.session.commit()
    try:
        logger.info('Building static site: %s', static_site)
        session.lang = static_site.creator.settings.get('lang')
        rh = RH()
        g.rh = rh
        g.static_site = True

        zip_file_path = create_static_site(rh, static_site.event)
        static_site.state = StaticSiteState.success
        static_site.content_type = 'application/zip'
        static_site.filename = 'offline_site_{}.zip'.format(static_site.event.id)
        with open(zip_file_path, 'rb') as f:
            static_site.save(f)
        db.session.commit()

        logger.info('Building static site successful: %s', static_site)
        g.static_site = False
        g.rh = None
        notify_static_site_success(static_site)
    except Exception:
        logger.exception('Building static site failed: %s', static_site)
        static_site.state = StaticSiteState.failed
        db.session.commit()
        raise
    finally:
        g.static_site = False
        g.rh = None
Exemplo n.º 2
0
def build_static_site(static_site):
    static_site.state = StaticSiteState.running
    db.session.commit()
    try:
        logger.info('Building static site: %s', static_site)
        session.lang = static_site.creator.settings.get('lang')
        rh = RH()
        rh._conf = rh._target = static_site.event.as_legacy

        g.rh = rh
        g.static_site = True

        zip_file_path = OfflineEvent(rh, rh._conf).create()
        static_site.state = StaticSiteState.success
        static_site.content_type = 'application/zip'
        static_site.filename = 'offline_site_{}.zip'.format(
            static_site.event.id)
        with open(zip_file_path, 'rb') as f:
            static_site.save(f)
        db.session.commit()

        logger.info('Building static site successful: %s', static_site)
        g.static_site = False
        g.rh = None
        notify_static_site_success(static_site)
    except Exception:
        logger.exception('Building static site failed: %s', static_site)
        static_site.state = StaticSiteState.failed
        db.session.commit()
        raise
    finally:
        g.static_site = False
        g.rh = None
Exemplo n.º 3
0
def build_static_site(static_site):
    static_site.state = StaticSiteState.running
    db.session.commit()
    try:
        logger.info('Building static site: {}'.format(static_site))
        session.lang = static_site.creator.settings.get('lang')
        rh = RHCustomizable()
        rh._aw = AccessWrapper()
        rh._conf = rh._target = static_site.event

        ContextManager.set('currentRH', rh)
        ContextManager.set('offlineMode', True)

        # Get event type
        wf = rh.getWebFactory()
        event_type = wf.getId() if wf else 'conference'

        zip_file_path = OfflineEvent(rh, rh._conf, event_type).create(static_site.id)

        static_site.path = zip_file_path
        static_site.state = StaticSiteState.success
        db.session.commit()

        logger.info('Building static site successful: {}'.format(static_site))
        ContextManager.set('offlineMode', False)
        ContextManager.set('currentRH', None)
        notify_static_site_success(static_site)
    except Exception:
        logger.exception('Building static site failed: {}'.format(static_site))
        static_site.state = StaticSiteState.failed
        db.session.commit()
        raise
    finally:
        ContextManager.set('offlineMode', False)
        ContextManager.set('currentRH', None)
Exemplo n.º 4
0
def static_sites_cleanup(days=30):
    """Clean up old static sites

    :param days: number of days after which to remove static sites
    """
    expired_sites = StaticSite.find_all(StaticSite.requested_dt < (now_utc() - timedelta(days=days)),
                                        StaticSite.state == StaticSiteState.success)
    logger.info('Removing %d expired static sites from the past %d days', len(expired_sites), days)
    try:
        for site in expired_sites:
            site.delete_file()
            site.path = None
            site.state = StaticSiteState.expired
            logger.info('Removed static site %s', site)
    finally:
        db.session.commit()
Exemplo n.º 5
0
def static_sites_cleanup(days=30):
    """Clean up old static sites

    :param days: number of days after which to remove static sites
    """
    expired_sites = StaticSite.find_all(StaticSite.requested_dt < (now_utc() - timedelta(days=days)),
                                        StaticSite.state == StaticSiteState.success)
    logger.info('Removing %d expired static sites from the past %d days', len(expired_sites), days)
    try:
        for site in expired_sites:
            try:
                site.delete()
            except StorageReadOnlyError:
                # If a site is on read-only storage we simply keep it alive.
                logger.debug('Could not delete static site %r (read-only storage)', site)
            else:
                site.state = StaticSiteState.expired
                logger.info('Removed static site %r', site)
    finally:
        db.session.commit()
Exemplo n.º 6
0
def build_static_site(static_site):
    static_site.state = StaticSiteState.running
    db.session.commit()
    try:
        logger.info('Building static site: %s', static_site)
        session.lang = static_site.creator.settings.get('lang')
        rh = RH()

        zip_file_path = create_static_site(rh, static_site.event)
        static_site.state = StaticSiteState.success
        static_site.content_type = 'application/zip'
        static_site.filename = 'offline_site_{}.zip'.format(static_site.event.id)
        with open(zip_file_path, 'rb') as f:
            static_site.save(f)
        db.session.commit()

        logger.info('Building static site successful: %s', static_site)
        notify_static_site_success(static_site)
    except Exception:
        logger.exception('Building static site failed: %s', static_site)
        static_site.state = StaticSiteState.failed
        db.session.commit()
        raise
Exemplo n.º 7
0
def build_static_site(static_site):
    static_site.state = StaticSiteState.running
    db.session.commit()
    try:
        logger.info('Building static site: %s', static_site)
        session.lang = static_site.creator.settings.get('lang')
        rh = RHCustomizable()
        rh._aw = AccessWrapper()
        rh._conf = rh._target = static_site.event_new.as_legacy

        g.rh = rh
        ContextManager.set('currentRH', rh)
        g.static_site = True

        # Get event type
        wf = rh.getWebFactory()
        event_type = wf.getId() if wf else 'conference'

        zip_file_path = OfflineEvent(rh, rh._conf,
                                     event_type).create(static_site.id)

        static_site.path = zip_file_path
        static_site.state = StaticSiteState.success
        db.session.commit()

        logger.info('Building static site successful: %s', static_site)
        g.static_site = False
        ContextManager.set('currentRH', None)
        notify_static_site_success(static_site)
    except Exception:
        logger.exception('Building static site failed: %s', static_site)
        static_site.state = StaticSiteState.failed
        db.session.commit()
        raise
    finally:
        g.static_site = False
        ContextManager.set('currentRH', None)