def get_tag(tag, parent=None): if parent: return get_tag_with_parent(tag, parent) tags = [] for t in tag.split(" "): tags.append(t) return [f.strip() for f in sh.tmsu("files", "--", tags)]
def refresh_cache(self): self.cache = [] for tag in sh.tmsu("tags", "--all"): tag = tag.strip() if tag.find(":") > -1: subtags = tag.split(":") create_tag(self.cache, subtags) else: create_tag(self.cache, [tag])
def get_tag_with_parent(tag, parent): tags = [] for t in tag.split(" "): if t.startswith("%s:" % parent) or tag.startswith("-%s:" % parent): tags.append(t) elif t.startswith("-"): tags.append("-%s:%s" % (parent, t[1:])) else: tags.append("%s:%s" % (parent, t)) return [f.strip() for f in sh.tmsu("files", "--", tags)]
def remove_tag(self, tag, validator): # Function is idempotent, will not error for removing a tag or files # that have already been removed files = [f.strip() for f in sh.tmsu("files", "--", tag)] for fn in files: self.remove_file(fn, validator) try: tags.remove(tag) except: pass
def add_tag(self, tag, validator): files = [f.strip() for f in sh.tmsu("files", "--", tag)] for fn in files: self.add_file(fn, validator) self.tags.add(tag)