Ejemplo n.º 1
0
    def importSets(self, text):
        sMkt = Market.getInstance()
        lines = text.splitlines()
        newSets = []
        errors = 0
        current = None
        lookup = {}

        for i, line in enumerate(lines):
            line = line.strip()
            try:
                if line == '' or line[0] == "#":  # comments / empty string
                    continue
                if line[:1] == "[" and line[-1:] == "]":
                    current = es_ImplantSet(line[1:-1])
                    newSets.append(current)
                else:
                    item = sMkt.getItem(line)
                    current.implants.append(es_Implant(item))
            except (KeyboardInterrupt, SystemExit):
                raise
            except:
                errors += 1
                continue

        for implant_set in self.getImplantSetList():
            lookup[implant_set.name] = implant_set

        for implant_set in newSets:
            if implant_set.name in lookup:
                match = lookup[implant_set.name]
                for implant in implant_set.implants:
                    match.implants.append(es_Implant(implant.item))
            else:
                eos.db.save(implant_set)

        eos.db.commit()

        lenImports = len(newSets)
        if lenImports == 0:
            raise ImportError("No patterns found for import")
        if errors > 0:
            raise ImportError("%d sets imported from clipboard; %d errors" %
                              (lenImports, errors))
Ejemplo n.º 2
0
    def importSets(self, text):
        sMkt = Market.getInstance()
        lines = text.splitlines()
        newSets = []
        errors = 0
        current = None
        lookup = {}

        for i, line in enumerate(lines):
            line = line.strip()
            try:
                if line == '' or line[0] == "#":  # comments / empty string
                    continue
                if line[:1] == "[" and line[-1:] == "]":
                    current = es_ImplantSet(line[1:-1])
                    newSets.append(current)
                else:
                    item = sMkt.getItem(line)
                    current.implants.append(es_Implant(item))
            except:
                errors += 1
                continue

        for implant_set in self.getImplantSetList():
            lookup[implant_set.name] = implant_set

        for implant_set in newSets:
            if implant_set.name in lookup:
                match = lookup[implant_set.name]
                for implant in implant_set.implants:
                    match.implants.append(es_Implant(implant.item))
            else:
                eos.db.save(implant_set)

        eos.db.commit()

        lenImports = len(newSets)
        if lenImports == 0:
            raise ImportError("No patterns found for import")
        if errors > 0:
            raise ImportError("%d sets imported from clipboard; %d errors" %
                              (lenImports, errors))
Ejemplo n.º 3
0
 def newSet(self, name):
     implant_set = es_ImplantSet()
     implant_set.name = name
     eds_queries.save(implant_set)
     return implant_set
Ejemplo n.º 4
0
 def newSet(name):
     implant_set = es_ImplantSet()
     implant_set.name = name
     eos.db.save(implant_set)
     return implant_set