[entropy.db,entropy.spm] rewrite SPM package metadata update code

This commit moves all the SPM package metadata update logic, including
pkgmove and slotmove to entropy.spm plugins.
This makes possible to handle the event more reliably. In particular,
Entropy now controls what Portage does, basing on the repository treeupdates
information.
The scenario in where the Portage tree was not updated and the called
"emaint --fix moveinst" did not do what it was supposed to do is now
handled correctly.
This commit is contained in:
Fabio Erculiani
2013-03-12 13:55:01 +00:00
parent 6804e79b37
commit f02283523d
3 changed files with 45 additions and 103 deletions
+1 -77
View File
@@ -1672,11 +1672,10 @@ class EntropyRepositoryBase(TextInterface, EntropyRepositoryPluginStore):
)
try:
spm = get_spm(self)
spm.packages_repositories_metadata_update()
spm.packages_repositories_metadata_update(actions)
except Exception:
entropy.tools.print_traceback()
spm_moves = set()
quickpkg_atoms = set()
executed_actions = []
for action in actions:
@@ -1693,7 +1692,6 @@ class EntropyRepositoryBase(TextInterface, EntropyRepositoryPluginStore):
header = darkred(" * ")
)
if command[0] == "move":
spm_moves.add(action)
move_actions = self._runTreeUpdatesMoveAction(command[1:],
quickpkg_atoms)
if move_actions:
@@ -1718,18 +1716,6 @@ class EntropyRepositoryBase(TextInterface, EntropyRepositoryPluginStore):
header = purple(" @@ ")
)
if spm_moves:
try:
self._doTreeupdatesSpmCleanup(spm_moves)
except Exception as e:
mytxt = "%s: %s: %s, %s." % (
bold(_("WARNING")),
red(_("Cannot run SPM cleanup, error")),
Exception,
e,
)
entropy.tools.print_traceback()
mytxt = "%s: %s." % (
bold(_("Entropy")),
blue(_("package moves completed successfully")),
@@ -1966,68 +1952,6 @@ class EntropyRepositoryBase(TextInterface, EntropyRepositoryPluginStore):
quickpkg_queue.add(myatom)
return quickpkg_queue
def _doTreeupdatesSpmCleanup(self, spm_moves):
"""
Erase dead Source Package Manager db entries.
@todo: make more Portage independent (create proper entropy.spm
methods for dealing with this)
@param spm_moves: list of raw package name/slot update actions.
@type spm_moves: list
"""
# now erase Spm entries if necessary
for action in spm_moves:
command = action.split()
if len(command) < 2:
continue
key = command[1]
category, name = key.split("/", 1)
dep_key = entropy.dep.dep_getkey(key)
try:
spm = get_spm(self)
except Exception:
entropy.tools.print_traceback()
continue
script_path = spm.get_installed_package_build_script_path(dep_key)
pkg_path = os.path.dirname(os.path.dirname(script_path))
if not os.path.isdir(pkg_path):
# no dir, no party!
continue
mydirs = [os.path.join(pkg_path, x) for x in \
os.listdir(pkg_path) if \
entropy.dep.dep_getkey(os.path.join(category, x)) \
== dep_key]
mydirs = [x for x in mydirs if os.path.isdir(x)]
# now move these dirs
for mydir in mydirs:
to_path = os.path.join(etpConst['entropyunpackdir'],
os.path.basename(mydir))
mytxt = "%s: %s '%s' %s '%s'" % (
bold(_("SPM")),
red(_("Moving old entry")),
blue(mydir),
red(_("to")),
blue(to_path),
)
self.output(
mytxt,
importance = 1,
level = "warning",
header = darkred(" * ")
)
if os.path.isdir(to_path):
shutil.rmtree(to_path, True)
try:
os.rmdir(to_path)
except OSError:
pass
shutil.move(mydir, to_path)
def listAllTreeUpdatesActions(self, no_ids_repos = False):
"""
This method should be considered internal and not suited for general
@@ -551,7 +551,7 @@ class PortagePlugin(SpmPlugin):
'global_make_profile': "/etc/make.profile",
}
PLUGIN_API_VERSION = 10
PLUGIN_API_VERSION = 11
SUPPORTED_MATCH_TYPES = [
"bestmatch-visible", "cp-list", "list-visible", "match-all",
@@ -910,33 +910,48 @@ class PortagePlugin(SpmPlugin):
mirrors.extend(self._portage.thirdpartymirrors[mirror_name])
return mirrors
def packages_repositories_metadata_update(self):
def packages_repositories_metadata_update(self, actions):
"""
Reimplemented from SpmPlugin class.
"""
root = etpConst['systemroot'] + os.path.sep
env = os.environ.copy()
env['ROOT'] = root
emaint_exec = "/usr/sbin/emaint"
args = (emaint_exec, "--fix", "moveinst")
if is_mute():
log = None
try:
log = LogFile(
level = SystemSettings()['system']['log_level'],
filename = etpConst['entropylogfile'],
header = "[spm]"
)
subprocess.call(args, env = env, stdout = log,
stderr = log)
finally:
if log is not None:
log.flush()
log.close()
else:
if os.access(emaint_exec, os.X_OK):
subprocess.call(args, env = env)
# else meh!
vartree = self._get_portage_vartree(root = root)
move = vartree.dbapi.move_ent
slotmove = vartree.dbapi.move_slot_ent
commands = []
for action in actions:
mytxt = "%s: %s: %s." % (
brown(_("SPM")),
purple(_("action")),
blue(action),
)
self.__output.output(
mytxt,
importance = 1,
level = "warning",
header = darkred(" * ")
)
command = action.split()
if command[0] == "move":
move(command)
commands.append(command)
elif command[0] == "slotmove":
slotmove(command)
commands.append(command)
mytxt = "%s: %s." % (
brown(_("SPM")),
purple(_("updating metadata")),
)
self.__output.output(
mytxt,
importance = 1,
level = "warning",
header = darkred(" * ")
)
vartree.dbapi.update_ents(commands)
def match_package(self, package, match_type = None):
"""
+5 -2
View File
@@ -24,7 +24,7 @@ import entropy.tools
class SpmPlugin(Singleton):
"""Base class for Source Package Manager plugins"""
BASE_PLUGIN_API_VERSION = 10
BASE_PLUGIN_API_VERSION = 11
# this must be reimplemented by subclasses and value
# must match BASE_PLUGIN_API_VERSION
@@ -355,10 +355,13 @@ class SpmPlugin(Singleton):
"""
raise NotImplementedError()
def packages_repositories_metadata_update(self):
def packages_repositories_metadata_update(self, actions):
"""
Executes Source Package Manager available packages repositories
metadata update.
@param actions: a list of metadata update strings
@type actions: list
"""
raise NotImplementedError()