def remove_binstar_token(url): try: from binstar_client.utils.appdirs import AppDirs, EnvAppDirs except ImportError: raise if 'BINSTAR_CONFIG_DIR' in os.environ: dirs = EnvAppDirs('binstar', 'ContinuumIO', os.environ['BINSTAR_CONFIG_DIR']) else: dirs = AppDirs('binstar', 'ContinuumIO') tokenfile = join(dirs.user_data_dir, '%s.token' % quote_plus(url)) rm_rf(tokenfile)
def read_binstar_tokens(): tokens = dict() try: from binstar_client.utils.appdirs import AppDirs, EnvAppDirs except ImportError: return tokens if 'BINSTAR_CONFIG_DIR' in os.environ: dirs = EnvAppDirs('binstar', 'ContinuumIO', os.environ['BINSTAR_CONFIG_DIR']) else: dirs = AppDirs('binstar', 'ContinuumIO') token_files = glob(join(dirs.user_data_dir, '*.token')) for tkn_file in token_files: url = re.sub(r'\.token$', '', unquote_plus(basename(tkn_file))) with open(tkn_file) as f: token = f.read() tokens[url] = tokens[replace_first_api_with_conda(url)] = token return tokens
def set_binstar_token(url, token): try: from binstar_client.utils.appdirs import AppDirs, EnvAppDirs except ImportError: raise if 'BINSTAR_CONFIG_DIR' in os.environ: dirs = EnvAppDirs('binstar', 'ContinuumIO', os.environ['BINSTAR_CONFIG_DIR']) else: dirs = AppDirs('binstar', 'ContinuumIO') if not isdir(dirs.user_data_dir): os.makedirs(dirs.user_data_dir) tokenfile = join(dirs.user_data_dir, '%s.token' % quote_plus(url)) if isfile(tokenfile): os.unlink(tokenfile) with open(tokenfile, 'w') as fd: fd.write(token) os.chmod(tokenfile, S_IWRITE | S_IREAD)
def expandvars(path): environ = dict(CONDA_ROOT=CONDA_ROOT, CONDA_PREFIX=CONDA_PREFIX) environ.update(os.environ) return Template(path).safe_substitute(**environ) def expand(path): return abspath(expanduser(expandvars(path))) log = logging.getLogger('binstar') if 'BINSTAR_CONFIG_DIR' in os.environ: dirs = EnvAppDirs('binstar', 'ContinuumIO', os.environ['BINSTAR_CONFIG_DIR']) USER_CONFIG = join(dirs.user_data_dir, 'config.yaml') else: dirs = AppDirs('binstar', 'ContinuumIO') USER_CONFIG = expand('~/.continuum/anaconda-client/config.yaml') USER_LOGDIR = dirs.user_log_dir SITE_CONFIG = expand('$CONDA_ROOT/etc/anaconda-client/config.yaml') SYSTEM_CONFIG = SITE_CONFIG DEFAULT_URL = 'https://api.anaconda.org' ALPHA_URL = 'http://api.alpha.binstar.org' DEFAULT_CONFIG = { 'sites': { 'binstar': { 'url': DEFAULT_URL