示例#1
0
def jobdata(uid):
    job = read_job(uid, 'directory', 'data_ext')
    if not job:
        return abort(404)
    print job
    r.set('job:%s:dt_started' % uid, time())
    r.set('job:%s:is_started' % uid, 1)
    return send_file(job.data_fn)
示例#2
0
def jobpush(uid):
    job = read_job(uid)
    if not job:
        return abort(404)
    file = request.files['file']
    if file and file.filename.rsplit('.', 1)[-1] == 'apk':
        filename = secure_filename(file.filename)
        file.save(join(job.directory, filename))
        r.set('job:%s:apk' % uid, filename)
        r.set('job:%s:dt_done' % uid, time())
        r.set('job:%s:is_done' % uid, 1)

        try:
            job.notify()
        except:
            pass
        return make_response('done')
    else:
        return abort(403)
示例#3
0
def submit():
    form = JobForm()
    if form.validate_on_submit():
        fn = secure_filename(form.directory.file.filename)
        ext = splitext(fn)[-1]
        if splitext(fn)[-1] not in (
                '.zip'):#, '.tbz', '.tar.gz', '.tbz2', '.tar.bz2'):
            return render_template('frontend/index.html', form=form,
                    error='Invalid application directory package')

        # create a job
        uid = str(uuid4())

        # fake job obj for getting path
        job = JobObj({'uid': uid})

        jobkey = 'job:%s' % uid
        basekey = jobkey + ':'
        r.set(basekey + 'dt_added', time())

        # create the job directory
        d = job.directory
        mkdir(d)
        form.directory.file.save(join(d, 'data%s' % ext))

        if form.package_presplash.file:
            form.package_presplash.file.save(job.presplash_fn)
            r.set(basekey + 'have_presplash', 1)
        else:
            r.set(basekey + 'have_presplash', 0)

        if form.package_icon.file:
            form.package_icon.file.save(job.icon_fn)
            r.set(basekey + 'have_icon', 1)
        else:
            r.set(basekey + 'have_icon', 0)

        # add in the database
        r.set(basekey + 'package_name', form.package_name.data)
        r.set(basekey + 'package_version', form.package_version.data)
        r.set(basekey + 'package_title', form.package_title.data)
        r.set(basekey + 'package_orientation', form.package_orientation.data)
        r.set(basekey + 'package_permissions', form.package_permissions.data)
        r.set(basekey + 'modules', form.modules.data)
        r.set(basekey + 'emails', form.emails.data)
        r.set(basekey + 'data_ext', ext)
        r.set(basekey + 'is_release', 1 if form.release.data else 0)
        r.set(basekey + 'build_status', '')
        r.set(basekey + 'is_failed', 0)
        r.set(basekey + 'is_started', 0)
        r.set(basekey + 'is_done', 0)
        r.set(basekey + 'apk', '')

        # creation finished
        r.set(jobkey, uid)

        # not optimized, but reread it.
        job = read_job(uid)

        # submit a job in reddis
        qjob.put({
            'uid': job.uid,
            'package_name': job.package_name,
            'package_title': job.package_title,
            'package_version': job.package_version,
            'package_orientation': job.package_orientation,
            'package_permissions': csplit(job.package_permissions),
            'emails': csplit(job.emails),
            'have_icon': job.have_icon,
            'have_presplash': job.have_presplash,
            'mode': 'release' if job.is_release == '1' else 'debug',
            'modules': csplit(job.modules)
        })

        if 'batch' in request.form:
            d = {'status': 'ok',
                'uid': job.uid,
                'url': url_for('frontend.job', uid=job.uid, _external=True)}
            return jsonify(**d)
        else:
            # redirect to the view job
            return redirect(url_for('frontend.job', uid=job.uid))

    return render_template('frontend/index.html', form=form)
示例#4
0
def loop_handle(log):
    if 'cmd' not in log:
        return
    cmd = log['cmd']

    if 'host' in log:
        r.set('host:{}:last_alive'.format(log['host']), time())

    if cmd in ('available', 'busy'):
        r.set('host:{}:status'.format(log['host']), cmd)
        return

    if cmd == 'purge':
        # search all projects done last 48h
        keys = r.keys('job:*:dt_added')
        print keys
        to_delete = []
        ctime = time()
        for key in keys:
            dt = ctime - float(r.get(key))
            print 'checked', key[4:-9], dt
            if dt > 60 * 60 * 48:
                print 'going to delete', key[4:-9], ', delta is', dt
                to_delete.append(key[4:-9])

        # delete everything related to all the jobs to delete
        print 'doing deletion of', to_delete
        for uid in to_delete:
            print 'delete', uid
            job = JobObj({'uid': uid})
            d = job.directory
            if d and len(d) > 10:
                subprocess.Popen(['rm', '-rf', d], shell=False).communicate()
            keys = r.keys('job:%s*' % uid)
            if keys:
                r.delete(*keys)
            keys = r.keys('log:%s*' % uid)
            if keys:
                r.delete(*keys)

        return

    # next command _need_ uid.

    if 'uid' not in log:
        return
    uid = log['uid']

    jobkey = 'job:%s' % uid
    if not r.keys(jobkey):
        return

    if cmd == 'status':
        r.set(jobkey + ':build_status', log['msg'])
    elif cmd == 'exception':
        r.set(jobkey + ':build_status', '[1/1] Error')
        r.set(jobkey + ':is_failed', 1)
        r.set(jobkey + ':fail_message', log['msg'])

    if cmd == 'log' or cmd == 'exception':
        logkey = 'log:%s' % uid
        if not r.keys(logkey):
            r.set(logkey, 1)
            lidx = 1
        else:
            lidx = r.incr(logkey)
        logkeytxt = logkey + ':%d' % lidx
        if cmd == 'log':
            r.set(logkeytxt, log['line'])
        else:
            r.set(logkeytxt, log['msg'])

    if cmd == 'exception':
        job = read_job(uid)
        if job:
            job.notify()