def show_distributions(self): """ Show available distributions for each index. """ if len(self.requirements) == 0: msg = StringIO() msg.write('show: Either specify requirements, or else' '--fetch-site-packages .\n\n') msg.write(self.usage) raise ValueError(msg.getvalue()) for index_url in self.options.index_urls: self.blather('=' * 50) self.blather('Package index: %s' % index_url) self.blather('=' * 50) index = self.index_factory(index_url=index_url) index.prescan() for rqmt in self.requirements: index.find_packages(rqmt) self.blather('Candidates: %s' % rqmt) for dist in self._findAll(index, rqmt): self.blather('%s: %s' % (dist.project_name, dist.location)) # TODO: implement ``--find-links`` logic. self.blather('=' * 50)
def move_to_pool(self): """ Move archives the pool directory and create symlinks. Ignore any archives which are already symlinks. """ if self.pool_dir is None: msg = StringIO() msg.write('No pool_dir!\n\n') msg.write(self.usage) raise ValueError(msg.getvalue()) all, pending = self.listArchives() if len(all) == 0: raise ValueError('No non-link archives in release dir: %s' % self.release_dir) if not os.path.exists(self.pool_dir): self.blather('Created new pool dir %s' % self.pool_dir) os.makedirs(self.pool_dir) if not os.path.isdir(self.pool_dir): raise ValueError('Pool dir is not a directory: %s' % self.pool_dir) for archive in pending: source = os.path.join(self.release_dir, archive) target = os.path.join(self.pool_dir, archive) if not os.path.exists(target): shutil.move(source, target) self.blather('Moved %s to %s' % (source, target)) if os.path.exists(source): os.remove(source) os.symlink(target, source) return all, pending
def show_distributions(self): """ Show available distributions for each index. """ if len(self.requirements) == 0: msg = StringIO() msg.write("show: Either specify requirements, or else" "--fetch-site-packages .\n\n") msg.write(self.usage) raise ValueError(msg.getvalue()) for index_url in self.options.index_urls: self.blather("=" * 50) self.blather("Package index: %s" % index_url) self.blather("=" * 50) index = self.index_factory(index_url=index_url) index.prescan() for rqmt in self.requirements: index.find_packages(rqmt) self.blather("Candidates: %s" % rqmt) for dist in self._findAll(index, rqmt): self.blather("%s: %s" % (dist.project_name, dist.location)) # TODO: implement ``--find-links`` logic. self.blather("=" * 50)
def make_index(self, path=None): """ Build an index from a directory full of source distributions. `path`, if passed, overrides the value set from the command line. """ if path is None: path = self.path if not os.path.isdir(path): msg = StringIO() msg.write('Not a directory: %s\n\n' % path) msg.write(self.usage) raise ValueError(msg.getvalue()) index_dir = os.path.join(path, self.options.index_name) if os.path.exists(index_dir): raise ValueError('Index directory exists: %s' % index_dir) self.blather('=' * 50) self.blather('Building index: %s' % index_dir) self.blather('=' * 50) projects = {} candidates = os.listdir(path) for candidate in candidates: cname = os.path.join(path, candidate) if not os.path.isfile(cname): continue project, revision = self._extractNameVersion(cname) if project is not None: projects.setdefault(project, []).append((revision, candidate)) items = sorted(projects.items()) if len(items) == 0: raise ValueError('No distributions in %s' % path) os.makedirs(index_dir) index_html = os.path.join(index_dir, 'index.html') top = open(index_html, 'w') top.writelines(['<html>\n', '<body>\n', '<h1>Package Index</h1>\n', '<ul>\n']) for key, value in items: self.blather('Project: %s' % key) dirname = os.path.join(index_dir, key) os.makedirs(dirname) top.write('<li><a href="%s">%s</a></li>\n' % (key, key)) sub_html = os.path.join(index_dir, key, 'index.html') sub = open(sub_html, 'w') sub.writelines(['<html>\n', '<body>\n', '<h1>%s Distributions</h1>\n' % key, '<ul>\n']) for revision, archive in value: self.blather(' -> %s, %s' % (revision, archive)) sub.write('<li><a href="../../%s">%s</a></li>\n' % (archive, archive)) sub.writelines(['</ul>\n', '</body>\n', '</html>\n']) sub.close() top.writelines(['</ul>\n', '</body>\n', '</html>\n']) top.close()
def download_distributions(self): """ Collect best sdist candidate for each requirement into a tempdir. Search each index and find-links URL provided in command options. Report results using the logger. """ # XXX ignore same-name problem for now if len(self.requirements) == 0: msg = StringIO() msg.write('fetch: Either specify requirements, or else ' '--fetch-site-packages .\n\n') msg.write(self.usage) raise ValueError(msg.getvalue()) if not os.path.exists(self.path): os.makedirs(self.path) if not os.path.isdir(self.path): msg = StringIO() msg.write('Not a directory: %s\n\n' % self.path) msg.write(self.usage) raise ValueError(msg.getvalue()) self.blather('=' * 50) self.blather('Scanning indexes for requirements') self.blather('=' * 50) results = {} for index_url in self.options.index_urls: self.blather('Package index: %s' % index_url) index = self.index_factory(index_url=index_url) source_only = self.options.source_only for rqmt in self.requirements: if results.get(rqmt, False): continue try: dist = index.fetch_distribution(rqmt, self.tmpdir, source=source_only) except Exception as e: self.error(' Error fetching: %s' % rqmt) self.blather(' %s' % e) results[rqmt] = False else: self.blather(' Searched for %s; found: %s' % (rqmt, (dist is not None))) results[rqmt] = (dist is not None) if self.options.find_links: self.blather('=' * 50) self.blather('Scanning find-links for requirements') index = self.index_factory() for find_link in self.options.find_links: index.add_find_links([find_link]) self.blather(' ' + find_link) self.blather('=' * 50) for rqmt in self.requirements: if results.get(rqmt, False): continue dist = index.fetch_distribution(rqmt, self.tmpdir, source=source_only) self.blather(' Searched for %s; found: %s' % (rqmt, (dist is not None))) results[rqmt] = (dist is not None) self.blather('=' * 50) self.blather('Merging indexes') self.blather('=' * 50) local_index = os.path.join(self.tmpdir) local = self.index_factory(index_url=local_index, search_path=(), # ignore installed! ) for rqmt in self.requirements: try: dist = local.fetch_distribution(rqmt, self.tmpdir, force_scan=True) except Exception: dist = None if dist is not None: shutil.copy(dist.location, self.path) self.blather('=' * 50) self.blather('Final Results') self.blather('=' * 50) found = [k for k, v in results.items() if v] notfound = [k for k, v in results.items() if not v] self.blather('Found eggs:') for x in found: self.blather(' ' + str(x)) self.blather('Not found eggs:') for x in notfound: self.blather(' ' + str(x))