-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into feature/1785109/tem…
…plates
- Loading branch information
Showing
67 changed files
with
1,366 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
[mypy] | ||
python_version = 3.5 | ||
ignore_missing_imports = True | ||
follow_imports=silent | ||
follow_imports=silent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | ||
# | ||
# Copyright (C) 2018 Canonical Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License version 3 as | ||
# published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
import click | ||
from datetime import datetime | ||
import json | ||
import logging | ||
from tabulate import tabulate | ||
|
||
from snapcraft import formatting_utils | ||
from snapcraft.internal import errors, project_loader | ||
from snapcraft.internal.project_loader import inspection | ||
from ._options import get_project | ||
from . import echo | ||
|
||
|
||
@click.group(context_settings={}) | ||
@click.pass_context | ||
def inspectcli(ctx): | ||
pass | ||
|
||
|
||
@inspectcli.command() | ||
@click.option( | ||
"--provides", | ||
metavar="<path>", | ||
help=( | ||
"Show the part that provided <path>. <path> can be relative or absolute, and " | ||
"must be pointing within the staging or priming area." | ||
), | ||
) | ||
@click.option( | ||
"--latest-step", is_flag=True, help="Show the most recently-completed step" | ||
) | ||
@click.option("--json", "use_json", is_flag=True, help="Print the result in json") | ||
def inspect(*, provides: str, latest_step: bool, use_json: bool, **kwargs): | ||
"""Inspect the current state of the project. | ||
By default, this command will print a tabulated summary of the current state of the | ||
project. | ||
""" | ||
count = 0 | ||
for option in (provides, latest_step): | ||
if option: | ||
count += 1 | ||
|
||
if count > 1: | ||
raise errors.SnapcraftEnvironmentError( | ||
"Only one of --provides or --latest-step may be supplied" | ||
) | ||
|
||
# Silence the plugin loader logger | ||
logging.getLogger("snapcraft.internal.pluginhandler._plugin_loader").setLevel( | ||
logging.ERROR | ||
) | ||
project = get_project(**kwargs) | ||
config = project_loader.load_config(project) | ||
|
||
if provides: | ||
providing_parts = inspection.provides( | ||
provides, config.project, config.all_parts | ||
) | ||
providing_part_names = sorted([p.name for p in providing_parts]) | ||
if use_json: | ||
print( | ||
json.dumps( | ||
{"path": provides, "parts": providing_part_names}, | ||
sort_keys=True, | ||
indent=4, | ||
) | ||
) | ||
else: | ||
echo.info( | ||
"This path was provided by the following {}:".format( | ||
formatting_utils.pluralize(providing_part_names, "part", "parts") | ||
) | ||
) | ||
echo.info("\n".join(providing_part_names)) | ||
|
||
elif latest_step: | ||
part, step, timestamp = inspection.latest_step(config.all_parts) | ||
directory = part.working_directory_for_step(step) | ||
if use_json: | ||
print( | ||
json.dumps( | ||
{ | ||
"part": part.name, | ||
"step": step.name, | ||
"directory": directory, | ||
"timestamp": timestamp, | ||
}, | ||
sort_keys=True, | ||
indent=4, | ||
) | ||
) | ||
else: | ||
echo.info( | ||
"The latest step that was run is the {!r} step of the {!r} part, " | ||
"which ran at {}. The working directory for this step is {!r}".format( | ||
step.name, | ||
part.name, | ||
datetime.fromtimestamp(timestamp).strftime("%c"), | ||
directory, | ||
) | ||
) | ||
|
||
else: | ||
summary = inspection.lifecycle_status(config) | ||
if use_json: | ||
summary_dict = dict() | ||
for part_summary in summary: | ||
part_name = part_summary.pop("part") | ||
summary_dict[part_name] = part_summary | ||
print(json.dumps(summary_dict, sort_keys=True, indent=4)) | ||
else: | ||
print(tabulate(summary, headers="keys")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | ||
# | ||
# Copyright (C) 2018 Canonical Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License version 3 as | ||
# published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from ._latest_step import latest_step # noqa: F401 | ||
from ._lifecycle_status import lifecycle_status # noqa: F401 | ||
from ._provides import provides # noqa: F401 |
48 changes: 48 additions & 0 deletions
48
snapcraft/internal/project_loader/inspection/_latest_step.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | ||
# | ||
# Copyright (C) 2018 Canonical Ltd | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License version 3 as | ||
# published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import contextlib | ||
from typing import List, Tuple | ||
|
||
from snapcraft.internal import pluginhandler, steps | ||
import snapcraft.internal.errors | ||
from . import errors | ||
|
||
|
||
def latest_step( | ||
parts: List[pluginhandler.PluginHandler] | ||
) -> Tuple[pluginhandler.PluginHandler, steps.Step, int]: | ||
"""Determine and return the latest step that was run. | ||
:param list parts: List of all parts. | ||
:returns: Tuple of (part, step, timestamp). | ||
""" | ||
latest_part = None | ||
latest_step = None | ||
latest_timestamp = 0 | ||
for part in parts: | ||
with contextlib.suppress(snapcraft.internal.errors.NoLatestStepError): | ||
step = part.latest_step() | ||
timestamp = part.step_timestamp(step) | ||
if latest_timestamp < timestamp: | ||
latest_part = part | ||
latest_step = step | ||
latest_timestamp = timestamp | ||
|
||
if not latest_part: | ||
raise errors.NoStepsRunError() | ||
|
||
return (latest_part, latest_step, latest_timestamp) |
Oops, something went wrong.