Beispiel #1
0
 def info_list_name(self, name):
     req = Req(name)
     info_list = []
     for key, info in self.query_remote(name=name):
         if req.matches(info):
             repo = self.remote.where_from(key)
             info['repo_dispname'] = repo.info()['dispname']
             info_list.append(dict(info))
     try:
         return sorted(info_list,
                   key=lambda info: comparable_version(info['version']))
     except TypeError:
         return info_list
 def info_list_name(self, name):
     """
     return (sorted by versions (when possible)), a list of metadata
     dictionaries which are available on the remote KVS for a given name
     """
     req = Req(name)
     info_list = []
     for key, info in self.query_remote(name=name):
         if req.matches(info):
             info_list.append(dict(info))
     try:
         return sorted(info_list, key=comparable_info)
     except TypeError:
         return info_list
Beispiel #3
0
 def info_list_name(self, name):
     """
     return (sorted by versions (when possible)), a list of metadata
     dictionaries which are available on the remote KVS for a given name
     """
     req = Req(name)
     info_list = []
     for key, info in self.query_remote(name=name):
         if req.matches(info):
             info_list.append(dict(info))
     try:
         return sorted(info_list, key=comparable_info)
     except TypeError:
         return info_list
Beispiel #4
0
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)
Beispiel #5
0
def req_from_anything(arg):
    if isinstance(arg, Req):
        return arg
    if is_valid_eggname(arg):
        return Req('%s %s-%d' % split_eggname(arg))
    return Req(arg)