show external status as [e] (#33792)
This commit is contained in:
parent
0fd224404a
commit
e5f270c8da
@ -686,7 +686,7 @@ def is_relocatable(spec):
|
|||||||
Raises:
|
Raises:
|
||||||
ValueError: if the spec is not installed
|
ValueError: if the spec is not installed
|
||||||
"""
|
"""
|
||||||
if not spec.install_status():
|
if not spec.installed:
|
||||||
raise ValueError("spec is not installed [{0}]".format(str(spec)))
|
raise ValueError("spec is not installed [{0}]".format(str(spec)))
|
||||||
|
|
||||||
if spec.external or spec.virtual:
|
if spec.external or spec.virtual:
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
"""
|
"""
|
||||||
import collections
|
import collections
|
||||||
import collections.abc
|
import collections.abc
|
||||||
|
import enum
|
||||||
import io
|
import io
|
||||||
import itertools
|
import itertools
|
||||||
import os
|
import os
|
||||||
@ -173,6 +174,16 @@
|
|||||||
SPECFILE_FORMAT_VERSION = 3
|
SPECFILE_FORMAT_VERSION = 3
|
||||||
|
|
||||||
|
|
||||||
|
# InstallStatus is used to map install statuses to symbols for display
|
||||||
|
# Options are artificially disjoint for dispay purposes
|
||||||
|
class InstallStatus(enum.Enum):
|
||||||
|
installed = "@g{[+]} "
|
||||||
|
upstream = "@g{[^]} "
|
||||||
|
external = "@g{[e]} "
|
||||||
|
absent = "@K{ - } "
|
||||||
|
missing = "@r{[-]} "
|
||||||
|
|
||||||
|
|
||||||
def colorize_spec(spec):
|
def colorize_spec(spec):
|
||||||
"""Returns a spec colorized according to the colors specified in
|
"""Returns a spec colorized according to the colors specified in
|
||||||
color_formats."""
|
color_formats."""
|
||||||
@ -4401,12 +4412,20 @@ def __str__(self):
|
|||||||
def install_status(self):
|
def install_status(self):
|
||||||
"""Helper for tree to print DB install status."""
|
"""Helper for tree to print DB install status."""
|
||||||
if not self.concrete:
|
if not self.concrete:
|
||||||
return None
|
return InstallStatus.absent
|
||||||
try:
|
|
||||||
record = spack.store.db.get_record(self)
|
if self.external:
|
||||||
return record.installed
|
return InstallStatus.external
|
||||||
except KeyError:
|
|
||||||
return None
|
upstream, record = spack.store.db.query_by_spec_hash(self.dag_hash())
|
||||||
|
if not record:
|
||||||
|
return InstallStatus.absent
|
||||||
|
elif upstream and record.installed:
|
||||||
|
return InstallStatus.upstream
|
||||||
|
elif record.installed:
|
||||||
|
return InstallStatus.installed
|
||||||
|
else:
|
||||||
|
return InstallStatus.missing
|
||||||
|
|
||||||
def _installed_explicitly(self):
|
def _installed_explicitly(self):
|
||||||
"""Helper for tree to print DB install status."""
|
"""Helper for tree to print DB install status."""
|
||||||
@ -4420,7 +4439,10 @@ def _installed_explicitly(self):
|
|||||||
|
|
||||||
def tree(self, **kwargs):
|
def tree(self, **kwargs):
|
||||||
"""Prints out this spec and its dependencies, tree-formatted
|
"""Prints out this spec and its dependencies, tree-formatted
|
||||||
with indentation."""
|
with indentation.
|
||||||
|
|
||||||
|
Status function may either output a boolean or an InstallStatus
|
||||||
|
"""
|
||||||
color = kwargs.pop("color", clr.get_color_when())
|
color = kwargs.pop("color", clr.get_color_when())
|
||||||
depth = kwargs.pop("depth", False)
|
depth = kwargs.pop("depth", False)
|
||||||
hashes = kwargs.pop("hashes", False)
|
hashes = kwargs.pop("hashes", False)
|
||||||
@ -4452,14 +4474,12 @@ def tree(self, **kwargs):
|
|||||||
|
|
||||||
if status_fn:
|
if status_fn:
|
||||||
status = status_fn(node)
|
status = status_fn(node)
|
||||||
if node.installed_upstream:
|
if status in list(InstallStatus):
|
||||||
out += clr.colorize("@g{[^]} ", color=color)
|
out += clr.colorize(status.value, color=color)
|
||||||
elif status is None:
|
|
||||||
out += clr.colorize("@K{ - } ", color=color) # !installed
|
|
||||||
elif status:
|
elif status:
|
||||||
out += clr.colorize("@g{[+]} ", color=color) # installed
|
out += clr.colorize("@g{[+]} ", color=color)
|
||||||
else:
|
else:
|
||||||
out += clr.colorize("@r{[-]} ", color=color) # missing
|
out += clr.colorize("@r{[-]} ", color=color)
|
||||||
|
|
||||||
if hashes:
|
if hashes:
|
||||||
out += clr.colorize("@K{%s} ", color=color) % node.dag_hash(hlen)
|
out += clr.colorize("@K{%s} ", color=color) % node.dag_hash(hlen)
|
||||||
|
Loading…
Reference in New Issue
Block a user