def download_index(self, target_file, force, verbose=True): """Download repository index - verbose: If False, try not to print (LOG.info) anything to console unless an actual download happens. """ index_url = url_join(self.url, [self.REMOTE_INDEX_FILENAME]) try: idxgz_file = net.download_file(index_url, dirname(target_file), { 'use_cache': not force, 'save_properties': True, 'info': 'Get: [%s] :repository-index:' % ( urlparse(self.url).netloc) }) except urllib2.HTTPError, e: if e.code == 304: # Not Modified # repository was not modified; no need to download index if verbose: LOG.info('Hit: [%s] :repository-index:', urlparse(self.url).netloc) return False elif e.code == 404: # Not Found raise ValueError, ( '{0.url} does not appear to be a valid repository ' 'because {1} is missing.'.format(self, index_url)) raise
def download_package(self, package): assert type(package) is RepoPackage sh.mkdirs(DOWNLOAD_CACHE) auth = licensing.get_be_license_auth() send_license = package.requires_be_license license_installed = auth is not None # A license is required for this package, but no license is installed if not license_installed and send_license: msg = '\n'.join([ wrapped('If you have purchased ActivePython Business Edition, ' 'please login to your account at:'), ' https://account.activestate.com/', wrapped('and download and run the license installer for your ' 'platform.'), '', wrapped('Please visit <%s> to learn more about the ' 'ActivePython Business Edition offering.' % \ licensing.BE_HOME_PAGE)]) raise error.PackageAccessError( package, 'requires Business Edition subscription', msg) try: # At this point, the user is already known to have a BE license file_location, _ = net.download_file( package.download_url, DOWNLOAD_CACHE, dict( auth=auth, use_cache=True, # XXX: this introduces network delay # (If-None-Match) despite having the file # in download cache # TODO: abstract client.store...autosync save_properties=True, start_info='{{status}}: [{0}] {1} {2}'.format( six.moves.urlparse(package.download_url).netloc, package.name, package.printable_version)), interactive=self.pypmenv.options['interactive']) except six.moves.HTTPError as e: reason = str(e) LOG.debug("HTTPError while accessing URL: %s -- reason: %s", package.download_url, reason) if send_license and e.code in (401, 402, 403): msg = wrapped( 'Your ActivePython Business Edition subscription seems to ' 'have expired. Please visit your account at ' 'https://account.activestate.com/ to renew your subscription.' ) else: msg = '' raise error.PackageAccessError(package, reason, msg) return file_location
def install_remote_file(pypmenv, url): """Install a .pypm file from an URL Dependency is not automatically resolved, although we should do this in future """ sh.mkdirs(DOWNLOAD_CACHE) local_file, _ = net.download_file(url, DOWNLOAD_CACHE) return install_local_file(pypmenv, local_file)
def download_index(self, target_file, force, verbose=True, interactive=True): """Download repository index unless it was downloaded recently (Etag) - force: Do not use cache; always download - verbose: If False, try not to print (LOG.info) anything to console unless an actual download happens. Return True if download actually happened. """ def start_info(status): if status == 'Hit' and not verbose: return None return '%s: [%s] :repository-index:' % ( status, six.moves.urlparse(self.url).netloc) index_url = url_join(self.url, [self.REMOTE_INDEX_FILENAME]) try: idxgz_file, downloaded = net.download_file( index_url, P.dirname(target_file), { 'use_cache': not force, 'save_properties': True, 'start_info': start_info, }, interactive=interactive) if not downloaded: # index was not updated return False except six.moves.HTTPError as e: if e.code == 404: # Not Found raise ValueError( '{0.url} does not appear to be a valid repository ' 'because {1} is missing.'.format(self, index_url)) raise # extract index.gz (REMOTE_INDEX_FILENAME) to index (target_file) try: with closing(gzip.open(idxgz_file, 'rb')) as f: with open(target_file, 'wb') as f2: f2.write(f.read()) except: # If an error occurs during extraction, simply delete the index file # (so that it will get properly synced during next sync) sh.rm(target_file) sh.rm(idxgz_file) raise return True
def download_package(self, package): assert type(package) is RepoPackage sh.mkdirs(DOWNLOAD_CACHE) LOG.info('Get: [%s] %s %s', six.moves.urlparse(package.download_url).netloc, package.name, package.printable_version) auth = licensing.get_be_license_auth() send_license = package.requires_be_license license_installed = auth is not None # A license is required for this package, but no license is installed if not license_installed and send_license: msg = '\n'.join([ wrapped('If you have purchased ActivePython Business Edition, ' 'please login to your account at:'), ' https://account.activestate.com/', wrapped('and download and run the license installer for your ' 'platform.'), '', wrapped('Please visit <%s> to learn more about the ' 'ActivePython Business Edition offering.' % \ licensing.BE_HOME_PAGE)]) raise error.PackageAccessError( package, 'requires Business Edition subscription', msg) try: # At this point, the user is already known to have a BE license file_location = net.download_file( package.download_url, DOWNLOAD_CACHE, dict(auth=auth), interactive=self.pypmenv.options['interactive']) except six.moves.HTTPError as e: reason = str(e) LOG.debug("HTTPError while accessing URL: %s -- reason: %s", package.download_url, reason) if send_license and e.code in (401, 402, 403): msg = wrapped( 'Your ActivePython Business Edition subscription seems to ' 'have expired. Please visit your account at ' 'https://account.activestate.com/ to renew your subscription.' ) else: msg = '' raise error.PackageAccessError(package, reason, msg) return file_location
def download_index(self, target_file, force, verbose=True, interactive=True): """Download repository index unless it was downloaded recently (Etag) - force: Do not use cache; always download - verbose: If False, try not to print (LOG.info) anything to console unless an actual download happens. Return True if download actually happened. """ def start_info(status): if status == 'Hit' and not verbose: return None return '%s: [%s] :repository-index:' % ( status, six.moves.urlparse(self.url).netloc) index_url = url_join(self.url, [self.REMOTE_INDEX_FILENAME]) try: idxgz_file, downloaded = net.download_file(index_url, P.dirname(target_file), { 'use_cache': not force, 'save_properties': True, 'start_info': start_info, }, interactive=interactive) if not downloaded: # index was not updated return False except six.moves.HTTPError as e: if e.code == 404: # Not Found raise ValueError( '{0.url} does not appear to be a valid repository ' 'because {1} is missing.'.format(self, index_url)) raise # extract index.gz (REMOTE_INDEX_FILENAME) to index (target_file) try: with closing(gzip.open(idxgz_file, 'rb')) as f: with open(target_file, 'wb') as f2: f2.write(f.read()) except: # If an error occurs during extraction, simply delete the index file # (so that it will get properly synced during next sync) sh.rm(target_file) sh.rm(idxgz_file) raise return True
def download_package(self, package): assert type(package) is RepoPackage console.mkdirs(DOWNLOAD_CACHE) LOG.info('Get: [%s] %s %s', urlparse(package.download_url).netloc, package.canonical_name, package.full_version) auth = activestate.get_be_license_auth() send_license = package.requires_be_license license_installed = auth is not None access_msg = ('Access to package "{0.full_name}" requires a valid ' + 'Business Edition license. Please visit {1} for more ' + 'details').format(package, activestate.BE_HOME_PAGE) if not license_installed and send_license: raise error.PackageAccessError( package, 'requires Business Edition subscription', ('Please visit {0} to learn more\n' 'about the ActivePython Business Edition offering.').format( activestate.BE_HOME_PAGE)) try: # At this point, the user is already know to have a BE license file_location = net.download_file(package.download_url, DOWNLOAD_CACHE, dict(auth=auth)) except HTTPError, e: reason = str(e) LOG.debug("HTTPError while accessing URL: %s -- reason: %s", package.download_url, reason) if send_license and e.code in (401, 402, 403): msg = ( 'Your ActivePython Business Edition subscription seems to ' 'have expired.\n' 'Please visit your account at ' 'https://account.activestate.com to \n' 'renew your subscription.') else: msg = '' raise error.PackageAccessError(package, reason, msg)