예제 #1
0
def result(request):
    if request.method == 'POST': return error403(request)

    if 'job_id' not in request.GET:
        return error400(request)
    else:
        job_id = request.GET.get('job_id')
        if not job_id: return HttpResponseRedirect('/')
        if len(job_id) != 16 or (not re.match('[0-9a-fA-F]{16}', job_id)):
            return error400(request)

        if 'json' in request.GET and request.GET.get(
                'json').lower() != 'false':
            return result_json(job_id)
        try:
            job_list_entry = JobIDs.objects.get(job_id=job_id)
        except:
            return error404(request)
        form = Design1DForm() if job_list_entry.type == "1" else (
            Design2DForm() if job_list_entry.type == "2" else Design3DForm())
        json = {
            'result_job_id': job_id,
            '%sd_form' % job_list_entry.type: form
        }
        return render(request,
                      PATH.HTML_PATH['design_%sd' % job_list_entry.type], json)
예제 #2
0
def tutorial(request, keyword):
    if keyword in dist_dict:
        return HttpResponsePermanentRedirect('https://ribokit.github.io/' +
                                             dist_dict[keyword])
    elif keyword in ('predict', 'api'):
        return render(request,
                      PATH.HTML_PATH['tutorial'].replace('xxx', keyword), {})
    else:
        return error404(request)
예제 #3
0
def tools_license(request, keyword):
    if keyword in dist_dict:
        title = dist_dict[keyword]
        file_name = '%s/dist/%s-LICENSE.md' % (MEDIA_ROOT, title)
        license_md = '404 Not Found'
        if os.path.exists(file_name):
            license_md = ''.join(open(file_name, 'r').readlines())
            license_md = license_md.replace('\n', '<br/>') + '</strong>'

        return render(request, PATH.HTML_PATH['tools_license'], {
            'keyword': keyword,
            'title': title,
            'license_md': license_md
        })
    else:
        return error404(request)
예제 #4
0
def tools_link(request, keyword, tag):
    records = SourceDownloader.objects.filter(
        package=keyword, rmdb_user=RMDBUser.objects.get(user=request.user))
    if len(records):
        title = dist_dict[keyword]
        tag = tag.replace('/', '')
        file_name = '%s/dist/%s-%s.zip' % (MEDIA_ROOT, title, tag)
        if os.path.exists(file_name):
            response = HttpResponse(content_type='application/zip')
            response[
                'Content-Disposition'] = 'attachment; filename=%s-%s.zip' % (
                    title, tag)
            response['X-Sendfile'] = smart_str(file_name)
            return response
        else:
            return error404(request)
    return error401(request)
예제 #5
0
def git_hook(request):
    if request.method != 'POST': return error404(request)
    if ('HTTP_X_HUB_SIGNATURE' not in request.META) or (
            'HTTP_X_GITHUB_DELIVERY'
            not in request.META) or ('HTTP_X_GITHUB_EVENT'
                                     not in request.META):
        return error400(request)

    signature = request.META['HTTP_X_HUB_SIGNATURE']
    mac = hmac.new(env('GITHOOK_SECRET'), msg=request.body, digestmod=sha1)
    if not hmac.compare_digest('sha1=' + str(mac.hexdigest()), str(signature)):
        return error403(request)

    try:
        call_command('dist')
    except Exception:
        print traceback.format_exc()
        return error500(request)
    return HttpResponse(content="", status=201)
예제 #6
0
def tools_download(request, keyword):
    if keyword in dist_dict:
        new = SourceDownloader(
            date=datetime.now(),
            package=keyword,
            rmdb_user=RMDBUser.objects.get(user=request.user))
        new.save()

        result = simplejson.load(
            open('%s/cache/stat_dist.json' % MEDIA_ROOT, 'r'))
        result = result[keyword]
        title = dist_dict[keyword]
        return render(request, PATH.HTML_PATH['tools_download'], {
            'keyword': keyword,
            'title': title,
            'dist': result
        })
    else:
        return error404(request)
예제 #7
0
def detail(request, rmdb_id):
    try:
        entry = RMDBEntry.objects.filter(
            rmdb_id=rmdb_id).order_by('-version')[0]
        is_isatab = os.path.exists('%s%s/%s_%s.xls' %
                                   (PATH.DATA_DIR['FILE_DIR'], entry.rmdb_id,
                                    entry.rmdb_id, entry.version))
    except (RMDBEntry.DoesNotExist, IndexError):
        return error404(request)

    json = {
        'rmdb_id': entry.rmdb_id,
        'status': entry.status,
        'is_isatab': is_isatab
    }
    if entry.status != "PUB":
        json.update({
            'version': entry.version,
            'rev_form': ReviewForm(initial={'rmdb_id': entry.rmdb_id})
        })
    return render(request, PATH.HTML_PATH['detail'], json)