示例#1
0
 def warm_app(id, short_name, featured=False):
     if id not in apps_cached:
         cached_apps.get_app(short_name)
         cached_apps.n_tasks(id)
         n_task_runs = cached_apps.n_task_runs(id)
         cached_apps.overall_progress(id)
         cached_apps.last_activity(id)
         cached_apps.n_completed_tasks(id)
         cached_apps.n_volunteers(id)
         if n_task_runs >= 1000 or featured:
             print "Getting stats for %s as it has %s task runs" % (short_name, n_task_runs)
             stats.get_stats(id, app.config.get('GEO'))
         apps_cached.append(id)
示例#2
0
def get_app_stats(id, short_name): # pragma: no cover
    """Get stats for app."""
    import pybossa.cache.apps as cached_apps
    import pybossa.cache.project_stats as stats
    from flask import current_app

    cached_apps.get_app(short_name)
    cached_apps.n_tasks(id)
    cached_apps.n_task_runs(id)
    cached_apps.overall_progress(id)
    cached_apps.last_activity(id)
    cached_apps.n_completed_tasks(id)
    cached_apps.n_volunteers(id)
    stats.get_stats(id, current_app.config.get('GEO'))
示例#3
0
文件: warm.py 项目: fesp21/pybossa
 def warm_app(id, short_name):
     if id not in apps_cached:
         cached_apps.get_app(short_name)
         cached_apps.n_tasks(id)
         n_task_runs = cached_apps.n_task_runs(id)
         cached_apps.overall_progress(id)
         cached_apps.last_activity(id)
         cached_apps.n_completed_tasks(id)
         cached_apps.n_volunteers(id)
         if n_task_runs >= 1000:
             print "Getting stats for %s as it has %s" % (id,
                                                          n_task_runs)
             stats.get_stats(id, app.config.get('GEO'))
         apps_cached.append(id)
示例#4
0
文件: jobs.py 项目: idahoan/pybossa
def get_app_stats(id, short_name): # pragma: no cover
    """Get stats for app."""
    import pybossa.cache.apps as cached_apps
    import pybossa.cache.project_stats as stats
    from flask import current_app

    cached_apps.get_app(short_name)
    cached_apps.n_tasks(id)
    cached_apps.n_task_runs(id)
    cached_apps.overall_progress(id)
    cached_apps.last_activity(id)
    cached_apps.n_completed_tasks(id)
    cached_apps.n_volunteers(id)
    stats.get_stats(id, current_app.config.get('GEO'))
示例#5
0
def app_by_shortname(short_name):
    app = cached_apps.get_app(short_name)
    if app.id:
        # Populate CACHE with the data of the app
        return (app, cached_apps.n_tasks(app.id),
                cached_apps.n_task_runs(app.id),
                cached_apps.overall_progress(app.id),
                cached_apps.last_activity(app.id))

    else:
        return abort(404)
示例#6
0
def app_by_shortname(short_name):
    app = cached_apps.get_app(short_name)
    if app.id:
        # Populate CACHE with the data of the app
        return (app,
                cached_apps.n_tasks(app.id),
                cached_apps.n_task_runs(app.id),
                cached_apps.overall_progress(app.id),
                cached_apps.last_activity(app.id))

    else:
        return abort(404)
示例#7
0
    def handle_valid_form(form):
        hidden = int(form.hidden.data)

        new_info = {}
        # Add the info items
        app, n_tasks, n_task_runs, overall_progress, last_activity = app_by_shortname(
            short_name)
        if form.thumbnail.data:
            new_info['thumbnail'] = form.thumbnail.data
        #if form.sched.data:
        #    new_info['sched'] = form.sched.data

        # Merge info object
        info = dict(app.info.items() + new_info.items())

        new_application = model.App(
            id=form.id.data,
            name=form.name.data,
            short_name=form.short_name.data,
            description=form.description.data,
            long_description=form.long_description.data,
            hidden=hidden,
            info=info,
            owner_id=app.owner_id,
            allow_anonymous_contributors=form.allow_anonymous_contributors.
            data,
            category_id=form.category_id.data)

        app, n_tasks, n_task_runs, overall_progress, last_activity = app_by_shortname(
            short_name)
        db.session.merge(new_application)
        db.session.commit()
        cached_apps.delete_app(short_name)
        cached_apps.reset()
        cached_cat.reset()
        cached_apps.get_app(new_application.short_name)
        flash(gettext('Application updated!'), 'success')
        return redirect(
            url_for('.details', short_name=new_application.short_name))
