From 33a05fdb68c30776487e3d2dd340d055629c19a9 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 23 Jun 2006 11:08:50 +0000 Subject: Split the --metadata action into a separate function from --sync. svn path=/main/trunk/; revision=3628 --- bin/emerge | 185 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 96 insertions(+), 89 deletions(-) (limited to 'bin') diff --git a/bin/emerge b/bin/emerge index 70385e5ad..e0a4b4ef3 100755 --- a/bin/emerge +++ b/bin/emerge @@ -2745,94 +2745,7 @@ def action_sync(myopts, myaction): updatecache_flg = False if os.path.exists(myportdir+"/metadata/cache") and updatecache_flg: - if "--quiet" not in myopts: - print "\n>>> Updating Portage cache: ", - os.umask(0002) - cachedir = os.path.normpath(portage.settings.depcachedir) - if cachedir in ["/", "/bin", "/dev", "/etc", "/home", - "/lib", "/opt", "/proc", "/root", "/sbin", - "/sys", "/tmp", "/usr", "/var"]: - print "!!! PORTAGE_CACHEDIR IS SET TO A PRIMARY ROOT DIRECTORY ON YOUR SYSTEM." - print "!!! This is ALMOST CERTAINLY NOT what you want: "+str(cachedir) - sys.exit(73) - if not os.path.exists(cachedir): - os.mkdir(cachedir) - - # Potentially bad - #if os.path.exists(cachedir+"/"+myportdir): - # portage.spawn("rm -Rf "+cachedir+"/"+myportdir+"/*",portage.settings,free=1) - - portage.portdb.flush_cache() - - ec = portage.eclass_cache.cache(portage.portdb.porttree_root) - # kinda ugly. - # XXX: nuke the filter when mr UNUSED_0? keys are dead - cm = portage.settings.load_best_module("portdbapi.metadbmodule")(myportdir, "metadata/cache", - filter(lambda x: not x.startswith("UNUSED_0"), portage.auxdbkeys)) - - # we don't make overlay trees cache here, plus we don't trust portage.settings.categories - porttree_root = portage.portdb.porttree_root - conf = portage.config(config_profile_path=portage.settings.profile_path[:], \ - config_incrementals=portage.settings.incrementals[:]) - - conf["PORTDIR_OVERLAY"] = '' - conf.categories = portage.grabfile(os.path.join(porttree_root, "profiles", "categories")) - try: - i = conf.categories.index("virtual") - if i != -1: - conf.categories.remove(i) - except (ValueError, IndexError): - pass - - pdb = portage.portdbapi(porttree_root, conf) - - cp_all_list = pdb.cp_all() - import cache.util - - class percentage_noise_maker(cache.util.quiet_mirroring): - def __init__(self, dbapi): - self.dbapi = dbapi - self.cp_all = dbapi.cp_all() - l = len(self.cp_all) - self.call_update_min = 100000000 - self.min_cp_all = l/100.0 - self.count = 1 - self.pstr = '' - - def __iter__(self): - for x in self.cp_all: - self.count += 1 - if self.count > self.min_cp_all: - self.call_update_min = 0 - self.count = 0 - for y in self.dbapi.cp_list(x): - yield y - self.call_update_mine = 0 - - def update(self, *arg): - try: self.pstr = int(self.pstr) + 1 - except ValueError: self.pstr = 1 - sys.stdout.write("%s%i%%" % ("\b" * (len(str(self.pstr))+1), self.pstr)) - sys.stdout.flush() - self.call_update_min = 10000000 - - def finish(self, *arg): - sys.stdout.write("\b\b\b\b100%\n") - sys.stdout.flush() - - - if "--quiet" in myopts: - def quicky_cpv_generator(cp_all_list): - for x in cp_all_list: - for y in pdb.cp_list(x): - yield y - source = quicky_cpv_generator(pdb.cp_all()) - noise_maker = cache.util.quiet_mirroring() - else: - noise_maker = source = percentage_noise_maker(pdb) - cache.util.mirror_cache(source, cm, pdb.auxdb[porttree_root], eclass_cache=ec, verbose_instance=noise_maker) - - sys.stdout.flush() + action_metadata(myopts) portage.portageexit() reload(portage) @@ -2859,6 +2772,97 @@ def action_sync(myopts, myaction): print red(" * ")+"To update portage, run 'emerge portage'." print +def action_metadata(myopts): + portage.writemsg_stdout("\n>>> Updating Portage cache: ") + old_umask = os.umask(0002) + cachedir = os.path.normpath(portage.settings.depcachedir) + if cachedir in ["/", "/bin", "/dev", "/etc", "/home", + "/lib", "/opt", "/proc", "/root", "/sbin", + "/sys", "/tmp", "/usr", "/var"]: + print >> sys.stderr, "!!! PORTAGE_DEPCACHEDIR IS SET TO A PRIMARY " + \ + "ROOT DIRECTORY ON YOUR SYSTEM." + print >> sys.stderr, \ + "!!! This is ALMOST CERTAINLY NOT what you want: '%s'" % cachedir + sys.exit(73) + if not os.path.exists(cachedir): + os.mkdir(cachedir) + + portage.portdb.flush_cache() + + ec = portage.eclass_cache.cache(portage.portdb.porttree_root) + myportdir = portage.settings["PORTDIR"] + cm = portage.settings.load_best_module("portdbapi.metadbmodule")( + myportdir, "metadata/cache", portage.auxdbkeys[:]) + + # we don't make overlay trees cache here, plus we don't trust + # portage.settings.categories + porttree_root = portage.portdb.porttree_root + conf = portage.config( + config_profile_path=portage.settings.profile_path[:], \ + config_incrementals=portage.settings.incrementals[:]) + + conf["PORTDIR_OVERLAY"] = '' + conf.categories = portage.grabfile( + os.path.join(porttree_root, "profiles", "categories")) + try: + i = conf.categories.index("virtual") + if i != -1: + conf.categories.remove(i) + except (ValueError, IndexError): + pass + + pdb = portage.portdbapi(porttree_root, conf) + + cp_all_list = pdb.cp_all() + import cache.util + + class percentage_noise_maker(cache.util.quiet_mirroring): + def __init__(self, dbapi): + self.dbapi = dbapi + self.cp_all = dbapi.cp_all() + l = len(self.cp_all) + self.call_update_min = 100000000 + self.min_cp_all = l/100.0 + self.count = 1 + self.pstr = '' + + def __iter__(self): + for x in self.cp_all: + self.count += 1 + if self.count > self.min_cp_all: + self.call_update_min = 0 + self.count = 0 + for y in self.dbapi.cp_list(x): + yield y + self.call_update_mine = 0 + + def update(self, *arg): + try: self.pstr = int(self.pstr) + 1 + except ValueError: self.pstr = 1 + sys.stdout.write("%s%i%%" % \ + ("\b" * (len(str(self.pstr))+1), self.pstr)) + sys.stdout.flush() + self.call_update_min = 10000000 + + def finish(self, *arg): + sys.stdout.write("\b\b\b\b100%\n") + sys.stdout.flush() + + if "--quiet" in myopts: + def quicky_cpv_generator(cp_all_list): + for x in cp_all_list: + for y in pdb.cp_list(x): + yield y + source = quicky_cpv_generator(pdb.cp_all()) + noise_maker = cache.util.quiet_mirroring() + else: + noise_maker = source = percentage_noise_maker(pdb) + cache.util.mirror_cache(source, cm, pdb.auxdb[porttree_root], + eclass_cache=ec, verbose_instance=noise_maker) + + sys.stdout.flush() + os.umask(old_umask) + def action_regen(): emergelog(" === regen") #regenerate cache entries @@ -3651,7 +3655,10 @@ if __name__ == "__main__": if "--pretend" in myopts: print "emerge: \"sync\" actions do not support \"--pretend.\"" sys.exit(1) - action_sync(myopts, myaction) + if "sync" == myaction: + action_sync(myopts, myaction) + else: + action_metadata(myopts) elif myaction=="regen": action_regen() # HELP action -- cgit v1.2.3-1-g7c22