def patchtool_index(request): running = is_running('/usr/local/bin/tklpatch') if running != '': return HttpResponseRedirect('status/') baseimages = list_images() patches = list_patches() return render_to_response('patchtool/index.html', {"baseimages": baseimages, "patches": patches, }, context_instance=RequestContext(request))
def get_image(request): running = is_running('/usr/local/bin/tklpatch-getimage') message='' if len(running) > 0: image = running.split()[3] else: if request.POST.has_key('image'): image = request.POST['image'] if os.path.exists('/srv/tklpatch/base-images/'+image+'.iso'): message = 'File '+image+'.iso already exists' else: Popen(['tklpatch-getimage',image]) else: return HttpResponseRedirect('/baseimages') return render_to_response('baseimages/getimage.html',{"image": image, "message": message})
def available_images(request): running = is_running('/usr/local/bin/tklpatch-getimage') if len(running) > 0: return HttpResponseRedirect('/baseimages/getimage/') if os.path.exists(settings.TKLPATCH_BASEIMAGES_FILE): imagelist = Popen(['tklpatch-getimage','--list'],stdout=PIPE).communicate()[0] imagelist = imagelist.split("\n") imagelist.pop() #Remove empty element baseimagelist = list_images() for x in baseimagelist: image = x[:-4] try: imagelist.remove(image) except: pass else: imagelist = '' return render_to_response('baseimages/listimages.html',{"imagelist": imagelist}, context_instance=RequestContext(request))
def status(request): lastpatch = last_patch_run() baseimage = lastpatch[0] patch = lastpatch[1] logfile = settings.TKLPATCH_LOGS_ROOT+baseimage+'-'+patch+'.log' log = '' try: with open(logfile, 'r') as f: for line in f: log += line except IOError: log = "Not available" running = is_running('/usr/local/bin/tklpatch') if len(running) > 0: status = 'Running' else: status = 'Stopped' return render_to_response('patchtool/status.html', {"baseimage": baseimage, "patch": patch, "status": status, "log": log, })
def refresh_list(request): running = is_running('/usr/local/bin/tklpatch-getimage') if len(running) > 0: return HttpResponseRedirect('/baseimages/getimage/') Popen(['tklpatch-getimage','--update']).wait() return HttpResponseRedirect('/baseimages/listimages')