Пример #1
0
Файл: req.py Проект: fdev31/pyg
 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')
Пример #2
0
Файл: web.py Проект: Malex/pyg
    def download(self, dest):
        dest = os.path.abspath(dest)
        files = self.files()

        ## We need a placeholder because of the nested for loops
        success = False

        for p in self.pref:
            if success:
                break
            if not files[p]:
                logger.warn('{0} files not found. Continue searching...', p)
                continue
            for v, name, hash, url in files[p]:
                if success:
                    break
                if p == '.egg' and not right_egg(name):
                    logger.info('Found egg file for another Python version: {0}. Continue searching...',                               version_egg(name))
                    continue
                try:
                    data = download(url, 'Retrieving data for {0}'.format(self.name)).getvalue()
                except (urllib2.URLError, urllib2.HTTPError) as e:
                    logger.debug('urllib2 error: {0}', e.args)
                    continue
                if not data:
                    logger.debug('debug: Request failed')
                    continue
                if not os.path.exists(dest):
                    os.makedirs(dest)
                try:
                    # Fix for packages with no version in the name
                    if '-' not in name:
                        name = '{0}-{1}{2}'.format(name, v, p)
                    logger.info('Writing data into {0}', name)
                    with open(os.path.join(dest, name), 'w') as f:
                        f.write(data)
                except (IOError, OSError):
                    logger.debug('debug: Error while writing data')
                    continue
                logger.success('{0} downloaded successfully', self.name)
                success = True
            self.downloaded_name = name
            self.downloaded_version = v