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')
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')
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)]))
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)]))
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)]))
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)]))
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)]))
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)]))