示例#8
0
    def handle_valid_form(form):
        hidden = int(form.hidden.data)

        new_info = {}
        # Add the info items
        app, n_tasks, n_task_runs, overall_progress, last_activity = app_by_shortname(short_name)
        if form.thumbnail.data:
            new_info['thumbnail'] = form.thumbnail.data
        #if form.sched.data:
        #    new_info['sched'] = form.sched.data

        # Merge info object
        info = dict(app.info.items() + new_info.items())

        new_application = model.App(
            id=form.id.data,
            name=form.name.data,
            short_name=form.short_name.data,
            description=form.description.data,
            long_description=form.long_description.data,
            hidden=hidden,
            info=info,
            owner_id=app.owner_id,
            allow_anonymous_contributors=form.allow_anonymous_contributors.data,
            category_id=form.category_id.data)

        app, n_tasks, n_task_runs, overall_progress, last_activity = app_by_shortname(short_name)
        db.session.merge(new_application)
        db.session.commit()
        cached_apps.delete_app(short_name)
        cached_apps.reset()
        cached_cat.reset()
        cached_apps.get_app(new_application.short_name)
        flash(gettext('Application updated!'), 'success')
        return redirect(url_for('.details',
                                short_name=new_application.short_name))
示例#9
0
文件: cli.py 项目: idahoan/pybossa
def resize_project_avatars():
    """Resize project avatars to 512px."""
    if app.config['UPLOAD_METHOD'] == 'rackspace':
        import pyrax
        import tempfile
        import requests
        from PIL import Image
        import time
        import pybossa.cache.apps as cached_apps
        # Disable cache to update the data in it :-)
        os.environ['PYBOSSA_REDIS_CACHE_DISABLED'] = '1'
        pyrax.set_setting("identity_type", "rackspace")
        pyrax.set_credentials(username=app.config['RACKSPACE_USERNAME'],
                              api_key=app.config['RACKSPACE_API_KEY'],
                              region=app.config['RACKSPACE_REGION'])

        cf = pyrax.cloudfiles

        #apps = App.query.all()
        file_name = 'project_id_updated_thumbnails.txt'
        project_id_updated_thumbnails = []
        if os.path.isfile(file_name):
            f = open(file_name, 'r')
            project_id_updated_thumbnails = f.readlines()
            f.close()
        apps = App.query.filter(
            ~App.id.in_(project_id_updated_thumbnails)).all()
        #apps = [App.query.get(2042)]
        print "Downloading avatars for %s projects" % len(apps)
        dirpath = tempfile.mkdtemp()
        f = open(file_name, 'a')
        for a in apps:
            try:
                if a.info.get('container'):
                    cont = cf.get_container(a.info['container'])
                    avatar_url = "%s/%s" % (cont.cdn_uri, a.info['thumbnail'])
                    r = requests.get(avatar_url, stream=True)
                    if r.status_code == 200:
                        print "Downloading avatar for %s ..." % a.short_name
                        prefix = time.time()
                        filename = "app_%s_thumbnail_%s.png" % (a.id, prefix)
                        with open(os.path.join(dirpath, filename), 'wb') as f:
                            for chunk in r.iter_content(1024):
                                f.write(chunk)
                        # Resize image
                        im = Image.open(os.path.join(dirpath, filename))
                        size = 512, 512
                        tmp = im.resize(size, Image.ANTIALIAS)
                        scale_down_img = tmp.convert('P',
                                                     colors=255,
                                                     palette=Image.ADAPTIVE)
                        scale_down_img.save(os.path.join(dirpath, filename),
                                            format='png')

                        print "New scaled down image created!"
                        print "%s" % (os.path.join(dirpath, filename))
                        print "---"

                        chksum = pyrax.utils.get_checksum(
                            os.path.join(dirpath, filename))
                        cf.upload_file(cont,
                                       os.path.join(dirpath, filename),
                                       obj_name=filename,
                                       etag=chksum)
                        old_avatar = a.info['thumbnail']
                        # Update new values
                        a.info['thumbnail'] = filename
                        #a.info['container'] = "user_%s" % u.id
                        db.session.commit()
                        f = open(file_name, 'a')
                        f.write("%s\n" % a.id)
                        # delete old avatar
                        obj = cont.get_object(old_avatar)
                        obj.delete()
                        print "Done!"
                        cached_apps.get_app(a.short_name)
                    else:
                        print "No Avatar found."
                else:
                    print "No avatar found."
            except pyrax.exceptions.NoSuchObject:
                print "Previous avatar not found, so not deleting it."
            except:
                raise
                print "No Avatar, this project will use the placehoder."
        f.close()
