def __init__(self, spec): # These attributes are required for all packages. attr_required(self.__class__, 'homepage') attr_required(self.__class__, 'url') # this determines how the package should be built. self.spec = spec # Name of package is the name of its module (the file that contains it) self.name = inspect.getmodulename(self.module.__file__) # Make sure URL is an allowed type validate.url(self.url) # patch up the URL with a new version if the spec version is concrete if self.spec.versions.concrete: self.url = self.url_for_version(self.spec.version) # This is set by scraping a web page. self._available_versions = None # versions should be a dict from version to checksum, for safe versions # of this package. If it's not present, make it an empty dict. if not hasattr(self, 'versions'): self.versions = {} if not isinstance(self.versions, dict): raise ValueError("versions attribute of package %s must be a dict!" % self.name) # Version-ize the keys in versions dict try: self.versions = { Version(v):h for v,h in self.versions.items() } except ValueError: raise ValueError("Keys of versions dict in package %s must be versions!" % self.name) # stage used to build this package. self._stage = None # Set a default list URL (place to find available versions) if not hasattr(self, 'list_url'): self.list_url = None if not hasattr(self, 'list_depth'): self.list_depth = 1
def memory_iter(self): robot_nofollow = self.robot_archive_options + ['nofollow'] self.links = (link for i, link in enumerate(self.links) if validate.url( link) and not self.robots[i] in robot_nofollow) self.name = ["links"] for link in self.links: if link not in self.visited: yield {'links': link} self.visited.append(link)