Skip to content

Commit

Permalink
echo_info and set default loglevel of cmdline to INFO
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Apr 20, 2022
1 parent 35e1cc0 commit ea40e21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 6 additions & 4 deletions aiida_optimade/cli/cmd_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def calc(obj: dict, fields: Tuple[str], force_yes: bool, silent: bool):
from aiida import load_profile
from aiida.cmdline.utils import echo

echo.CMDLINE_LOGGER.setLevel("INFO")

try:
profile: str = obj.get("profile").name
except AttributeError:
Expand Down Expand Up @@ -68,12 +70,12 @@ def calc(obj: dict, fields: Tuple[str], force_yes: bool, silent: bool):
number_of_nodes = STRUCTURES.count(**query_kwargs)
if number_of_nodes:
if not silent:
echo.echo_report(
echo.echo_info(
f"Field{'s' if len(fields) > 1 else ''} found for {number_of_nodes}"
f" Node{'s' if number_of_nodes > 1 else ''}."
)
if not silent:
echo.echo_report(
echo.echo_info(
f"Total number of Nodes in profile {profile!r}: {STRUCTURES.count()}"
)

Expand Down Expand Up @@ -110,7 +112,7 @@ def calc(obj: dict, fields: Tuple[str], force_yes: bool, silent: bool):
del all_calculated_nodes

if not silent:
echo.echo_report(
echo.echo_info(
f"Done removing {', '.join(fields)} from {number_of_nodes} Node"
f"{'s' if number_of_nodes > 1 else ''}."
)
Expand Down Expand Up @@ -154,7 +156,7 @@ def calc(obj: dict, fields: Tuple[str], force_yes: bool, silent: bool):
"AiiDA-OPTIMADE."
)
else:
echo.echo_report(
echo.echo_info(
"No StructureData and CifData Nodes found to calculate field"
f"{'s' if len(fields) > 1 else ''} {', '.join(fields)} for {profile!r}."
)
14 changes: 9 additions & 5 deletions aiida_optimade/cli/cmd_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def init(obj: dict, force: bool, silent: bool, mongo: bool, filename: str):
from aiida import load_profile
from aiida.cmdline.utils import echo

# The default aiida.cmdline loglevel inherit from aiida loglevel is REPORT
# Here we use INFO loglevel for the operations
echo.CMDLINE_LOGGER.setLevel("INFO")

filename: Path = Path(filename) if filename else filename

if mongo and filename:
Expand Down Expand Up @@ -77,7 +81,7 @@ def init(obj: dict, force: bool, silent: bool, mongo: bool, filename: str):
)
STRUCTURES_MONGO.collection.drop()
if not silent:
echo.echo_report(
echo.echo_info(
f"Done dropping {STRUCTURES_MONGO.collection.full_name!r} "
"collection."
)
Expand All @@ -90,7 +94,7 @@ def init(obj: dict, force: bool, silent: bool, mongo: bool, filename: str):

number_of_nodes = STRUCTURES.count(**query_kwargs)
if not silent:
echo.echo_report(
echo.echo_info(
"Forcing re-calculation. About to remove OPTIMADE-specific "
f"extras for {number_of_nodes} Nodes."
)
Expand All @@ -111,13 +115,13 @@ def init(obj: dict, force: bool, silent: bool, mongo: bool, filename: str):
del all_calculated_nodes

if not silent:
echo.echo_report(
echo.echo_info(
f"Done removing extra {extras_key!r} in {number_of_nodes} "
"Nodes."
)

if not silent:
echo.echo_report(f"Initializing {profile}.")
echo.echo_info(f"Initializing {profile}.")
echo.echo_warning("This may take several minutes!")

if filename:
Expand Down Expand Up @@ -209,7 +213,7 @@ def init(obj: dict, force: bool, silent: bool, mongo: bool, filename: str):
"documents have been initialized."
)
else:
echo.echo_report(
echo.echo_info(
"No new StructureData and CifData Nodes or MongoDB documents found to "
f"initialize for {profile}."
)
Expand Down

0 comments on commit ea40e21

Please sign in to comment.