def depend_warn(pkgs, ignore_version=False): """ Warns the user about packages to be changed (i.e. removed or updated), if other packages depend on the package. Warnings are printed when the required name of the package matches. The ignore_version option determines if a version comparison is also desired as well, which it is not for the --remove option, since when a package is removed it does not matter which version is required. Hence, in remove_req() this function is called with ignore_version=True. """ names = {} for pkg in pkgs: names[cname_fn(pkg)] = pkg index = read_depend_files() for spec in index.itervalues(): if spec['cname'] in names: continue for req in spec["Reqs"]: if req.name not in names: continue if (ignore_version or (req.version and req.version != names[req.name].split('-')[1])): print "Warning: %s depends on %s" % (spec_as_req(spec), req)
def egginst_install(conf, dist): repo, fn = dist_naming.split_dist(dist) pkg_path = join(conf['local'], fn) pprint_fn_action(fn, 'installing') if dry_run: return ei = egginst.EggInst(pkg_path) ei.install() info = get_installed_info(cname_fn(fn)) path = join(info['meta_dir'], '__enpkg__.txt') fo = open(path, 'w') fo.write("repo = %r\n" % repo) fo.close()
def print_installed(pat=None): fmt = '%-20s %-20s %s' print fmt % ('Project name', 'Version', 'Repository') print 60 * '=' for fn in egginst.get_installed(): if pat and not pat.search(fn[:-4]): continue lst = list(egginst.name_version_fn(fn)) info = get_installed_info(cname_fn(fn)) if info is None: lst.append('') else: path = join(info['meta_dir'], '__enpkg__.txt') if isfile(path): d = {} execfile(path, d) lst.append(shorten_repo(d['repo'])) else: lst.append('') print fmt % tuple(lst)
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)