def edit_project(request): """ Edit Project Command API :param request: :return: """ data = request.POST command = data.get("command") group = data.get("group") name = data.get("project") timeout = data.get("timeout") status = data.get("status") priority = data.get("priority") info = data.get("info") script = data.get("script") interval = data.get("interval") number = data.get("number") ip_limit = data.get("ip_limit") if command and name and (group or timeout or status or priority or info or script or interval or number or ip_limit): handler = Handler() result = handler.edit_project_settings(data) else: result = { "status": False, "project": name, "message": "Bad Parameters", "code": 4001, } return result
def task_project(request): """ Query Projcet Result Command API :param request: :return: """ name = request.GET.get("project") page = int(request.GET.get("page", '1')) rows = int(request.GET.get("rows", '10')) if name and page > 0 and rows > 0: handler = Handler() _result = handler.query_task_by_name(name, page, rows) result = { "status": True, "project": name, "result": _result, "message": "Query Result Succeed!", "code": 2001, } else: result = { "status": False, "project": name, "message": "Bad Parameters", "code": 4001, } return result
def create_project(request): """ Create Project Command API :param request: :return: """ name = request.POST.get("project") command = request.POST.get("command") url = request.POST.get("url") if name and command: handler = Handler() if url is not None: url = url.strip() result = handler.create_project(name, url) else: result = handler.create_project(name) else: result = { "status": False, "project": name, "message": "Bad Parameters", "code": 4001, } return result
def run_query_project_status(): """ Run Query Project Status to Redis :return: """ handler = Handler() results = handler.query_all_projects_status("--all") print "[{0}]::Analysis Dispatch::{1} Updated Success".format( str(datetime.datetime.now())[:-4], len(results))
def data(request): """ Data index page :param request: :return: """ handler = Handler() projects = handler.query_projects_status_by_redis() return render_to_response("data.html", {"projects": projects})
def nodes(request): """ API index page :param request: :return: """ handler = Handler() nodes = handler.query_nodes_in_redis(node='--all') # return nodes return render_to_response("nodes.html", {'nodes': nodes})
def debug(request, name): """ Debug index page :param request: :return: """ handler = Handler() projects = handler.query_projects_status_by_redis(name=name) project = projects[0] return render_to_response("debug.html", {'project': project})
def node(request, name): """ API index page :param request: :return: """ # name = request.GET.get('node') # print 'node: ', name handler = Handler() nodes = handler.query_nodes_in_redis(node=name) return nodes
def task(request, name): """ Task index page :param request: :return: """ if name is not None: handler = Handler() projects = handler.query_projects_status_by_redis(name=name) return render_to_response("task.html", {"project": projects[0]}) else: return
def _get_iplimit(self): """ :return: a_dict """ handler = Handler() projects = handler.query_projects_status_by_redis( name=self.project_name) if not projects: return {"status": False, "message": "Project does not exist."} else: iplimit = projects[0].get("iplimit", 60) limit = projects[0].get("limit", 60) return { "status": True, "iplimit": iplimit, "downloader_limit": limit }
def log(request, name, task_id): """ Task index page :param request: :return: """ if name is not None: handler = Handler() task = handler.query_task_by_task_id(name=name, task_id=task_id) print task return render_to_response("log.html", { "task": task["task"], 'log': task }) else: return
def run_project(request): """ Run Projcet Generator Command API :param request: :return: """ name = request.POST.get("project") command = request.POST.get("command") task = request.POST.get("task") if name and command and task: handler = Handler() result = handler.run_processor(name, json.loads(task)) elif name and command: handler = Handler() result = handler.run_generator(name) else: result = { "status": False, "project": name, "message": "Bad Parameters", "code": 4001, } return result
def index(request): """ Dashboard Index Page :param request: :return: """ handler = Handler() projects = handler.query_projects_status_by_redis() for project in projects: if project['total'] >= 0 and project['total'] != project['new']: _task_num = float(project['total'] - project['new']) project['success_rate'] = round( 100 * project['success'] / _task_num, 2) project['failed_rate'] = round(100 * project['failed'] / _task_num, 2) project['invalid_rate'] = round( 100 * project['invalid'] / _task_num, 2) project['schedule'] = round((_task_num / project['total']) * 100, 2) else: project['succ_rate'] = 0 project['failed_rate'] = 0 project['invalid_rate'] = 0 project['schedule'] = 0 if project['total_d'] >= 0 and project['total_d'] != project['new_d']: _task_num = float(project['total_d'] - project['new_d']) project['success_rate_d'] = round( 100 * project['success_d'] / _task_num, 2) project['failed_rate_d'] = round( 100 * project['failed_d'] / _task_num, 2) project['invalid_rate_d'] = round( 100 * project['invalid_d'] / _task_num, 2) project['schedule_d'] = round( (_task_num / project['total_d']) * 100, 2) else: project['succ_rate_d'] = 0 project['failed_rate_d'] = 0 project['invalid_rate_d'] = 0 project['schedule_d'] = 0 if project['total_h'] >= 0 and project['total_h'] != project['new_h']: _task_num = float(project['total_h'] - project['new_h']) project['success_rate_h'] = round( 100 * project['success_h'] / _task_num, 2) project['failed_rate_h'] = round( 100 * project['failed_h'] / _task_num, 2) project['invalid_rate_h'] = round( 100 * project['invalid_h'] / _task_num, 2) project['schedule_h'] = round( (_task_num / project['total_h']) * 100, 2) else: project['succ_rate_h'] = 0 project['failed_rate_h'] = 0 project['invalid_rate_h'] = 0 project['schedule_h'] = 0 if project['total_m'] >= 0 and project['total_m'] != project['new_m']: _task_num = float(project['total_m'] - project['new_m']) project['success_rate_m'] = round( 100 * project['success_m'] / _task_num, 2) project['failed_rate_m'] = round( 100 * project['failed_m'] / _task_num, 2) project['invalid_rate_m'] = round( 100 * project['invalid_m'] / _task_num, 2) project['schedule_m'] = round( (_task_num / project['total_m']) * 100, 2) else: project['succ_rate_m'] = 0 project['failed_rate_m'] = 0 project['invalid_rate_m'] = 0 project['schedule_m'] = 0 return render_to_response("index.html", { 'projects': projects, 'tasks': None, 'profile': None, })
def test_query_nodes_in_redis_2(self): handler = Handler() result = handler.query_nodes_in_redis() print result