def get(self, request, *args, **kwargs): try: param_list = Systeminfo.objects.all() print Systeminfo.get_param("site_name") template_name = "systeminfo_list.html" return render_to_response(template_name, {"param_list": param_list}, context_instance=RequestContext(request)) except: traceback.print_exc()
def get(self, request, *args, **kwargs): name = "QiaoTest" ip = "192.168.174.128" port = 22 username = "******" password = "******" try: server = Systeminfo(name, ip, port, username, password) server.save() # server.initContent() return redirect(reverse('systeminfo:systeminfo_list')) except: traceback.print_exc()
def post(self, request, *args, **kwargs): template_name = "systeminfo_param.html" try: result_dict = {} param_name = request.POST.get("name", "") param_value = request.POST.get("newvalue", "") try: Systeminfo.objects.filter(param_name=param_name).update( param_value=param_value) Systeminfo.update_system_cache() result_dict["msg"] = "设置成功!" except: result_dict["msg"] = "设置失败!" return HttpResponse(json.dumps(result_dict), content_type="application/json") except: traceback.print_exc()
def getDataDict_gh(contentdict={}, serverid=1): #获取目录下的所有目录和文件属性 content = Contentinfo.objects.get(absname=contentdict["absname"], serverid=serverid) content_absname = str(content.absname) # 根据绝对路径字符串匹配,判断当前目录是否大于5层,如果大于,则不再寻找子节点。 if len(content_absname.replace(rootname, '', 1).split('/')) >= 5: return childcontents = Contentinfo.Children(content) nodemaximum = Systeminfo.get_param_value("nodemaximum", "1") if nodemaximum: nodemaximum = int(nodemaximum) else: nodemaximum = 10 if childcontents.count() > nodemaximum: childcontents = childcontents[:nodemaximum] #global depthlist global nodenumber global normalnodenumber global addnodenumber global changenodenumber global deletenodenumber for childcontent in childcontents: changeflag = random.randint(0, 4) temp_contentdict = {} # 非叶子节点 if Contentinfo.Children(childcontent): #print str(childcontent.absname) temp_contentdict["name"] = str(childcontent.name) temp_contentdict["absname"] = str(childcontent.absname) temp_contentdict["ftype"] = str(childcontent.ftype) temp_contentdict["changeflag"] = str(childcontent.changeflag) temp_contentdict["children"] = [] contentdict["children"].append(temp_contentdict) nodenumber += 1 if childcontent.changeflag == "0": normalnodenumber += 1 elif childcontent.changeflag == "1": addnodenumber += 1 elif childcontent.changeflag == "2": changenodenumber += 1 elif childcontent.changeflag == "3": deletenodenumber += 1 getDataDict_gh(temp_contentdict, serverid) # 叶子结点 else: temp_contentdict["name"] = str(childcontent.name) temp_contentdict["absname"] = str(childcontent.absname) temp_contentdict["ftype"] = str(childcontent.ftype) temp_contentdict["changeflag"] = str(childcontent.changeflag) temp_contentdict["children"] = [] contentdict["children"].append(temp_contentdict) nodenumber += 1 if childcontent.changeflag == "0": normalnodenumber += 1 elif childcontent.changeflag == "1": addnodenumber += 1 elif childcontent.changeflag == "2": changenodenumber += 1 elif childcontent.changeflag == "3": deletenodenumber += 1 return contentdict
def getDataDict(contentdict={}, serverid=1): #获取目录下的所有目录和文件属性 content = Contentinfo.objects.get(absname=contentdict["absname"], serverid=serverid) childcontents = Contentinfo.Children(content) nodemaximum = Systeminfo.get_param_value("nodemaximum", "1") if nodemaximum: nodemaximum = int(nodemaximum) else: nodemaximum = 10 if childcontents.count() > nodemaximum: childcontents = childcontents[:nodemaximum] global datadepth global depthlist global nodenumber global normalnodenumber global addnodenumber global changenodenumber global deletenodenumber for childcontent in childcontents: if datadepth > 5: continue changeflag = random.randint(0, 4) temp_contentdict = {} # 非叶子节点 if Contentinfo.Children(childcontent): temp_contentdict["name"] = str(childcontent.name) temp_contentdict["absname"] = str(childcontent.absname) temp_contentdict["ftype"] = str(childcontent.ftype) temp_contentdict["changeflag"] = str(childcontent.changeflag) temp_contentdict["children"] = [] contentdict["children"].append(temp_contentdict) nodenumber += 1 if childcontent.changeflag == "0": normalnodenumber += 1 elif childcontent.changeflag == "1": addnodenumber += 1 elif childcontent.changeflag == "2": changenodenumber += 1 elif childcontent.changeflag == "3": deletenodenumber += 1 if childcontent.absname not in depthlist: depthlist.append(childcontent.absname) getDataDict(temp_contentdict, serverid) if childcontent.superid not in depthlist: datadepth += 1 # 叶子结点 else: temp_contentdict["name"] = str(childcontent.name) temp_contentdict["absname"] = str(childcontent.absname) temp_contentdict["ftype"] = str(childcontent.ftype) temp_contentdict["changeflag"] = str(childcontent.changeflag) temp_contentdict["children"] = [] contentdict["children"].append(temp_contentdict) nodenumber += 1 if childcontent.changeflag == "0": normalnodenumber += 1 elif childcontent.changeflag == "1": addnodenumber += 1 elif childcontent.changeflag == "2": changenodenumber += 1 elif childcontent.changeflag == "3": deletenodenumber += 1 return contentdict
def get_system_param(param_name): try: return Systeminfo.get_param(param_name).get(param_name, "") except: traceback.print_exc() return ""