예제 #1
0
파일: views.py 프로젝트: pombredanne/bvd
def pull_jobs(request, *args, **kwargs):
    
    if request.user.is_authenticated():
        joblist = get_jobs_for_user(request.user)
        for product, jobs in joblist.iteritems():
            for job in jobs:
                jenkins = RetrieveJob(job['hostname'],job['jobname'])
                result = jenkins.lookup_job()

                lastSuccess = jenkins.lookup_last_successful_build()
                job['timeSinceLastSuccess'] = lastSuccess.get('timeSinceLastSuccess')

                if result == urllib2.URLError:
                    #TODO: add an additional state other than down 
                    job['status'] = "DOWN"
                elif result == ValueError:
                    #TODO: add an additional state other than down
                    job['status'] = "DOWN"
                elif not result['status']:
                    job['status'] = 'SUCCESS'
                elif job['status'] == 'ABORTED' or job['status'] == 'NOT_BUILT':
                    job['status'] = "DOWN"
                else:
                    job['status'] = result['status'] 

        return HttpResponse(simplejson.dumps([dict(status = 200, jobs = joblist)]))
예제 #2
0
def validate_hostname(request):
    """
        This function:
            Validates that a Jenkins hostname is valid

        Requested by:
            add_job.html, edit_job.html

        Request method:
            POST
    """
    print request.POST.get('hostname')
    job = RetrieveJob(append_http(request.POST.get('hostname',None)),None)
    print request.POST.get('username') == 'Username'
    test = job.lookup_hostname(request.POST.get('username') != 'Username', request.POST.get('username'), request.POST.get('password1'))
    
    if test == urllib2.URLError:
        result = dict(status = 500)
    elif test == ValueError:
        result = dict(status = 404)
    elif test == 403: #autherization required
        result = dict(status = 403)
    elif test == 401: #invalid cerendtials
        result = dict(status = 401)
    else:
        result = dict(status = 200)
    
    return HttpResponse(simplejson.dumps([result]))
예제 #3
0
def pull_apple_tv_jobs(request, *args, **kwargs):
    joblist = get_jobs_for_readonly()
    for product, jobs in joblist.iteritems():
        for job in jobs:
            jenkins = RetrieveJob(job['hostname'], job['jobname'])
            result = jenkins.lookup_job()

            lastSuccess = jenkins.lookup_last_successful_build()
            job['timeSinceLastSuccess'] = lastSuccess.get(
                'timeSinceLastSuccess')

            if result == urllib2.URLError:
                #TODO: add an additional state other than down
                job['status'] = "DOWN"
            elif result == ValueError:
                #TODO: add an additional state other than down
                job['status'] = "DOWN"
            elif not result['status']:
                job['status'] = 'SUCCESS'
            elif job['status'] == 'ABORTED' or job['status'] == 'NOT_BUILT':
                job['status'] = "DOWN"
            else:
                job['status'] = result['status']

    return HttpResponse(simplejson.dumps([dict(status=200, jobs=joblist)]))
예제 #4
0
def validate_job(request):
    hostname = append_http(request.POST.get('hostname', ''))
    jobname = request.POST.get('jobname', None)

    if hostname.strip() == 'http://' or not jobname:
        result = dict(status=500)
        return HttpResponse(simplejson.dumps([result]))

    job = RetrieveJob(hostname, jobname)
    result = job.lookup_job(
        request.POST.get('username') != 'Username',
        request.POST.get('username'), request.POST.get('password1'))

    if result == urllib2.URLError:
        result = dict(status=500)
        return HttpResponse(simplejson.dumps([result]))
    elif result == ValueError:
        result = dict(status=404)
        return HttpResponse(simplejson.dumps([result]))
    elif result == 403:  #autherization required
        result = dict(status=403)
    elif result == 401:  #invalid cerendtials
        result = dict(status=401)
        return HttpResponse(simplejson.dumps([result]))
    elif not result['status']:
        result['status'] = 'SUCCESS'
    else:
        result.update(dict(hostname=hostname))

    key = str('%s/%s' % (hostname, jobname))

    request.session[key] = result
    return HttpResponse(simplejson.dumps([dict(status=200)]))
