Ejemplo n.º 1
0
def home(request):
    print '****** Welcome to home page ********'
    print >> sys.stderr, '****** Welcome to the error output ******'
    if 'target_repo' in request.GET:
        print "we are inside"
        target_repo = request.GET['target_repo']
        if target_repo.strip() == "" or len(target_repo.split('/')) != 2:
            return render(request, 'msg.html',
                          {'msg': 'please enter a valid repo'})
        init_g()
        # if not has_access_to_repo(target_repo):# this for the organization
        # return render(request,'msg.html',{'msg': 'repos under organizations are not supported at the moment'})
        if request.user.is_authenticated():
            ouser = OUser.objects.get(username=request.user.username)
            # this is initially to get the access key for the user
            webhook_access_url, state = webhook_access(
                client_id, host + '/get_access_token', ouser.private)
        else:  # private access in case not logged in
            webhook_access_url, state = webhook_access(
                client_id, host + '/get_access_token', True)
        request.session['target_repo'] = target_repo
        request.session['state'] = state
        # if '127.0.0.1:8000' not in request.META['HTTP_HOST']:  # Not testing   # or not settings.test_conf['local']:
        if True:
            request.session['access_token_time'] = '1'
            return HttpResponseRedirect(webhook_access_url)
        if request.user.is_authenticated():
            generateforall(target_repo, request.user.email)
    repos = Repo.objects.order_by('-last_used')[:10]
    return render(request, 'home.html', {'repos': repos, 'user': request.user})
Ejemplo n.º 2
0
def home(request):
    print '****** Welcome to home page ********'
    print >> sys.stderr,  '****** Welcome to the error output ******'
    if 'target_repo' in request.GET:
        #print request.GET
        target_repo = request.GET['target_repo']
        init_g()
        if not has_access_to_repo(target_repo):# this for the organization
            return render(request,'msg.html',{'msg': 'repos under organizations are not supported at the moment'})
        webhook_access_url, state = webhook_access(client_id,host+'/get_access_token')
        request.session['target_repo'] = target_repo
        request.session['state'] = state 
        try: 
            repo = Repo.objects.get(url=target_repo)
        except Exception as e:
            print str(e)
            repo = Repo()
            repo.url=target_repo
            repo.save()            
        if request.user.is_authenticated():
            ouser = OUser.objects.get(email=request.user.email)
            if repo not in ouser.repos:
                ouser.repos.append(repo)
                ouser.save()
        sys.stdout.flush()
        sys.stderr.flush()        
        if '127.0.0.1:8000' not in request.META['HTTP_HOST'] or not settings.test_conf['local']:
            return  HttpResponseRedirect(webhook_access_url)
    sys.stdout.flush()
    sys.stderr.flush()
    repos = get_repos_formatted(Repo.objects.all())
    return render(request,'home.html',{'repos': repos, 'user': request.user })    
Ejemplo n.º 3
0
def home(request):
    global client_id, client_secret, is_private
    # sys.stdout = sys.stderr
    # print "******* output to stderror ********"
    sys.stdout.flush()
    sys.stderr.flush()
    if 'target_repo' in request.GET:
        print "we are inside"
        target_repo = request.GET['target_repo']
        if target_repo.strip() == "" or len(target_repo.split('/')) != 2:
            return render(request, 'msg.html', {'msg': 'please enter a valid repo'})
        init_g()
        # if not has_access_to_repo(target_repo):# this for the organization
        # return render(request,'msg.html',{'msg': 'repos under organizations are not supported at the moment'})
        wgets_dir = os.environ['wget_dir']
        if call('cd %s; wget %s;' % (wgets_dir, 'http://github.com/' + target_repo.strip()), shell=True) == 0:
            is_private = False
            client_id = client_id_public
            client_secret = client_secret_public
        else:
            is_private = True
            client_id = client_id_private
            client_secret = client_secret_private
        webhook_access_url, state = webhook_access(client_id, host + '/get_access_token', isprivate=is_private)
        request.session['target_repo'] = target_repo
        request.session['state'] = state
        request.session['access_token_time'] = '1'
        return HttpResponseRedirect(webhook_access_url)
    repos = Repo.objects.order_by('-last_used')[:10]
    num_of_users = len(User.objects.all())
    num_of_repos = len(Repo.objects.all())
    print "returning the request"
    print("The user: %s" % str(request.user) )
    return render(request, 'home.html', {'repos': repos, 'user': request.user, 'num_of_users': num_of_users,
                                         'num_of_repos': num_of_repos})
Ejemplo n.º 4
0
def home(request):
    print '****** Welcome to home page ********'
    print >> sys.stderr, '****** Welcome to the error output ******'
    if 'target_repo' in request.GET:
        print "we are inside"
        target_repo = request.GET['target_repo']
        if target_repo.strip() == "" or len(target_repo.split('/')) != 2:
            return render(request, 'msg.html', {'msg': 'please enter a valid repo'})
        init_g()
        # if not has_access_to_repo(target_repo):# this for the organization
        # return render(request,'msg.html',{'msg': 'repos under organizations are not supported at the moment'})
        if request.user.is_authenticated():
            ouser = OUser.objects.get(username=request.user.username)
            # this is initially to get the access key for the user
            webhook_access_url, state = webhook_access(client_id, host + '/get_access_token', ouser.private)
        else:  # private access in case not logged in
            webhook_access_url, state = webhook_access(client_id, host + '/get_access_token', True)
        request.session['target_repo'] = target_repo
        request.session['state'] = state
        # if '127.0.0.1:8000' not in request.META['HTTP_HOST']:  # Not testing   # or not settings.test_conf['local']:
        if True:
            request.session['access_token_time'] = '1'
            return HttpResponseRedirect(webhook_access_url)
        if request.user.is_authenticated():
            generateforall(target_repo, request.user.email)
    repos = Repo.objects.order_by('-last_used')[:10]
    return render(request, 'home.html', {'repos': repos, 'user': request.user})
Ejemplo n.º 5
0
def home(request):
    print '****** Welcome to home page ********'
    print >> sys.stderr, '****** Welcome to the error output ******'
    if 'target_repo' in request.GET:
        #print request.GET
        target_repo = request.GET['target_repo']
        init_g()
        if not has_access_to_repo(target_repo):  # this for the organization
            return render(request, 'msg.html', {
                'msg':
                'repos under organizations are not supported at the moment'
            })
        webhook_access_url, state = webhook_access(client_id,
                                                   host + '/get_access_token')
        request.session['target_repo'] = target_repo
        request.session['state'] = state
        try:
            repo = Repo.objects.get(url=target_repo)
        except Exception as e:
            print str(e)
            repo = Repo()
            repo.url = target_repo
            repo.save()
        if request.user.is_authenticated():
            ouser = OUser.objects.get(email=request.user.email)
            if repo not in ouser.repos:
                ouser.repos.append(repo)
                ouser.save()
        sys.stdout.flush()
        sys.stderr.flush()
        if '127.0.0.1:8000' not in request.META[
                'HTTP_HOST'] or not settings.test_conf['local']:
            return HttpResponseRedirect(webhook_access_url)
    sys.stdout.flush()
    sys.stderr.flush()
    repos = get_repos_formatted(Repo.objects.all())
    return render(request, 'home.html', {'repos': repos, 'user': request.user})