示例#10
0
文件: cli.py 项目: Krispy2009/pybossa
def resize_project_avatars():
    """Resize project avatars to 512px."""
    if app.config['UPLOAD_METHOD'] == 'rackspace':
        import pyrax
        import tempfile
        import requests
        from PIL import Image
        import time
        import pybossa.cache.apps as cached_apps
        # Disable cache to update the data in it :-)
        os.environ['PYBOSSA_REDIS_CACHE_DISABLED'] = '1'
        pyrax.set_setting("identity_type", "rackspace")
        pyrax.set_credentials(username=app.config['RACKSPACE_USERNAME'],
                              api_key=app.config['RACKSPACE_API_KEY'],
                              region=app.config['RACKSPACE_REGION'])

        cf = pyrax.cloudfiles

        #apps = App.query.all()
        file_name = 'project_id_updated_thumbnails.txt'
        project_id_updated_thumbnails = []
        if os.path.isfile(file_name):
            f = open(file_name, 'r')
            project_id_updated_thumbnails = f.readlines()
            f.close()
        apps = App.query.filter(~App.id.in_(project_id_updated_thumbnails)).all()
        #apps = [App.query.get(2042)]
        print "Downloading avatars for %s projects" % len(apps)
        dirpath = tempfile.mkdtemp()
        f = open(file_name, 'a')
        for a in apps:
            try:
                if a.info.get('container'):
                   cont = cf.get_container(a.info['container'])
                   avatar_url = "%s/%s" % (cont.cdn_uri, a.info['thumbnail'])
                   r = requests.get(avatar_url, stream=True)
                   if r.status_code == 200:
                       print "Downloading avatar for %s ..." % a.short_name
                       prefix = time.time()
                       filename = "app_%s_thumbnail_%s.png" % (a.id, prefix)
                       with open(os.path.join(dirpath, filename), 'wb') as f:
                           for chunk in r.iter_content(1024):
                               f.write(chunk)
                       # Resize image
                       im = Image.open(os.path.join(dirpath, filename))
                       size = 512, 512
                       tmp = im.resize(size, Image.ANTIALIAS)
                       scale_down_img = tmp.convert('P', colors=255, palette=Image.ADAPTIVE)
                       scale_down_img.save(os.path.join(dirpath, filename), format='png')

                       print "New scaled down image created!"
                       print "%s" % (os.path.join(dirpath, filename))
                       print "---"

                       chksum = pyrax.utils.get_checksum(os.path.join(dirpath,
                                                                      filename))
                       cf.upload_file(cont,
                                      os.path.join(dirpath, filename),
                                      obj_name=filename,
                                      etag=chksum)
                       old_avatar = a.info['thumbnail']
                       # Update new values
                       a.info['thumbnail'] = filename
                       #a.info['container'] = "user_%s" % u.id
                       db.session.commit()
                       f = open(file_name, 'a')
                       f.write("%s\n" % a.id)
                       # delete old avatar
                       obj = cont.get_object(old_avatar)
                       obj.delete()
                       print "Done!"
                       cached_apps.get_app(a.short_name)
                   else:
                       print "No Avatar found."
                else:
                   print "No avatar found."
            except pyrax.exceptions.NoSuchObject:
                print "Previous avatar not found, so not deleting it."
            except:
                raise
                print "No Avatar, this project will use the placehoder."
        f.close()