62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
from django.apps import AppConfig
|
|
from django.http import HttpResponse
|
|
from django.shortcuts import render
|
|
from django.shortcuts import redirect
|
|
from jinja2 import Environment, FileSystemLoader
|
|
from django.core.files import File
|
|
from kubernetes import client, config
|
|
|
|
import time
|
|
import random
|
|
import mimetypes
|
|
import ruamel.yaml
|
|
import yaml
|
|
import urllib.request
|
|
|
|
def hello(request):
|
|
return HttpResponse('<h1>Hello stash!</h1>')
|
|
def form(request):
|
|
return render(request, 'stash_form.html',{})
|
|
|
|
def handle_survey_form(request):
|
|
config.load_kube_config(config_file='/kubeconfig/config')
|
|
v1 = client.BatchV1Api()
|
|
name = request.GET.get('name')
|
|
url = request.GET.get('url')
|
|
external_galleries = str(request.GET.get('external_galleries'))
|
|
|
|
stash_folder = "/stash"
|
|
|
|
if external_galleries:
|
|
print("external_galleries is not null")
|
|
performer_external_galleries = stash_folder+"/"+name+"_external_galleries.txt"
|
|
with open(performer_external_galleries, "a") as f:
|
|
f.write(external_galleries)
|
|
skip_searching_gallery = True
|
|
else:
|
|
print("external_galleries is null")
|
|
print("another")
|
|
skip_searching_gallery = False
|
|
|
|
with open('django_code/stash_management/templates/template.stash-pornpics-dowloader.job.yml', 'r') as file:
|
|
#get the manifest in a variable template_manifest from the manifest file
|
|
template_manifest = yaml.safe_load(file)
|
|
|
|
#edit the container name
|
|
template_manifest['metadata']['name'] ="stash-pornpics-dowloader-"+name
|
|
template_manifest['spec']['template']['spec']['containers'][0]['name'] ="stash-pornpics-dowloader-"+name
|
|
|
|
#edit the command based on the input
|
|
command=['bash', '/config/download.sh', '--http_proxy', 'http://gluetun-svc.gluetun.svc:8888', '--BASE_URL', url, '--pornstars', name]
|
|
template_manifest['spec']['template']['spec']['containers'][0]['command']=command
|
|
|
|
|
|
#execute based on the value
|
|
#api_response = v1.create_namespaced_job(body=template_manifest,namespace='stash')
|
|
return HttpResponse(template_manifest)
|
|
|
|
|
|
|
|
|
|
|