Beispiel #1
0
    def migrate(self):
        print cformat('%{white!}migrating static sites')
        for item in committing_iterator(chain.from_iterable(
                                        self.zodb_root['modules']['offlineEvents']._idxConf.itervalues())):

            event_id = item.conference.id
            if is_legacy_id(event_id):
                print cformat('%{red!}!!!%{reset} '
                              '%{white!}{0:6s}%{reset} %{yellow!}Event has non-numeric/broken ID').format(event_id)
                continue

            if event_id not in self.zodb_root['conferences']:
                print cformat('%{red!}!!!%{reset} '
                              '%{white!}{0:6s}%{reset} %{yellow!}Event deleted, skipping static site').format(event_id)
                continue

            event_id = int(event_id)
            user = self._get_user(item.avatar.id)
            state = STATE_MAPPING[item.status]
            requested_dt = item.requestTime
            file_name, file_path = self._get_file_data(item.file)

            if file_path is None and state == StaticSiteState.success:
                print cformat('%{yellow!}!!!%{reset} %{white!}{0:6d}%{reset} '
                              '%{yellow!}file missing, marking static site as expired.').format(event_id)
                state = StaticSite.expired

            static_site = StaticSite(creator=user, event_id=event_id, state=state, requested_dt=requested_dt)
            if static_site.state == StaticSiteState.success:
                static_site.path = file_path
            db.session.add(static_site)

            print cformat('%{green}+++%{reset} %{white!}{0.event_id:6d}%{reset} '
                          '%{cyan}{0}%{reset}').format(static_site)
Beispiel #2
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()
Beispiel #3
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()
Beispiel #4
0
 def _process_args(self):
     RHStaticSiteBase._process_args(self)
     self.static_site = StaticSite.get_one(request.view_args['id'])
Beispiel #5
0
def _merge_users(target, source, **kwargs):
    StaticSite.find(creator_id=source.id).update({StaticSite.creator_id: target.id})
Beispiel #6
0
def _event_deleted(event, **kwargs):
    for static_site in StaticSite.find(event_id=int(event.id)):
        db.session.delete(static_site)
Beispiel #7
0
 def _process(self):
     static_site = StaticSite.get_one(request.view_args['id'])
     if static_site.state != StaticSiteState.success:
         raise NotFound()
     return send_file('static_site_{0.event_id}.zip'.format(static_site), static_site.path, 'application/zip')
Beispiel #8
0
 def _process(self):
     static_site = StaticSite(creator=session.user, event=self.event)
     db.session.add(static_site)
     db.session.commit()
     build_static_site.delay(static_site)
     return redirect(url_for('.list', self.event))
Beispiel #9
0
 def _process_args(self):
     RHStaticSiteBase._process_args(self)
     self.static_site = StaticSite.get_or_404(request.view_args['id'])
Beispiel #10
0
 def _process(self):
     if not Config.getInstance().getOfflineStore():
         raise NotFound()
     static_sites = StaticSite.find(event_id=self._conf.id).order_by(StaticSite.requested_dt.desc()).all()
     return WPStaticSites.render_template('static_sites.html', self._conf,
                                          event=self._conf, static_sites=static_sites)
Beispiel #11
0
def _merge_users(target, source, **kwargs):
    StaticSite.find(creator_id=source.id).update(
        {StaticSite.creator_id: target.id})
Beispiel #12
0
 def _checkParams(self, params):
     RHStaticSiteBase._checkParams(self, params)
     self.static_site = StaticSite.get_one(request.view_args["id"])
Beispiel #13
0
 def _checkParams(self, params):
     RHStaticSiteBase._checkParams(self, params)
     self.static_site = StaticSite.get_one(request.view_args['id'])
Beispiel #14
0
 def has_data(self):
     return bool(StaticSite.find().count())
Beispiel #15
0
def _event_deleted(event, **kwargs):
    if event.has_legacy_id:
        return
    for static_site in StaticSite.find(event_id=int(event.id)):
        db.session.delete(static_site)