示例#1
0
    def get(self, request, *args, **kwargs):
        server = "192.168.174.128"
        remotepath = "/home/redhat/tomcat-8.5.14"
        try:
            dirlist = remotepath.split("/")
            templist = dirlist[1:]
            count = remotepath.count("/")
            alldir = []
            pwddir = ""
            for l in range(count):
                i = 1
                tempdir = ""
                for i in range(i):
                    tempdir = "/" + templist[l]
                    pwddir += tempdir
                    i += 1
                alldir.append(pwddir)

                content = Contentinfo(name=pwddir,
                                      type=1,
                                      superid=0,
                                      serverid=server,
                                      changeflag=0,
                                      oldproperty=0,
                                      newproperty=0,
                                      flag=0,
                                      writetime='00')
                content.save()

            return redirect(reverse('contentinfo:contentinfo_list'))
        except:
            traceback.print_exc()
示例#2
0
def getDataDict(contentdict={}):
    #获取目录下的所有目录和文件属性
    content = Contentinfo.objects.get(absname=contentdict["absname"])
    childcontents = Contentinfo.Children(content)
    global datadepth
    for childcontent in childcontents:
        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)
            getDataDict(temp_contentdict)
            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)

    return contentdict
示例#3
0
    def initContent(self):
        from modules.contentinfo.models import Contentinfo

        filelist = self.getDirContent(r"/")
        for f in filelist:
            if S_ISDIR(f.st_mode):
                ftype = 1
            else:
                ftype = 2
            try:
                content = Contentinfo.objects.get(absname="/" + f.filename,
                                                  serverid=self.ip)
            except:
                content = None
            if content:
                content.writetime = datetime.datetime.now()
                content.save()
            else:
                content = Contentinfo(name=f.filename,
                                      absname="/" + f.filename,
                                      ftype=ftype,
                                      superid="/",
                                      serverid=self,
                                      changeflag=0,
                                      oldproperty="",
                                      newproperty="",
                                      checkflag=0,
                                      writetime=datetime.datetime.now())
                content.save()
        return []
示例#4
0
    def syncContent(self, remotepath):
        from modules.contentinfo.models import Contentinfo

        print "11111111111111111"

        filelist = self.formatRemotepath(remotepath)
        for file in filelist:
            print "FFFFFFFFFFFF", file["absname"]
            try:
                content = Contentinfo.objects.get(absname=file["absname"])
            except:
                content = None
            if content:
                if content.oldproperty == file["st_mtime"]:
                    content.changeflag = 0
                else:
                    content.changeflag = 2
            else:
                content = Contentinfo(name=file["name"],
                                      absname=file["absname"],
                                      ftype=file["ftype"],
                                      superid=file["parent"],
                                      serverid=self,
                                      changeflag=1,
                                      oldproperty=0,
                                      newproperty=file["st_mtime"],
                                      checkflag=1,
                                      writetime=datetime.datetime.now())
            content.save()

        return "syncContent==============="
示例#5
0
    def initPathContent(self, remotepath):
        from modules.contentinfo.models import Contentinfo

        filelist = []
        count = remotepath.count("/")
        for l in range(count):
            dirdict = {}
            i = remotepath.rfind("/")
            if i == 0:
                dirdict["superid"] = "/"
            else:
                dirdict["superid"] = remotepath[:i]
            dirdict["name"] = remotepath[i + 1:]
            dirdict["absname"] = remotepath
            remotepath = remotepath[:i]
            filelist.append(dirdict)
        for file in filelist:
            try:
                content = Contentinfo.objects.get(absname=file["absname"], serverid=self)
            except:
                content = None
            if not content:
                content = Contentinfo(name=file["name"], absname=file["absname"], ftype=1,
                                      superid=file["superid"],
                                      serverid=self, changeflag=0,
                                      oldproperty="",
                                      newproperty="", checkflag=0, writetime=datetime.datetime.now())
                content.save()

        return "initPathContent==============="
示例#6
0
    def syncContent(self, remotepath):
        from modules.contentinfo.models import Contentinfo
        #初始化同步的目录
        self.initPathContent(remotepath)

        filelist = self.formatRemotepath(remotepath)
        for file in filelist:
            filestr = str(file["st_mtime"])
            try:
                content = Contentinfo.objects.get(absname=file["absname"], serverid=self)
            except:
                content = None
            if content:
                if content.newproperty == filestr:
                    content.changeflag = "0"
                else:
                    content.changeflag = "2"
                    content.oldproperty = content.newproperty
                content.newproperty = filestr
                content.writetime = datetime.datetime.now()
            else:
                content = Contentinfo(name=file["name"], absname=file["absname"], ftype=file["ftype"],
                                      superid=file["parent"],
                                      serverid=self, changeflag=1,
                                      oldproperty=0,
                                      newproperty=filestr, checkflag=1, writetime=datetime.datetime.now())
            content.save()

        return "syncContent==============="
def testA(contentdict={}):
    #获取目录下的所有目录和文件属性
    content = Contentinfo.objects.get(contentdict["absname"])
    childcontents = Contentinfo.Children(content)

    for childcontent in childcontents:
        temp_contentdict = {}
        if Contentinfo.Children(childcontents):
            temp_contentdict["name"] = childcontent.name
            temp_contentdict["absname"] = childcontent.absname
            temp_contentdict["childrens"] = []
            contentdict["childrens"].append(temp_contentdict)
            testA(temp_contentdict)
        else:
            temp_contentdict["name"] = childcontent.name
            temp_contentdict["absname"] = childcontent.absname
            temp_contentdict["childrens"] = []
            contentdict["childrens"].append(temp_contentdict)

    return contentdict
示例#8
0
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
示例#9
0
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
示例#10
0
# coding=utf-8

import datetime
import random
from modules.contentinfo.models import Contentinfo
from modules.serverinfo.models import Serverinfo

originStr = "abcdefghijklmnopqrstuvwxyz"
serverobj = Serverinfo.objects.all()[0]

for i in range(10000000):
    r = random.randint(1, 23)
    namestr = originStr[0:r] + "==" + str(i)
    # print namestr, 'IIIIIIIIIIIIIIIII', i
    content = Contentinfo(name=namestr,
                          absname=namestr,
                          ftype=namestr,
                          superid=namestr,
                          serverid=serverobj,
                          changeflag=namestr,
                          oldproperty=namestr,
                          newproperty=namestr,
                          checkflag=0,
                          writetime=datetime.datetime.now())
    content.save()
示例#11
0
            temp_contentdict["childrens"] = []
            contentdict["childrens"].append(temp_contentdict)
        else:
            temp_contentdict["name"] = content.filename
            temp_contentdict[
                "absname"] = contentdict["absname"] + content.filename
            temp_contentdict["ftype"] = 2
            temp_contentdict["childrens"] = []
            contentdict["childrens"].append(temp_contentdict)

    return contentdict


Adict = testA(rootdict)

print '=========', Adict

content = Contentinfo(name=rootdict["name"],
                      type=1,
                      superid=0,
                      serverid=0,
                      changeflag=0,
                      oldproperty=0,
                      newproperty=0,
                      checkflag=0,
                      writetime='00')
content.save()

for root in rootdict["childrens"]:
    pass