def sync_repository(self, remote_repository, force, verbose=True): """Sync the cache for a remote repository""" with dlocked(self.path): assert isinstance(remote_repository, RemoteRepository) idx_path = self.get_local_index_path(remote_repository) console.mkdirs(dirname(idx_path)) return remote_repository.download_index(idx_path, force, verbose)
def get_repository(self, pyver, osarch, autocreate=False): path = xjoin(self.path, pyver, osarch) url = '/'.join([self.url, pyver, osarch]) if autocreate: # create, if does not already exist console.mkdirs(path) return Repository(path, self.name, pyver, osarch, url)
def ensure_write_access(self): if not os.path.exists(self.user_base_dir): # user may not have a ~/.local directory *yet* console.mkdirs(self.user_base_dir) # This is unlikely to happen if not os.access(self.user_base_dir, os.W_OK): raise NoWriteAccess, ('no write access to user base "%s"' % self.user_base_dir)
def __init__(self, pyenv, repository_list, interactive=False): self.pyenv = pyenv self.repository_list = repository_list self.interactive = interactive # if raw_input() can be used self.pypm_dir = join(self.pyenv.site_packages_dir, '_pypm') self.repo_store = store.RepoPackageStore( RemoteRepositoryManager(IDX_PATH), repository_list) if not exists(self.pypm_dir): self.pyenv.ensure_write_access() console.mkdirs(self.pypm_dir) self.installed_store = store.InstalledPackageStore( join(self.pypm_dir, 'installed.db'))
def setup_trace(l, tracefile): """Trace logging calls to a standard log file Log file name and location will be determined based on platform. """ l.setLevel(logging.DEBUG) # trace file must have >=DEBUG entries console.mkdirs(dirname(tracefile)) _rollover_log(tracefile) _begin_log_section(tracefile) h = logging.FileHandler(tracefile) h.setFormatter( logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s")) l.addHandler(h)
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)
def handledby(l, filename, create_dirs=False, level=None, formatter=None): """Momentarily handle logger `l` using FileHandler Within the 'with' context, all logging calls made to the logger `l` will get written to the file `filename`. When exiting the 'with' context, this file is closed and the handler will be removed. """ assert isabs(filename), 'not an absolute path: {0}'.format(filename) if create_dirs: console.mkdirs(dirname(filename)) h = logging.FileHandler(filename) if level: h.setLevel(level) if formatter: h.setFormatter(formatter) l.addHandler(h) try: yield finally: h.close() l.removeHandler(h)
def __init__(self, path): # local cache directory where repository indexes will be stored self.path = path console.mkdirs(path)
def create_repositories(self): """Create repositories for supported configuration""" for osarch in supported.os_architectures: for pyver in supported.py_versions: console.mkdirs( join(self.path, pyver, osarch))