def kill_task(request, id): if request.POST: task_manager = get_process_manager() task_manager.kill_thread(int(id)) return {'POST': "RETURN_OK"} else: task_manager = get_process_manager() object = task_manager.thread_info(int(id)) messages = task_manager.get_messages(int(id)) return {'object': object, 'messages': messages}
def put(request): fun = request.POST.get("func", "") title = request.POST.get("title", "") username = request.POST.get("username", "guest") param = json_loads(request.POST.get("param", "{}")) ret = get_process_manager().put(username, title, fun, **param) return HttpResponse(json_dumps(ret), content_type="application/json")
def run_python_shell_task_base(request, base_path, prj_name): command = "from app_sets.%s.manage import *" % prj_name pconsole = settings.PYTHON_CONSOLE.split(' ') pconsole[0]=">>>" + pconsole[0] pconsole.append('-i') pconsole.append('-c') pconsole.append(command) param = ["python-shell",] + pconsole id = get_process_manager().put(request, *param) return id
def thread_info(request): id = request.POST.get("id", 0) pos = get_process_manager().thread_info(int(id)) elem = {} elem['id'] = pos.id elem['title'] = pos.title elem['status'] = pos.status elem['username'] = pos.username elem['time_from'] = pos.time_from elem['time_to'] = pos.time_to return HttpResponse(json_dumps(elem), content_type="application/json")
def list_threads(request): id = request.POST.get("id", 0) ret = get_process_manager().list_threads(int(id)) ret2 = [] for pos in ret: elem = {} elem['id'] = pos.id elem['title'] = pos.title elem['status'] = pos.status elem['username'] = pos.username elem['time_from'] = pos.time_from elem['time_to'] = pos.time_to ret2.append(elem) return HttpResponse(json_dumps(ret2), content_type="application/json")
def manage(request, pk): prj = models.SChAppSet.objects.get(id=pk) base_path = os.path.join(settings.PRJ_PATH, prj.name) src_path = os.path.join(settings.PRJ_PATH, "schdevtools") command = "import sys; sys.path.append('%s'); from manage import *" % base_path pconsole = settings.PYTHON_CONSOLE.split(' ') pconsole[0]=">>>" + pconsole[0] pconsole.append('-i') pconsole.append('-c') pconsole.append(command) param = ["python-shell",] + pconsole id = get_process_manager().put(request, *param) new_url = "../../../tasks/form/TaskListForm/%d/edit2__task" % id #new_url = "../../schsys/thread/%d/edit/" % id return HttpResponseRedirect(new_url)
def process(self, request, queryset=None): time_from = self.cleaned_data['time_from'] time_to = self.cleaned_data['time_to'] if time_from: _time_from = time_from.isoformat() else: _time_from = None if time_to: _time_to = time_to.isoformat() else: _time_to = None if request.user.is_authenticated: username = request.user.username else: username = '******' print("X1:", time_from, time_to) only_my = self.cleaned_data['only_my'] only_active = self.cleaned_data['only_active'] task_manager = get_process_manager() object_list = [] l = task_manager.list_threads(all=not only_active) for pos in l: test = True if time_from and pos['time_from'] < time_from: test = False if time_to and (not pos['time_to'] or pos['time_to'] > time_to): test = False if only_my and pos['username'] != username: test = False if test: object_list.append(pos) return { "object_list": object_list, 'time_from': _time_from, 'time_to': _time_to, 'only_my': only_my, 'only_active': only_active }
def wait_for_result(request): ret = get_process_manager().wait_for_result() return HttpResponse(json_dumps(ret), content_type="application/json")
def kill_all(request): id = request.POST.get("id", 0) ret = get_process_manager().kill_all(int(id)) return HttpResponse(json_dumps(ret), content_type="application/json")
def get_messages(request): id = request.POST.get("id", 0) id_start = request.POST.get("id_start", 0) ret = get_process_manager().get_messages(int(id), int(id_start)) return HttpResponse(json_dumps(ret), content_type="application/json")
def put_message(request): id = request.POST.get("id", 0) message = request.POST.get("message", "") ret = get_process_manager().put_message(int(id), message) return HttpResponse(json_dumps(ret), content_type="application/json")
def run_python_shell_task2(request): id = get_process_manager().put(request, "python-shell", "python3", '-i') new_url = make_href("../../schsys/thread/%d/edit/" % id) return HttpResponseRedirect(new_url)