예제 #5
0
파일: views.py 프로젝트: pombredanne/bvd
def validate_job(request):
    hostname = append_http(request.POST.get('hostname',''))
    jobname = request.POST.get('jobname',None)

    if hostname.strip() == 'http://' or not jobname:
        result = dict(status = 500)
        return HttpResponse(simplejson.dumps([result]))
  
    job = RetrieveJob(hostname,jobname)
    result = job.lookup_job(request.POST.get('username') != 'Username', request.POST.get('username'), request.POST.get('password1'))

    if result == urllib2.URLError:
        result = dict(status = 500)
        return HttpResponse(simplejson.dumps([result]))
    elif result == ValueError:
        result = dict(status = 404)
        return HttpResponse(simplejson.dumps([result]))
    elif result == 403: #autherization required
        result = dict(status = 403)
    elif result == 401: #invalid cerendtials
        result = dict(status = 401)
        return HttpResponse(simplejson.dumps([result]))
    elif not result['status']:
            result['status'] = 'SUCCESS'
    else:
        result.update(dict(hostname = hostname))
        
    key = str('%s/%s' % (hostname, jobname))
    
    request.session[key] = result
    return HttpResponse(simplejson.dumps([dict(status = 200)]))
예제 #6
0
파일: views.py 프로젝트: webiken/bvd
def pull_jobs(request, *args, **kwargs):
    
    if request.user.is_authenticated():
        list = get_jobs_for_user(request.user)
        for job in list:
            jenkins = RetrieveJob(job['hostname'],job['jobname'])
            result = jenkins.lookup_job()

            if result == urllib2.HTTPError:
                jenkins = RetrieveJob(job['hostname'],job['jobname'])
                result = jenkins.lookup_job(True, settings.JENKINS_USER, settings.JENKINS_PASS)

            
            if result == urllib2.URLError:
                #TODO: add an additional state other than down 
                job['status'] = "DOWN"

            elif result == ValueError:
                #TODO: add an additional state other than down
                job['status'] = "DOWN"
            elif not result['status']:
                job['status'] = 'SUCCESS'
            else:
                job['status'] = result['status'] 

            
        return HttpResponse(simplejson.dumps([dict(status = 200, jobs = list)]), content_type = 'application/json')
예제 #7
0
def add_job(request):
    """
        This Function is POSTed to by the Add Job modal to create a new widget. It:
            - Checks if the user is authenticated
            - Initializes widget data not provided by the add job modal
            - If a displayname isn't provided, uses the jobname
            - Creates a new Ci Server object if provided
            - Checks if the user has a widget for that job on that server
                Yes: Updates that widget with the form data
                 No: Creates a new widget with the form data
            - Saves the widget
            - Redirects to '/'
    """
    if request.user.is_authenticated():
        widget_data = request.POST.copy()  # request.POST is immutable

        widget_data['user'] = request.user.id
        widget_data['icon'] = 'checkmark.png'
        widget_data['readonly'] = False
        widget_data['entity_active'] = True
        widget_data['appletv'] = False
        widget_data['appletv_active'] = True

        if not 'displayname' in widget_data or widget_data['displayname'] == '':
            widget_data['displayname'] = widget_data['jobname']

        if 'new_ci_server' in widget_data and not widget_data[
                'new_ci_server'] == '':
            job = RetrieveJob(append_http(widget_data['new_ci_server']), None)
            if job.lookup_hostname(False):
                newserver = models.CiServer(
                    hostname=widget_data['new_ci_server'])
                newserver.save()
                widget_data['ci_server'] = newserver.hostname

        matches = models.UserCiJob.objects.filter(
            user__username=request.user.username,
            ci_server__hostname=widget_data['ci_server'],
            jobname=widget_data['jobname'])

        if len(matches) > 0:
            # Don't change the Public TV Display properties of the existing widget.
            widget_data['appletv'] = matches[0].appletv
            widget_data['appletv_active'] = matches[0].appletv_active

            form = forms.UserCiJobForm(widget_data, instance=matches[0])
        else:
            form = forms.UserCiJobForm(widget_data)

        if form.is_valid():
            form.save()
        else:
            print form.errors

    return HttpResponseRedirect('/')
