| 28 | |
| 29 | |
| 30 | class TargetProfile: |
| 31 | instance = None |
| 32 | |
| 33 | @classmethod |
| 34 | def getInstance(cls): |
| 35 | if cls.instance is None: |
| 36 | cls.instance = TargetProfile() |
| 37 | |
| 38 | return cls.instance |
| 39 | |
| 40 | @staticmethod |
| 41 | def getUserTargetProfileList(): |
| 42 | return db.getTargetProfileList() |
| 43 | |
| 44 | @staticmethod |
| 45 | def getBuiltinTargetProfileList(): |
| 46 | return es_TargetProfile.getBuiltinList() |
| 47 | |
| 48 | @staticmethod |
| 49 | def newPattern(name): |
| 50 | p = es_TargetProfile() |
| 51 | p.rawName = name |
| 52 | db.save(p) |
| 53 | return p |
| 54 | |
| 55 | @staticmethod |
| 56 | def renamePattern(p, newName): |
| 57 | p.rawName = newName |
| 58 | db.save(p) |
| 59 | |
| 60 | @staticmethod |
| 61 | def deletePattern(p): |
| 62 | db.remove(p) |
| 63 | |
| 64 | @staticmethod |
| 65 | def copyPattern(p): |
| 66 | newP = copy.deepcopy(p) |
| 67 | db.save(newP) |
| 68 | return newP |
| 69 | |
| 70 | @staticmethod |
| 71 | def saveChanges(p): |
| 72 | db.save(p) |
| 73 | |
| 74 | def importPatterns(self, text): |
| 75 | imports, num = es_TargetProfile.importPatterns(text) |
| 76 | lenImports = len(imports) |
| 77 | |
| 78 | if lenImports == 0: |
| 79 | raise ImportError("No patterns found for import") |
| 80 | if lenImports != num: |
| 81 | raise ImportError("%d patterns imported from clipboard; %d had errors" % (num, num - lenImports)) |
| 82 | |
| 83 | def exportPatterns(self): |
| 84 | patterns = self.getUserTargetProfileList() |
| 85 | patterns.sort(key=lambda p: p.fullName) |
| 86 | return es_TargetProfile.exportPatterns(*patterns) |
no outgoing calls
no test coverage detected