class Repository(object): """Repository directory containing packages and index""" def __init__(self, path, name, pyver, osarch, url): from pypm.web.uptree import UpTree # XXX: put uptree out of 'web' self.path = path self.name = name self.pyver = pyver self.osarch = osarch self.url = url self.uptree = UpTree( self.path, content_cache_filenames=['info.json', 'imports'], mtime_cache_filenames=['log'], ) def _update_uptree(self): counters = self.uptree.update() # potentially long-operation if any(counters.values()): LOG.info('Uptree was updated: %s', counters) return counters def find_packages(self): """Return available packages in the repository""" LOG.info("Updating uptree for %s", self) self._update_uptree() LOG.info("Retrieving files via uptree for %s", self) return [p for p in self.uptree.get_files() if p.endswith('.pypm')] def find_all_packages(self): """Return all packages whether succeeded or failed Return a list of tuples of the form: (pkgfile, pkgdir, succeeded) where: pkgfile - path to the package file (may not exist) pkgdir - path to the package dir (.d/ directory) succeeded - True of the pkgfile exists """ self._update_uptree() processed = set() for fil in textui.ProgressBar.iterate(self.uptree.get_files(), note='Files'): if fil.endswith('.pypm'): pkgfile, pkgdir, succeeded = fil, fil + '.d', True elif fil.endswith('.pypm.d'): pkgfile, pkgdir = fil[:-2], fil succeeded = self.uptree.exists(pkgfile) else: continue if pkgfile not in processed: processed.add(pkgfile) yield pkgfile, pkgdir, succeeded def __str__(self): return '{0}<{1.path}>'.format(self.__class__.__name__, self)
def __init__(self, path, name, pyver, osarch, url): from pypm.web.uptree import UpTree # XXX: put uptree out of 'web' self.path = path self.name = name self.pyver = pyver self.osarch = osarch self.url = url self.uptree = UpTree( self.path, content_cache_filenames=['info.json', 'imports'], mtime_cache_filenames=['log'], )