예제 #8
0
def pull_jobs_for_product(request):
    """
        This function:
            Loads the list of jobs for a specific product.

        Requested by:
            view_product.html - update()

        Request method:
            GET
    """
    productname = request.GET.get('productname')

    if request.user.is_authenticated():
        jobs = [ widget_to_dictionary(job) for job in models.Product.objects.filter(productname=productname,jobs__user__username=request.user.username)[0].jobs.all() ]
    else:
        jobs = [ widget_to_dictionary(job) for job in models.Product.objects.filter(productname=productname,jobs__appletv_active=True)[0].jobs.all() ]

    for job in jobs:
        if not request.user.is_authenticated():
            job['readonly'] = True
        
        if settings.CACHE_BACKEND:
            cache_key = job['hostname'] + '_' + job['jobname']
            last_success_key = cache_key + '_lastSuccess'
            
            result = cache.get(cache_key)
            lastSuccess = cache.get(last_success_key)

        if not result:
            jenkins = RetrieveJob(job['hostname'],job['jobname'])
            result = jenkins.lookup_job()
            cache.set(cache_key, result, 60 * 10)
            lastSuccess = jenkins.lookup_last_successful_build()
            cache.set(last_success_key, lastSuccess, 60 * 10)

        if result == urllib2.URLError:
            #TODO: add an additional state other than down 
            job['status'] = "DOWN"
        elif result == ValueError:
            #TODO: add an additional state other than down
            job['status'] = "DOWN"
        elif not result['status']:
            job['status'] = 'SUCCESS'
        elif job['status'] == 'ABORTED' or job['status'] == 'NOT_BUILT':
            job['status'] = "DOWN"
        else:
            job['status'] = result['status']         

    joblist = dict()
    joblist["no_product"] = jobs

    return HttpResponse(simplejson.dumps([dict(status=200, jobs=joblist)]))
예제 #9
0
def pull_jobs(request, *args, **kwargs):
    """
        This function:
            Pulls the list of jobs for the user.

        Requested by:
            Poll.ajax('/pull/pull_jobs')

        Request method:
            GET
    """
    if request.user.is_authenticated():
        joblist = get_jobs_for_user(request.user)
        for product, jobs in joblist.iteritems():
            for job in jobs:
                if settings.CACHE_BACKEND:
                    cache_key = job['hostname'] + '_' + job['jobname']
                    last_success_key = cache_key + '_lastSuccess'
                    
                    result = cache.get(cache_key)
                    lastSuccess = cache.get(last_success_key)

                if not result:
                    jenkins = RetrieveJob(job['hostname'],job['jobname'])
                    result = jenkins.lookup_job()
                    if settings.CACHE_BACKEND:
                        cache.set(cache_key, result, 60 * 10)
                if not lastSuccess:
                    try:
                        lastSuccess = jenkins.lookup_last_successful_build()
                        if settings.CACHE_BACKEND:
                            cache.set(last_success_key, lastSuccess, 60 * 10)
                    except:
                        lastSuccess = None

                if lastSuccess and not lastSuccess == urllib2.URLError:
                    job['timeSinceLastSuccess'] = lastSuccess.get('timeSinceLastSuccess')

                if result == urllib2.URLError:
                    #TODO: add an additional state other than down 
                    job['status'] = "DOWN"
                elif result == ValueError:
                    #TODO: add an additional state other than down
                    job['status'] = "DOWN"
                elif not result['status']:
                    job['status'] = 'SUCCESS'
                elif job['status'] == 'ABORTED' or job['status'] == 'NOT_BUILT':
                    job['status'] = "DOWN"
                else:
                    job['status'] = result['status'] 

        return HttpResponse(simplejson.dumps([dict(status = 200, jobs = joblist)]))
