Example #1
0
def generateforall(target_repo, user_email, branch):
    user = user_email
    ontologies = get_ontologies_in_online_repo(target_repo)
    changed_files = ontologies
    print('current file dir: %s' %
          str(os.path.dirname(os.path.realpath(__file__))))

    try:
        r = Repo.objects.get(url=target_repo)
    except Exception as e:
        print(str(e))
        return {'status': False}
    if settings.test_conf['local']:
        print("running autoncode in the same thread")
        j = {
            'action': 'magic',
            'repo': target_repo,
            'branch': branch,
            'useremail': user,
            'changedfiles': changed_files,
            'created': str(timezone.now()),
        }
        rabbit.send(j)
    else:
        try:
            j = {
                'action': 'magic',
                'repo': target_repo,
                'branch': branch,
                'useremail': user,
                'changedfiles': changed_files,
                'created': str(timezone.now()),
            }
            rabbit.send(j)
        except Exception as e:
            sys.stdout.flush()
            sys.stderr.flush()
            error_msg = str(e)
            print('error running generall all subprocess: ' + error_msg)
            if 'execv() arg 2 must contain only strings' in error_msg:
                return {
                    'status':
                    False,
                    'error':
                    'make sure that your repository filenames does not have accents or special characters'
                }
            else:
                return {
                    'status':
                    False,
                    'error':
                    'generic error, please report the problem to us at [email protected]'
                }
    sys.stdout.flush()
    sys.stderr.flush()
    return {'status': True}
Example #2
0
def update_conf(request):
    print('inside update_conf')
    if request.method == "GET":
        return render(request, "msg.html",
                      {"msg": "This method expects POST only"})
    ontologies = request.POST.getlist('ontology')
    data = request.POST
    target_repo = data['repo'].strip()
    j = {
        'action': 'change_conf',
        'repo': target_repo,
        'useremail': request.user.email,
        'ontologies': ontologies,
        'data': data,
        'created': str(timezone.now()),
    }
    rabbit.send(j)
    return HttpResponseRedirect('/profile')
Example #3
0
def publish_view(request):
    if 'name' not in request.GET:
        print("missing name")
        return HttpResponseRedirect('/')
    if 'repo' not in request.GET:
        print("missing repo")
        return HttpResponseRedirect('/')
    if 'ontology' not in request.GET:
        print("missing ontology")
        return HttpResponseRedirect('/')
    if 'branch' not in request.GET:
        print("missing branch")
        return HttpResponseRedirect('/')
    name = request.GET['name'].strip()
    target_repo = request.GET['repo'].strip()
    ontology_rel_path = request.GET['ontology'].strip()
    branch = request.GET['branch'].strip()
    print("name: " + name)
    pns = PublishName.objects.filter(name=name)
    if len(pns) > 0:
        return JsonResponse(
            {'msg': 'This name is already taken, try to choose another name'},
            status=400)
    try:
        j = {
            'action': 'publish',
            'repo': target_repo,
            'branch': branch,
            'useremail': request.user.email,
            'ontology_rel_path': ontology_rel_path,
            'name': name,
            'created': str(timezone.now()),
        }
        rabbit.send(j)
        msg = '''<i>%s</i> will be published soon. This might take a few minutes for the published ontology to be
            available for GitHub pages.''' % ontology_rel_path[1:]
        return JsonResponse({'msg': msg})
        # return render(request, 'msg.html', {'msg': msg, 'img': 'https://github.com/OnToology/OnToology/raw/master/media/misc/gh-pages.png'})
    except Exception as e:
        print("publish_view> error : %s" % str(e))
        msg = "Error publishing your ontology. Please contact us to fix it."
        # return render(request, 'msg.html', {'msg': msg})
        return JsonResponse({'msg': msg}, status=500)
Example #4
0
def add_hook(request):
    print("in add hook function")
    print("method: " + request.method)
    print("body: ")
    print(request.body)
    print("header: ")
    print(request.headers)
    changed_files = []
    if settings.test_conf['local']:
        print('We are in test mode')
    try:
        print("\n\nPOST DATA\n\n: " + str(request.POST))
        s = str(request.POST['payload'])
        print("payload: " + s)
        j = json.loads(s, strict=False)
        print("json is loaded")
        if "ref" in j:
            branch = j["ref"].split("/")[-1]
            if branch == "gh-pages":
                print("it is just gh-pages")
                return render(request, 'msg.html',
                              {'msg': 'it is gh-pages, so nothing'})
            else:
                s = j['repository']['url'] + 'updated files: ' + str(
                    j['head_commit']['modified'])
                print("just s: " + str(s))
                target_repo = j['repository']['full_name']
                user = j['repository']['owner']['email']
                print("target_repo: " + str(target_repo))
                print("user email: " + str(user))
                changed_files = get_changed_files_from_payload(j)
                print("early changed files: " + str(changed_files))
                if 'Merge pull request' in j['head_commit']['message'] or \
                        'OnToology Configuration' == j['head_commit']['message'] or \
                        'OnToology Publish' == j['head_commit']['message']:
                    print('This is a merge request or Configuration push')
                    try:
                        repo = Repo.objects.get(url=target_repo)
                        print('got the repo')
                        repo.last_used = timezone.now()
                        repo.progress = 100.0
                        repo.save()
                        print('repo saved')
                    except Model.DoesNotExist:
                        repo = Repo()
                        repo.url = target_repo
                        repo.save()
                    except Exception as e:
                        print('database_exception: ' + str(e))
                        traceback.print_exc()
                    msg = 'This indicate that this merge request will be ignored'
                    print(msg)
                    if settings.test_conf['local']:
                        print(msg)
                        return
                    else:
                        return render(request, 'msg.html', {'msg': msg})
    except Exception as e:
        print("add hook exception: " + str(e))
        traceback.print_exc()
        msg = 'This request should be a webhook ping'
        if settings.test_conf['local']:
            print(msg)
            return JsonResponse({'status': False, 'error': str(e)})
        else:
            return JsonResponse({'status': False, 'error': str(e)})
    try:
        print('##################################################')
        print('changed_files: ' + str(changed_files))
        j = {
            'action': 'magic',
            'repo': target_repo,
            'branch': branch,
            'useremail': user,
            'changedfiles': changed_files,
            'created': str(timezone.now()),
        }
        rabbit.send(j)
    except Exception as e:
        error_msg = str(e)
        print('error running generall all subprocess: ' + error_msg)
        traceback.print_exc()
        sys.stdout.flush()
        sys.stderr.flush()
        if 'execv() arg 2 must contain only strings' in error_msg:
            error_msg = 'make sure that your repository filenames does not have accents or special characters'
        else:
            error_msg = 'generic error, please report the problem to us [email protected]'
        s = error_msg
    return JsonResponse({'status': True})