def iter_dists_excl(dists, exclude_fn): """ Iterates over all dists, excluding the ones whose filename is an element of exclude_fn. Yields the distribution. """ for dist in dists: fn = dist_naming.filename_dist(dist) if fn in exclude_fn: continue yield dist
def main(): p = OptionParser(usage="usage: %prog [options] [name] [version]", description=__doc__) p.add_option("--config", action="store_true", help="display the configuration and exit") p.add_option('-f', "--force", action="store_true", help="force install the main package " "(not it's dependencies, see --forceall)") p.add_option("--forceall", action="store_true", help="force install of all packages " "(i.e. including dependencies)") p.add_option('-i', "--info", action="store_true", help="show information about a package") p.add_option('-l', "--list", action="store_true", help="list the packages currently installed on the system") p.add_option('-n', "--dry-run", action="store_true", help="show what would have been downloaded/removed/installed") p.add_option('-N', "--no-deps", action="store_true", help="neither download nor install dependencies") p.add_option("--remove", action="store_true", help="remove a package") p.add_option('-s', "--search", action="store_true", help="search the index in the repo (chain) of packages " "and display versions available.") p.add_option('-v', "--verbose", action="store_true") p.add_option('--version', action="store_true") p.add_option("--whats-new", action="store_true", help="display to which installed packages updates are " "available") opts, args = p.parse_args() if len(args) > 0 and opts.config: p.error("Option takes no arguments") if opts.force and opts.forceall: p.error("Options --force and --forceall exclude each ohter") pat = None if (opts.list or opts.search) and args: pat = re.compile(args[0], re.I) if opts.version: # --version from enstaller import __version__ print "IronPkg version:", __version__ return if opts.config: # --config config.print_config() return if config.get_path() is None: # create config file if it dosn't exist config.write() conf = config.read() # conf global dry_run, version # set globals dry_run = opts.dry_run version = opts.version if opts.list: # --list print_installed(pat) return c = Chain(conf['IndexedRepos'], verbose) # init chain if opts.search: # --search search(c, pat) return if opts.info: # --info if len(args) != 1: p.error("Option requires one argument (name of package)") info_option(c, canonical(args[0])) return if opts.whats_new: # --whats-new if args: p.error("Option requires no arguments") whats_new(c) return if len(args) == 0: p.error("Requirement (name and optional version) missing") if len(args) > 2: p.error("A requirement is a name and an optional version") req = Req(' '.join(args)) if opts.remove: # --remove remove_req(req) return dists = get_dists( c, req, # dists recur=not opts.no_deps) # Warn the user about packages which depend on what will be updated depend_warn([dist_naming.filename_dist(d) for d in dists]) # Packages which are installed currently inst = set(egginst.get_installed()) # These are the packahes which are being excluded from being installed if opts.forceall: exclude = set() else: exclude = set(inst) if opts.force: exclude.discard(dist_naming.filename_dist(dists[-1])) # Fetch distributions if not isdir(conf['local']): os.makedirs(conf['local']) for dist in iter_dists_excl(dists, exclude): c.fetch_dist(dist, conf['local'], check_md5=opts.force or opts.forceall, dry_run=dry_run) # Remove packages (in reverse install order) for dist in dists[::-1]: fn = dist_naming.filename_dist(dist) if fn in inst: # if the distribution (which needs to be installed) is already # installed don't remove it continue cname = cname_fn(fn) for fn_inst in inst: if cname == cname_fn(fn_inst): egginst_remove(fn_inst) # Install packages installed_something = False for dist in iter_dists_excl(dists, exclude): installed_something = True egginst_install(conf, dist) if not installed_something: print "No update necessary, %s is up-to-date." % req print_installed_info(req.name)
def main(): p = OptionParser(usage="usage: %prog [options] [name] [version]", description=__doc__) p.add_option("--config", action="store_true", help="display the configuration and exit") p.add_option('-f', "--force", action="store_true", help="force install the main package " "(not it's dependencies, see --forceall)") p.add_option("--forceall", action="store_true", help="force install of all packages " "(i.e. including dependencies)") p.add_option('-i', "--info", action="store_true", help="show information about a package") p.add_option('-l', "--list", action="store_true", help="list the packages currently installed on the system") p.add_option('-n', "--dry-run", action="store_true", help="show what would have been downloaded/removed/installed") p.add_option('-N', "--no-deps", action="store_true", help="neither download nor install dependencies") p.add_option("--remove", action="store_true", help="remove a package") p.add_option('-s', "--search", action="store_true", help="search the index in the repo (chain) of packages " "and display versions available.") p.add_option('-v', "--verbose", action="store_true") p.add_option('--version', action="store_true") p.add_option("--whats-new", action="store_true", help="display to which installed packages updates are " "available") opts, args = p.parse_args() if len(args) > 0 and opts.config: p.error("Option takes no arguments") if opts.force and opts.forceall: p.error("Options --force and --forceall exclude each ohter") pat = None if (opts.list or opts.search) and args: pat = re.compile(args[0], re.I) if opts.version: # --version from enstaller import __version__ print "IronPkg version:", __version__ return if opts.config: # --config config.print_config() return if config.get_path() is None: # create config file if it dosn't exist config.write() conf = config.read() # conf global dry_run, version # set globals dry_run = opts.dry_run version = opts.version if opts.list: # --list print_installed(pat) return c = Chain(conf['IndexedRepos'], verbose) # init chain if opts.search: # --search search(c, pat) return if opts.info: # --info if len(args) != 1: p.error("Option requires one argument (name of package)") info_option(c, canonical(args[0])) return if opts.whats_new: # --whats-new if args: p.error("Option requires no arguments") whats_new(c) return if len(args) == 0: p.error("Requirement (name and optional version) missing") if len(args) > 2: p.error("A requirement is a name and an optional version") req = Req(' '.join(args)) if opts.remove: # --remove remove_req(req) return dists = get_dists(c, req, # dists recur=not opts.no_deps) # Warn the user about packages which depend on what will be updated depend_warn([dist_naming.filename_dist(d) for d in dists]) # Packages which are installed currently inst = set(egginst.get_installed()) # These are the packahes which are being excluded from being installed if opts.forceall: exclude = set() else: exclude = set(inst) if opts.force: exclude.discard(dist_naming.filename_dist(dists[-1])) # Fetch distributions if not isdir(conf['local']): os.makedirs(conf['local']) for dist in iter_dists_excl(dists, exclude): c.fetch_dist(dist, conf['local'], check_md5=opts.force or opts.forceall, dry_run=dry_run) # Remove packages (in reverse install order) for dist in dists[::-1]: fn = dist_naming.filename_dist(dist) if fn in inst: # if the distribution (which needs to be installed) is already # installed don't remove it continue cname = cname_fn(fn) for fn_inst in inst: if cname == cname_fn(fn_inst): egginst_remove(fn_inst) # Install packages installed_something = False for dist in iter_dists_excl(dists, exclude): installed_something = True egginst_install(conf, dist) if not installed_something: print "No update necessary, %s is up-to-date." % req print_installed_info(req.name)