Skip to content

Commit f5a20a6

Browse files
authored
Add a list-pipelines management command #1397 (#1428)
* Add a `list-pipelines` management command #1397 Signed-off-by: tdruez <tdruez@nexb.com> * Refine the output of the list-pipelines command #1397 Signed-off-by: tdruez <tdruez@nexb.com> * Add unit test for the list-pipelines command #1397 Signed-off-by: tdruez <tdruez@nexb.com> --------- Signed-off-by: tdruez <tdruez@nexb.com>
1 parent e2b6d6b commit f5a20a6

File tree

5 files changed

+117
-11
lines changed

5 files changed

+117
-11
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ v34.9.0 (unreleased)
77
- Add ability to declared pipeline selected groups in create project REST API endpoint.
88
https://github.com/aboutcode-org/scancode.io/issues/1426
99

10+
- Add a new ``list-pipelines`` management command.
11+
https://github.com/aboutcode-org/scancode.io/issues/1397
12+
1013
v34.8.3 (2024-10-30)
1114
--------------------
1215

docs/built-in-pipelines.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Analyse Docker Windows Image
4545
.. _pipeline_collect_strings_gettext:
4646

4747
Collect string with Xgettext (addon)
48-
---------------------------------------------
48+
------------------------------------
4949
.. autoclass:: scanpipe.pipelines.collect_strings_gettext.CollectStringsGettext()
5050
:members:
5151
:member-order: bysource

docs/command-line-interface.rst

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,23 @@ ScanPipe's own commands are listed under the ``[scanpipe]`` section::
5454
$ scanpipe --help
5555
...
5656
[scanpipe]
57-
add-input
58-
add-pipeline
59-
archive-project
60-
create-project
61-
delete-project
62-
execute
63-
list-project
64-
output
65-
show-pipeline
66-
status
57+
add-input
58+
add-pipeline
59+
archive-project
60+
check-compliance
61+
create-project
62+
create-user
63+
delete-project
64+
execute
65+
flush-projects
66+
list-pipelines
67+
list-project
68+
output
69+
purldb-scan-worker
70+
reset-project
71+
run
72+
show-pipeline
73+
status
6774

6875

6976
`$ scanpipe <subcommand> --help`
@@ -127,6 +134,17 @@ Optional arguments:
127134
Pipelines are added and are executed in order.
128135

129136

137+
`$ scanpipe list-pipeline [--verbosity {0,1,2,3}]`
138+
--------------------------------------------------
139+
140+
Displays a list of available pipelines.
141+
Use ``--verbosity=2`` to include details of each pipeline's steps."
142+
143+
Optional arguments:
144+
145+
- ``--verbosity {0,1,2}`` Verbosity level.
146+
147+
130148
`$ scanpipe list-project [--search SEARCH] [--include-archived]`
131149
----------------------------------------------------------------
132150

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# http://nexb.com and https://github.com/aboutcode-org/scancode.io
4+
# The ScanCode.io software is licensed under the Apache License version 2.0.
5+
# Data generated with ScanCode.io is provided as-is without warranties.
6+
# ScanCode is a trademark of nexB Inc.
7+
#
8+
# You may not use this software except in compliance with the License.
9+
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
10+
# Unless required by applicable law or agreed to in writing, software distributed
11+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
# specific language governing permissions and limitations under the License.
14+
#
15+
# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES
16+
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
17+
# ScanCode.io should be considered or used as legal advice. Consult an Attorney
18+
# for any legal advice.
19+
#
20+
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
21+
# Visit https://github.com/aboutcode-org/scancode.io for support and download.
22+
23+
24+
from django.apps import apps
25+
from django.core.management.base import BaseCommand
26+
27+
scanpipe_app = apps.get_app_config("scanpipe")
28+
29+
30+
class Command(BaseCommand):
31+
help = (
32+
"Displays a list of available pipelines. "
33+
"Use --verbosity=2 to include details of each pipeline's steps."
34+
)
35+
36+
def handle(self, *args, **options):
37+
verbosity = options["verbosity"]
38+
39+
for module_name, pipeline_class in scanpipe_app.pipelines.items():
40+
msg = self.style.HTTP_INFO(module_name)
41+
if pipeline_class.is_addon:
42+
msg += " (addon)"
43+
self.stdout.write(msg)
44+
pipeline_info = pipeline_class.get_info()
45+
if verbosity >= 1:
46+
self.stdout.write(pipeline_info["summary"])
47+
48+
if verbosity >= 2:
49+
steps = pipeline_info["steps"]
50+
for step_info in steps:
51+
step_name = step_info["name"]
52+
step_doc = step_info["doc"].replace("\n", "\n ")
53+
step_groups = step_info["groups"]
54+
self.stdout.write(f" > [{step_name}]: {step_doc}")
55+
if step_groups:
56+
self.stdout.write(f" {{Group}}: {','.join(step_groups)}")
57+
58+
if verbosity >= 1:
59+
self.stdout.write("\n")

scanpipe/tests/test_commands.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,32 @@ def test_scanpipe_management_command_status(self):
451451
)
452452
self.assertIn(expected, output)
453453

454+
def test_scanpipe_management_command_list_pipelines(self):
455+
options = []
456+
out = StringIO()
457+
call_command("list-pipelines", *options, stdout=out)
458+
output = out.getvalue()
459+
self.assertIn("analyze_docker_image", output)
460+
self.assertIn("Analyze Docker images.", output)
461+
self.assertIn("(addon)", output)
462+
self.assertNotIn("[extract_images]", output)
463+
self.assertNotIn("Extract images from input tarballs.", output)
464+
465+
options = ["--verbosity=2"]
466+
out = StringIO()
467+
call_command("list-pipelines", *options, stdout=out)
468+
output = out.getvalue()
469+
self.assertIn("[extract_images]", output)
470+
self.assertIn("Extract images from input tarballs.", output)
471+
472+
options = ["--verbosity=0"]
473+
out = StringIO()
474+
call_command("list-pipelines", *options, stdout=out)
475+
output = out.getvalue()
476+
self.assertIn("analyze_docker_image", output)
477+
self.assertNotIn("Analyze Docker images.", output)
478+
self.assertIn("(addon)", output)
479+
454480
def test_scanpipe_management_command_list_project(self):
455481
project1 = Project.objects.create(name="project1")
456482
project2 = Project.objects.create(name="project2")

0 commit comments

Comments
 (0)