def read(): """ Return the configuration from the config file as a dictionary, fix some values, and give defaults. """ if hasattr(read, 'cache'): return read.cache path = get_path() read.cache = default.copy() if path is None: return read.cache execfile(path, read.cache) for k in read.cache: v = read.cache[k] if k == 'IndexedRepos': read.cache[k] = [fill_url(url) for url in v] elif k in ('prefix', 'local'): read.cache[k] = abs_expanduser(v) elif k == 'webservice_entry_point': read.cache[k] = fill_url(v) elif k == REPOSITORY_CACHE_CONFIG_NAME: read.cache[k] = v return read.cache
def __init__(self, use_keyring=None): self.proxy = None self.noapp = False self.use_webservice = True self.autoupdate = True self._prefix = sys.prefix self._local = join(sys.prefix, 'LOCAL-REPO') self._IndexedRepos = [] self._webservice_entry_point = fill_url(get_default_url()) self.repository_cache = self.local self._username = None self._password = None if use_keyring is None: self._use_keyring = keyring is not None elif use_keyring is True: if keyring is None: raise InvalidConfiguration("Requested using keyring, but " "no keyring available.") self._use_keyring = use_keyring elif use_keyring is False: self._use_keyring = use_keyring else: raise InvalidConfiguration("Invalid value for use_keyring: {0}". format(use_keyring)) self._filename = None
def read(): """ Return the configuration from the config file as a dictionary, fix some values, and give defaults. """ if hasattr(read, 'cache'): return read.cache path = get_path() read.cache = default if path is None: return read.cache execfile(path, read.cache) for k in read.cache: v = read.cache[k] if k == 'IndexedRepos': read.cache[k] = [fill_url(url) for url in v] elif k in ('prefix', 'local'): read.cache[k] = abs_expanduser(v) return read.cache
def main(): try: user_base = site.USER_BASE except AttributeError: user_base = abs_expanduser('~/.local') p = ArgumentParser(description=__doc__) p.add_argument('cnames', metavar='NAME', nargs='*', help='package(s) to work on') p.add_argument("--add-url", metavar='URL', help="add a repository URL to the configuration file") p.add_argument("--config", action="store_true", help="display the configuration and exit") p.add_argument('-f', "--force", action="store_true", help="force install the main package " "(not it's dependencies, see --forceall)") p.add_argument("--forceall", action="store_true", help="force install of all packages " "(i.e. including dependencies)") p.add_argument("--hook", action="store_true", help="don't install into site-packages (experimental)") p.add_argument("--imports", action="store_true", help="show which packages can be imported") p.add_argument('-i', "--info", action="store_true", help="show information about a package") p.add_argument("--log", action="store_true", help="print revision log") p.add_argument('-l', "--list", action="store_true", help="list the packages currently installed on the system") p.add_argument( '-n', "--dry-run", action="store_true", help="show what would have been downloaded/removed/installed") p.add_argument('-N', "--no-deps", action="store_true", help="neither download nor install dependencies") p.add_argument("--env", action="store_true", help="based on the configuration, display how to set the " "some environment variables") p.add_argument("--prefix", metavar='PATH', help="install prefix (disregarding of any settings in " "the config file)") p.add_argument("--proxy", metavar='URL', help="use a proxy for downloads") p.add_argument("--remove", action="store_true", help="remove a package") p.add_argument("--revert", metavar="REV", help="revert to a previous set of packages") p.add_argument('-s', "--search", action="store_true", help="search the index in the repo of packages " "and display versions available.") p.add_argument("--sys-config", action="store_true", help="use <sys.prefix>/.enstaller4rc (even when " "~/.enstaller4rc exists)") p.add_argument("--sys-prefix", action="store_true", help="use sys.prefix as the install prefix") p.add_argument("--user", action="store_true", help="install into user prefix, i.e. --prefix=%r" % user_base) p.add_argument("--userpass", action="store_true", help="change EPD authentication in configuration file") p.add_argument('-v', "--verbose", action="store_true") p.add_argument('--version', action="version", version='enstaller version: ' + __version__) p.add_argument("--whats-new", action="store_true", help="display to which installed packages updates are " "available") args = p.parse_args() if len(args.cnames) > 0 and (args.config or args.env or args.userpass or args.revert or args.log or args.whats_new): p.error("Option takes no arguments") if args.user: args.prefix = user_base if args.prefix and args.sys_prefix: p.error("Options --prefix and --sys-prefix exclude each other") if args.force and args.forceall: p.error("Options --force and --forceall exclude each other") pat = None if (args.list or args.search) and args.cnames: pat = re.compile(args.cnames[0], re.I) # make prefix if args.sys_prefix: prefix = sys.prefix elif args.prefix: prefix = args.prefix else: prefix = config.get('prefix', sys.prefix) # now make prefixes if prefix == sys.prefix: prefixes = [sys.prefix] else: prefixes = [prefix, sys.prefix] if args.verbose: print "Prefixes:" for p in prefixes: print ' %s%s' % (p, ['', ' (sys)'][p == sys.prefix]) print if args.env: # --env env_option(prefixes) return if args.log: # --log if args.hook: raise NotImplementedError from history import History h = History(prefix) h.update() h.print_log() return if args.sys_config: # --sys-config config.get_path = lambda: config.system_config_path if args.list: # --list list_option(prefixes, args.hook, pat) return if args.proxy: # --proxy setup_proxy(args.proxy) elif config.get('proxy'): setup_proxy(config.get('proxy')) else: setup_proxy() if 0: # for testing event manager only from encore.events.api import EventManager from encore.terminal.api import ProgressDisplay evt_mgr = EventManager() display = ProgressDisplay(evt_mgr) else: evt_mgr = None if config.get('use_webservice'): remote = None # Enpkg will create the default else: urls = [fill_url(u) for u in config.get('IndexedRepos')] remote = create_joined_store(urls) enpkg = Enpkg(remote, prefixes=prefixes, hook=args.hook, evt_mgr=evt_mgr, verbose=args.verbose) if args.config: # --config config.print_config(enpkg.remote) return if args.userpass: # --userpass username, password = config.input_auth() config.checked_change_auth(username, password, enpkg.remote) return if args.dry_run: def print_actions(actions): for item in actions: print '%-8s %s' % item enpkg.execute = print_actions if args.imports: # --imports assert not args.hook imports_option(enpkg, pat) return if args.add_url: # --add-url add_url(args.add_url, args.verbose) return if args.revert: # --revert if isfile(args.revert): arg = parse_list(args.revert) else: arg = args.revert try: actions = enpkg.revert_actions(arg) if not actions: print "Nothing to do" return enpkg.execute(actions) except EnpkgError as e: print e.message return # Try to auto-update enstaller if update_enstaller(enpkg, args): print "Enstaller has been updated.", \ "Please re-run your previous command." return if args.search: # --search search(enpkg, pat) return if args.info: # --info if len(args.cnames) != 1: p.error("Option requires one argument (name of package)") info_option(enpkg, args.cnames[0]) return if args.whats_new: # --whats-new whats_new(enpkg) return if len(args.cnames) == 0: p.error("Requirement(s) missing") elif len(args.cnames) == 2: pat = re.compile(r'\d+\.\d+') if pat.match(args.cnames[1]): args.cnames = ['-'.join(args.cnames)] reqs = [] for arg in args.cnames: if '-' in arg: name, version = arg.split('-', 1) reqs.append(Req(name + ' ' + version)) else: reqs.append(Req(arg)) if args.verbose: print "Requirements:" for req in reqs: print ' %r' % req print print "prefix:", prefix for req in reqs: if args.remove: # --remove try: enpkg.execute(enpkg.remove_actions(req)) except EnpkgError as e: print e.message else: install_req(enpkg, req, args) # install (default)
def add_url(url, verbose): url = fill_url(url) if url in config.get('IndexedRepos'): print "Already configured:", url return config.prepend_url(url)
def main(): try: user_base = site.USER_BASE except AttributeError: user_base = abs_expanduser('~/.local') p = ArgumentParser(description=__doc__) p.add_argument('cnames', metavar='NAME', nargs='*', help='package(s) to work on') p.add_argument("--add-url", metavar='URL', help="add a repository URL to the configuration file") p.add_argument("--config", action="store_true", help="display the configuration and exit") p.add_argument('-f', "--force", action="store_true", help="force install the main package " "(not it's dependencies, see --forceall)") p.add_argument("--forceall", action="store_true", help="force install of all packages " "(i.e. including dependencies)") p.add_argument("--hook", action="store_true", help="don't install into site-packages (experimental)") p.add_argument("--imports", action="store_true", help="show which packages can be imported") p.add_argument('-i', "--info", action="store_true", help="show information about a package") p.add_argument("--log", action="store_true", help="print revision log") p.add_argument('-l', "--list", action="store_true", help="list the packages currently installed on the system") p.add_argument('-n', "--dry-run", action="store_true", help="show what would have been downloaded/removed/installed") p.add_argument('-N', "--no-deps", action="store_true", help="neither download nor install dependencies") p.add_argument("--env", action="store_true", help="based on the configuration, display how to set the " "some environment variables") p.add_argument("--prefix", metavar='PATH', help="install prefix (disregarding of any settings in " "the config file)") p.add_argument("--proxy", metavar='URL', help="use a proxy for downloads") p.add_argument("--remove", action="store_true", help="remove a package") p.add_argument("--revert", metavar="REV", help="revert to a previous set of packages") p.add_argument('-s', "--search", action="store_true", help="search the index in the repo of packages " "and display versions available.") p.add_argument("--sys-config", action="store_true", help="use <sys.prefix>/.enstaller4rc (even when " "~/.enstaller4rc exists)") p.add_argument("--sys-prefix", action="store_true", help="use sys.prefix as the install prefix") p.add_argument("--user", action="store_true", help="install into user prefix, i.e. --prefix=%r" % user_base) p.add_argument("--userpass", action="store_true", help="change EPD authentication in configuration file") p.add_argument('-v', "--verbose", action="store_true") p.add_argument('--version', action="version", version='enstaller version: ' + __version__) p.add_argument("--whats-new", action="store_true", help="display to which installed packages updates are " "available") args = p.parse_args() if len(args.cnames) > 0 and (args.config or args.env or args.userpass or args.revert or args.log or args.whats_new): p.error("Option takes no arguments") if args.user: args.prefix = user_base if args.prefix and args.sys_prefix: p.error("Options --prefix and --sys-prefix exclude each ohter") if args.force and args.forceall: p.error("Options --force and --forceall exclude each ohter") pat = None if (args.list or args.search) and args.cnames: pat = re.compile(args.cnames[0], re.I) # make prefix if args.sys_prefix: prefix = sys.prefix elif args.prefix: prefix = args.prefix else: prefix = config.get('prefix', sys.prefix) # now make prefixes if prefix == sys.prefix: prefixes = [sys.prefix] else: prefixes = [prefix, sys.prefix] if args.verbose: print "Prefixes:" for p in prefixes: print ' %s%s' % (p, ['', ' (sys)'][p == sys.prefix]) print if args.env: # --env env_option(prefixes) return if args.log: # --log if args.hook: raise NotImplementedError from history import History h = History(prefix) h.update() h.print_log() return if args.sys_config: # --sys-config config.get_path = lambda: config.system_config_path if args.config: # --config config.print_config() return if args.list: # --list list_option(prefixes, args.hook, pat) return if args.proxy: # --proxy setup_proxy(args.proxy) elif config.get('proxy'): setup_proxy(config.get('proxy')) else: setup_proxy() if 0: # for testing event manager only from encore.events.api import EventManager from encore.terminal.api import ProgressDisplay evt_mgr = EventManager() display = ProgressDisplay(evt_mgr) else: evt_mgr = None if config.get('use_webservice'): remote = None # Enpkg will create the default else: urls = [fill_url(u) for u in config.get('IndexedRepos')] remote = create_joined_store(urls) enpkg = Enpkg(remote, prefixes=prefixes, hook=args.hook, evt_mgr=evt_mgr, verbose=args.verbose) if args.userpass: # --userpass auth = username, password = config.input_auth() if remote is not None: try: print 'Verifying username and password...' remote.connect(auth) except KeyError as e: print 'Invalid Username or Password' except Exception as e: print e.message else: config.change_auth(username, password) else: config.change_auth(username, password) return if args.dry_run: def print_actions(actions): for item in actions: print '%-8s %s' % item enpkg.execute = print_actions if args.imports: # --imports assert not args.hook imports_option(enpkg, pat) return if args.add_url: # --add-url add_url(args.add_url, args.verbose) return if args.revert: # --revert if isfile(args.revert): arg = parse_list(args.revert) else: arg = args.revert try: actions = enpkg.revert_actions(arg) if not actions: print "Nothing to do" return enpkg.execute(actions) except EnpkgError as e: print e.message return if args.search: # --search search(enpkg, pat) return if args.info: # --info if len(args.cnames) != 1: p.error("Option requires one argument (name of package)") info_option(enpkg, args.cnames[0]) return if args.whats_new: # --whats-new whats_new(enpkg) return if len(args.cnames) == 0: p.error("Requirement(s) missing") elif len(args.cnames) == 2: pat = re.compile(r'\d+\.\d+') if pat.match(args.cnames[1]): args.cnames = ['-'.join(args.cnames)] reqs = [] for arg in args.cnames: if '-' in arg: name, version = arg.split('-', 1) reqs.append(Req(name + ' ' + version)) else: reqs.append(Req(arg)) if args.verbose: print "Requirements:" for req in reqs: print ' %r' % req print print "prefix:", prefix for req in reqs: if args.remove: # --remove try: enpkg.execute(enpkg.remove_actions(req)) except EnpkgError as e: print e.message else: install_req(enpkg, req, args) # install (default)
def webservice_entry_point(self, url): self._webservice_entry_point = fill_url(url)
def IndexedRepos(self, urls): self._IndexedRepos = [fill_url(url) for url in urls]