예제 #10
0
def add_job(request):
    """
        This Function is POSTed to by the Add Job modal to create a new widget. It:
            - Checks if the user is authenticated
            - Initializes widget data not provided by the add job modal
            - If a displayname isn't provided, uses the jobname
            - Creates a new Ci Server object if provided
            - Checks if the user has a widget for that job on that server
                Yes: Updates that widget with the form data
                 No: Creates a new widget with the form data
            - Saves the widget
            - Redirects to '/'
    """
    if request.user.is_authenticated():
        widget_data = request.POST.copy() # request.POST is immutable

        widget_data['user'] = request.user.id
        widget_data['icon'] = 'checkmark.png'
        widget_data['readonly'] = False
        widget_data['entity_active'] = True
        widget_data['appletv'] = False
        widget_data['appletv_active'] = True

        if not 'displayname' in widget_data or widget_data['displayname'] == '':
            widget_data['displayname'] = widget_data['jobname']

        if 'new_ci_server' in widget_data and not widget_data['new_ci_server'] == '':
            job = RetrieveJob(append_http(widget_data['new_ci_server']), None)
            if job.lookup_hostname(False):
                newserver = models.CiServer(hostname = widget_data['new_ci_server'])
                newserver.save()
                widget_data['ci_server'] = newserver.hostname

        matches = models.UserCiJob.objects.filter(user__username = request.user.username,
                    ci_server__hostname = widget_data['ci_server'],
                    jobname = widget_data['jobname'])

        if len(matches) > 0:
            # Don't change the Public TV Display properties of the existing widget.
            widget_data['appletv'] = matches[0].appletv
            widget_data['appletv_active'] = matches[0].appletv_active

            form = forms.UserCiJobForm(widget_data, instance=matches[0])
        else:
            form = forms.UserCiJobForm(widget_data)

        if form.is_valid():
            form.save()
        else:
            print form.errors

    return HttpResponseRedirect('/')
예제 #11
0
def save_widget(request):
    """
        This Function:
            Is POST-ed to by the edit_widget modal in order to save changes
            to the widget.
    """
    if not request.user.is_authenticated():
        return HttpResponse(status=401)

    if 'widget_id' in request.POST:
        new_data = request.POST.copy()
        widget = models.UserCiJob.objects.get(pk=request.POST['widget_id'])
        old_data = widget_to_dictionary(widget)

        # The form has to be populated by old data because the edit_widget
        # modal form doesn't provide all attributes of the UserCiJob model.
        # The widget's attributes are copied to a dictionary and then
        # the values from the form data are used to update the dictionary.

        for key in ['displayname', 'jobname', 'ci_server']:
            if key in new_data:
                old_data[key] = new_data[key]

        # If these checkboxes are unchecked, the field is not returned
        # from the form, therefore in order to update them from the
        # edit widget modal we check if they exist in the POST data at all.

        for key in ['entity_active', 'appletv', 'appletv_active']:
            if key in new_data:
                if new_data[key] != "current":
                    old_data[key] = True
            else:
                old_data[key] = False

        # If the form provides a new CiServer hostname a new model object is
        # created and then the ci_server value is changed in the form data to match.

        if 'new_ci_server' in new_data and not new_data['new_ci_server'] == '':
            job = RetrieveJob(append_http(new_data['new_ci_server']),None)
            if job.lookup_hostname(False):
                newserver = models.CiServer(hostname = new_data['new_ci_server'])
                newserver.save()
                old_data['ci_server'] = newserver.hostname

        form = forms.UserCiJobForm(old_data, instance=widget)
        if form.is_valid():
            form.save()
        else:
            print form.errors

    return HttpResponseRedirect('/')
