def find(self, tags, extension=None): if not self.extended_data: self.init_download() log.debug("Looking for tags: {}".format(tags)) artifacts = self.artifacts if extension: artifacts = [a for a in self.artifacts if a.extension == extension] for tag in tags or []: tag = canonify(tag) artifacts = [a for a in artifacts if tag in a.tags] # Have to force evaluation using list comprehension, # since we are overwriting artifacts return artifacts
def filter_artifacts(artifacts, tags, extension): if extension: artifacts = [a for a in artifacts if a.extension == extension] log.debug("Looking for tags: {}".format(tags)) log.debug("In artifacts: {}".format(artifacts)) for tag in tags or []: tag = canonify(tag) new_artifacts = [a for a in artifacts if tag in a.tags] # Have to force evaluation using list comprehension, # since we are overwriting artifacts if len(new_artifacts) > 0: artifacts = new_artifacts log.debug("Found artifacts: {}".format(artifacts)) return artifacts
def __init__(self, data, filename=None): if filename and not data: data = {} data["URL"] = "./" + filename data["Title"] = "" data["Arch"] = None if "sparc" in filename.lower(): data["Arch"] = "spar" self.data = data self.url = data["URL"] self.title = data["Title"] self.arch = canonify(data["Arch"]) self.filename = basename(self.url) self.extension = splitext(self.filename)[1] self.tags = ["any"] self.create_tags()
def add_tag(self, string): assert type(string) is str canonified = canonify(string) if canonified not in self.tags: self.tags.append(canonified)