Exemplo n.º 1
0
Arquivo: views.py Projeto: 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')
Exemplo n.º 2
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)]))
Exemplo n.º 3
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)]))
Exemplo n.º 4
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('/')
Exemplo n.º 5
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('/')
Exemplo n.º 6
0
Arquivo: views.py Projeto: 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')