Exemplo n.º 1
0
    def nodeGroup(self, orm, dir, category):
        tag = tagAccess.findby1name(orm, category)

        controlNodes = []
        fsNodes = []
        for node in tag.nodes:
            controlNodes.append(node)
            if os.path.isdir("%s/%s" % (dir, node.host)):
                fsNodes.append(node.utf8("host"))

        return (controlNodes, fsNodes)
Exemplo n.º 2
0
    def getGraphLinks(self, orm, basedir, target, category, type, extensions=[".png", ".dat"], prefix="/graph"):
        ret = []
        _tags = []

        if type == "group" or type == "compare":
            hosts = target.split(",")
            if 1 < len(hosts):
                _tags = hosts

        elif type == "tag":
            # tag
            tags = tagAccess.findby1name(orm, target)
            for tag in tags.nodes:
                _tags.append(tag.host)
        else:
            # host
            _tags.append(target)

        for host in _tags:
            data = {}
            data["name"] = host
            hostdir = "%s/%s" % (basedir, host)
            if os.path.isdir(hostdir) is False:
                continue

            links = []

            for f in os.listdir(hostdir):
                regx = "^("+category+")"
                if re.search(regx, f):
                    link = {}
                    link["url"] = "%s/%s/%s" % (prefix, host, f)
                    link["name"] = f
                    link["type"] = []
                    for t in os.listdir("%s/%s" % (hostdir, f)):
                        link["type"].append(os.path.splitext(t)[0].replace(category+"-", ""))

                    links.append(link)

            data["links"] = links
            data["extensions"] = extensions
            ret.append(data)

        if type != "compare":
            return ret
        
        return convertCompare(ret, target, prefix)
Exemplo n.º 3
0
    def tagList(self, orm, directory, category, prefix):
        ret = {
            "node": {},
            "all": []
            }

        if os.path.isdir(directory) is False:
            return ret

        tag = tagAccess.findby1name(orm, category)

        if tag is None:
            return ret

        for node in tag.nodes:
            host = node.host
            target = "%s/%s" % (directory, host)
            ret["node"][host] = {}

            if os.path.isdir(target) is False:
                continue

            categorys = os.listdir(target)

            if prefix is False:
                categorys.sort()
                ret["node"][host]["category"] = category
            else:
                alist = []
                plist = []
                for category in categorys:
                    idx = category.find("-")
                    if idx != -1:
                        plist.append(category[:idx])
                    else:
                        plist.append(category)

                plist = list(set(plist))
                plist.sort()
                ret["node"][host]["category"] = plist
                alist = alist+plist
                alist = list(set(alist))
                alist.sort()
                ret["all"] = alist

        return ret
Exemplo n.º 4
0
    def add(self, orm, me, host, note, categorys, tags):
        # tags -> listdir
        _tags = []
        for y in [x.strip() for x in tags.split(',') if x]:
            _tags.append(y)

        otags = None
        if _tags:
            _tags = sorted(_tags)
            otags = []
            for x in _tags:
                if tagAccess.countby1name(orm, x) == 0:
                    otags.append(Tag(x, categorys)) # New
                else:
                    otags.append(tagAccess.findby1name(orm, x)) # reuse

        notebook = NoteBook(note)
        node = Node(me, me, host, notebook, otags)
        return nodeAccess.add(orm, node)