Skip to content

Commit 7c61e01

Browse files
committed
Merge remote-tracking branch 'upstream/262-shallow-extraction' into develop
2 parents df14210 + fc792d8 commit 7c61e01

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/scancode/extract_cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,13 @@ class ExtractCommand(utils.BaseCommand):
8686

8787
@click.option('--verbose', is_flag=True, default=False, help='Print verbose file-by-file progress messages.')
8888
@click.option('--quiet', is_flag=True, default=False, help='Do not print any summary or progress message.')
89+
@click.option('--shallow', is_flag=True, default=False, help='Do not extract recursively nested archives (e.g. not archives in archives).')
8990

9091
@click.help_option('-h', '--help')
9192
@click.option('--about', is_flag=True, is_eager=True, callback=print_about, help='Show information about ScanCode and licensing and exit.')
9293
@click.option('--version', is_flag=True, is_eager=True, callback=print_version, help='Show the version and exit.')
9394

94-
def extractcode(ctx, input, verbose, quiet, *args, **kwargs): # @ReservedAssignment
95+
def extractcode(ctx, input, verbose, quiet, shallow, *args, **kwargs): # @ReservedAssignment
9596
"""extract archives and compressed files found in the <input> file or directory tree.
9697
9798
Use this command before scanning proper as an <input> preparation step.
@@ -156,7 +157,7 @@ def display_extract_summary():
156157
if not quiet:
157158
echo_stderr('Extracting archives...', fg='green')
158159

159-
with utils.progressmanager(extract_archives(abs_location), item_show_func=extract_event,
160+
with utils.progressmanager(extract_archives(abs_location, recurse=not shallow), item_show_func=extract_event,
160161
verbose=verbose, quiet=quiet) as extraction_events:
161162
for xev in extraction_events:
162163
if xev.done and (xev.warnings or xev.errors):
801 Bytes
Binary file not shown.

tests/scancode/test_extract_cli.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,21 @@ def test_extractcode_command_can_extract_archive_with_unicode_names(monkeypatch)
209209
'/unicodepath/koristenjem_Karkkainen_-_Sander.pdf'
210210
]
211211
assert sorted(expected) == sorted(file_result)
212+
213+
214+
def test_extractcode_command_can_extract_shallow(monkeypatch):
215+
test_dir = test_env.get_test_loc('extract_shallow', copy=True)
216+
monkeypatch.setattr(click._termui_impl, 'isatty', lambda _: True)
217+
runner = CliRunner()
218+
result = runner.invoke(extract_cli.extractcode, ['--shallow', test_dir])
219+
assert result.exit_code == 0
220+
file_result = [f for f in map(as_posixpath, file_iter(test_dir)) if not f.endswith('unicodepath.tgz')]
221+
file_result = [''.join(f.partition('/top.zip-extract/')[1:]) for f in file_result]
222+
file_result = [f for f in file_result if f]
223+
# this checks that the zip in top.zip are not extracted
224+
expected = [
225+
'/top.zip-extract/some3.zip',
226+
'/top.zip-extract/some2.zip',
227+
'/top.zip-extract/some1.zip',
228+
]
229+
assert sorted(expected) == sorted(file_result)

0 commit comments

Comments
 (0)