예제 #12
0
def save_widget(request):
    """
        This Function:
            Is POST-ed to by the edit_widget modal in order to save changes
            to the widget.
    """
    if not request.user.is_authenticated():
        return HttpResponse(status=401)

    if 'widget_id' in request.POST:
        new_data = request.POST.copy()
        widget = models.UserCiJob.objects.get(pk=request.POST['widget_id'])
        old_data = widget_to_dictionary(widget)

        # The form has to be populated by old data because the edit_widget
        # modal form doesn't provide all attributes of the UserCiJob model.
        # The widget's attributes are copied to a dictionary and then
        # the values from the form data are used to update the dictionary.

        for key in ['displayname', 'jobname', 'ci_server']:
            if key in new_data:
                old_data[key] = new_data[key]

        # If these checkboxes are unchecked, the field is not returned
        # from the form, therefore in order to update them from the
        # edit widget modal we check if they exist in the POST data at all.

        for key in ['entity_active', 'appletv', 'appletv_active']:
            if key in new_data:
                if new_data[key] != "current":
                    old_data[key] = True
            else:
                old_data[key] = False

        # If the form provides a new CiServer hostname a new model object is
        # created and then the ci_server value is changed in the form data to match.

        if 'new_ci_server' in new_data and not new_data['new_ci_server'] == '':
            job = RetrieveJob(append_http(new_data['new_ci_server']), None)
            if job.lookup_hostname(False):
                newserver = models.CiServer(hostname=new_data['new_ci_server'])
                newserver.save()
                old_data['ci_server'] = newserver.hostname

        form = forms.UserCiJobForm(old_data, instance=widget)
        if form.is_valid():
            form.save()
        else:
            print form.errors

    return HttpResponseRedirect('/')
예제 #13
0
파일: views.py 프로젝트: aboarya/bvd
def validate_hostname(request):
    job = RetrieveJob(append_http(request.POST.get('hostname',None)),None)
    print(request.POST.get('username') == 'Username')
    test = job.lookup_hostname(request.POST.get('username') != 'Username', request.POST.get('username'), request.POST.get('password1'))
    
    if test == urllib2.URLError:
        result = dict(status = 500)
    elif test == ValueError:
        result = dict(status = 404)
    elif test == 403: #autherization required
        result = dict(status = 403)
    elif test == 401: #invalid cerendtials
        result = dict(status = 401)
    else:
        result = dict(status = 200)
    
    return HttpResponse(simplejson.dumps([result]), content_type = 'application/javascript')
예제 #14
0
파일: views.py 프로젝트: webiken/bvd
def validate_hostname(request):
    job = RetrieveJob(append_http(request.POST.get('hostname',None)),None)
    print request.POST.get('username') == 'Username'
    test = job.lookup_hostname(request.POST.get('username') != 'Username', request.POST.get('username'), request.POST.get('password1'))
    
    if test == urllib2.URLError:
        result = dict(status = 500)
    elif test == ValueError:
        result = dict(status = 404)
    elif test == 403: #autherization required
        result = dict(status = 403)
    elif test == 401: #invalid cerendtials
        result = dict(status = 401)
    else:
        result = dict(status = 200)
    
    return HttpResponse(simplejson.dumps([result]), content_type = 'application/javascript')
예제 #15
0
파일: views.py 프로젝트: aboarya/bvd
def pull_jobs(request, *args, **kwargs):
    
    if request.user.is_authenticated():
        list = get_jobs_for_user(request.user)
        for job in list:
            jenkins = RetrieveJob(job['hostname'],job['jobname'])
            result = jenkins.lookup_job()

            if result == urllib2.HTTPError:
                jenkins = RetrieveJob(job['hostname'],job['jobname'])
                result = jenkins.lookup_job(True, settings.JENKINS_USER, settings.JENKINS_PASS)

            
            if result == urllib2.URLError:
                #TODO: add an additional state other than down 
                job['status'] = "DOWN"

            elif result == ValueError:
                #TODO: add an additional state other than down
                job['status'] = "DOWN"
            elif not result['status']:
                job['status'] = 'SUCCESS'
            else:
                job['status'] = result['status'] 

            
        return HttpResponse(simplejson.dumps([dict(status = 200, jobs = list)]), content_type = 'application/json')