def install(self): self.success = False logger.info('Looking for {0} releases on PyPI', self.name) p = ReqManager(self) try: files = p.files() except (urllib2.URLError, urllib2.HTTPError) as e: raise InstallationError(repr(e.reason) if hasattr(e, 'reason') else e.msg) bad_eggs = [] for pext in ('.tar.gz', '.tar.bz2', '.zip', '.egg'): for v, name, hash, url in files[pext]: if pext == '.egg' and not right_egg(name): if args_manager['install']['force_egg_install']: bad_eggs.append( (url, name, p.name, hash) ) continue if ext(name) not in ('.tar.gz', '.tar.bz2', '.zip', '.egg') + WINDOWS_EXT: continue logger.info('Best match: {0}=={1}', self.name, v) try: self._download_and_install(url, name, p.name, hash) except InstallationError: logger.info('Trying another file (if there is one)...') continue if not self.version: self.version = v break if self.success: return if bad_eggs: self._check_bad_eggs(bad_eggs) if not self.success: raise InstallationError('Error: Cannot find files available for dowloading and installing')
def _download(self, dir, req): ''' Given a destination directory and a requirement to meet, download it and return the archive path. ''' manager = ReqManager(req, ('.tar.gz', '.tar.bz2', '.zip')) manager.download(dir) d_name, version = manager.downloaded_name, manager.downloaded_version arch_name = os.path.join(dir, d_name) unpack(arch_name) self.bundled.append('{0}=={1}'.format(name(d_name).split('-')[0], version)) return arch_name
def download_func(args): pref = None if args.prefer: pref = ['.' + args.prefer.strip('.')] name = args.packname dest = args_manager['download']['download_dir'] unpk = args_manager['download']['unpack'] downloader = ReqManager(Requirement(name), pref) downloader.download(dest) if downloader.downloaded_name is None: logger.fatal('Error: Did not find any files for {0}', name, exc=PygError) if unpk: path = os.path.abspath(downloader.downloaded_name) logger.info('Unpacking {0} to {1}', os.path.basename(path), os.getcwd()) unpack(path)