def _init_log_file(self, force=False): """ initialize the log file """ if not force and isfile(self._log_path): return self._write_egg_names(egginst.get_installed(self.prefix))
def update(self): """ update the history file (creating a new one if necessary) """ self._init_log_file() last = self.get_state() curr = set(egginst.get_installed(self.prefix)) if last == curr: return self._write_changes(last, curr)
def init(self, force=False): """ initialize the history file """ if not force and isfile(self.path): return fo = open(self.path, 'w') fo.write(time.strftime("==> %s <==\n" % TIME_FMT)) for eggname in egginst.get_installed(): fo.write('%s\n' % eggname) fo.close()
def _init_log_file(self, force=False): """ initialize the log file """ if not force and isfile(self._log_path): return fo = open(self._log_path, "w") fo.write(time.strftime("==> %s <==\n" % TIME_FMT)) for eggname in egginst.get_installed(self.prefix): fo.write("%s\n" % eggname) fo.close()
def update(self): """ update the history file (creating a new one if necessary) """ self.init() last = self.get_state() curr = set(egginst.get_installed()) if last == curr: return fo = open(self.path, 'a') fo.write(time.strftime("==> %s <==\n" % TIME_FMT)) for fn in last - curr: fo.write('-%s\n' % fn) for fn in curr - last: fo.write('+%s\n' % fn) fo.close()
def update(self): """ update the history file (creating a new one if necessary) """ self._init_log_file() last = self.get_state() curr = set(egginst.get_installed(self.prefix)) if last == curr: return fo = open(self._log_path, "a") fo.write("==> %s <==\n" % now()) for fn in last - curr: fo.write("-%s\n" % fn) for fn in curr - last: fo.write("+%s\n" % fn) fo.close()
def revert(enst, rev_in, quiet=False): history = History(enst.prefixes[0]) try: rev = int(rev_in) except ValueError: # we have a "date string" from parse_dt import parse rev = parse(rev_in) if rev is None: sys.exit("Error: could not parse: %r" % rev_in) print "reverting to: %r" % rev try: state = history.get_state(rev) except IndexError: sys.exit("Error: no such revision: %r" % rev) curr = set(egginst.get_installed()) if state == curr: print "Nothing to revert" return # remove packages for fn in curr - state: enst.remove_egg(fn) # install packages (fetch from server if necessary) to_install = [] need_fetch = [] for fn in state - curr: to_install.append(fn) if not isfile(join(enst.egg_dir, fn)): need_fetch.append(fn) if need_fetch: for fn in need_fetch: dist = enst.chain.get_dist(filename_as_req(fn)) if dist: enst.chain.fetch_dist(dist, enst.egg_dir, dry_run=enst.dry_run) for fn in to_install: egg_path = join(enst.egg_dir, fn) if isfile(egg_path): ei = egginst.EggInst(egg_path) ei.install() history.update()
def get_installed(prefix, pat=None): results = [] for fn in egginst.get_installed(prefix): if pat and not pat.search(fn[:-4]): continue lst = list(egginst.name_version_fn(fn)) info = get_installed_info(prefix, 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('-') results.append(tuple(lst)) return results
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 whats_new(c): fmt = '%-25s %-15s %s' print fmt % ('Name', 'installed', 'available') print 60 * "=" inst = set(egginst.get_installed()) something_new = False for egg_name in inst: if not dist_naming.is_valid_eggname(egg_name): continue in_n, in_v, in_b = dist_naming.split_eggname(egg_name) dist = c.get_dist(Req(in_n)) if dist is None: continue av_v = c.index[dist]['version'] if (av_v != in_v and comparable_version(av_v) > comparable_version(in_v)): print fmt % (in_n, in_v, av_v) something_new = True if not something_new: print "no new version of any installed package is available"
def whats_new(c): fmt = '%-25s %-15s %s' print fmt % ('Name', 'installed', 'available') print 60* "=" inst = set(egginst.get_installed()) something_new = False for egg_name in inst: if not dist_naming.is_valid_eggname(egg_name): continue in_n, in_v, in_b = dist_naming.split_eggname(egg_name) dist = c.get_dist(Req(in_n)) if dist is None: continue av_v = c.index[dist]['version'] if (av_v != in_v and comparable_version(av_v) > comparable_version(in_v)): print fmt % (in_n, in_v, av_v) something_new = True if not something_new: print "no new version of any installed package is available"
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)