Skip to content

Commit f18293d

Browse files
committed
Move extractcode API to extractcode #2233
Also move extractcli tests there Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 2199bfa commit f18293d

File tree

13 files changed

+430
-10
lines changed

13 files changed

+430
-10
lines changed

src/extractcode/NOTICE

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Software license
2+
================
3+
4+
Copyright (c) 2017 nexB Inc. and others. All rights reserved.
5+
http://nexb.com and https://github.com/nexB/scancode-toolkit/
6+
The ScanCode software is licensed under the Apache License version 2.0.
7+
Data generated with ScanCode require an acknowledgment.
8+
ScanCode is a trademark of nexB Inc.
9+
10+
You may not use this software except in compliance with the License.
11+
You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
12+
Unless required by applicable law or agreed to in writing, software distributed
13+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
specific language governing permissions and limitations under the License.
16+
17+
When you publish or redistribute any data created with ScanCode or any ScanCode
18+
derivative work, you must accompany this data with the following acknowledgment:
19+
20+
Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
21+
OR CONDITIONS OF ANY KIND, either express or implied. No content created from
22+
ScanCode should be considered or used as legal advice. Consult an Attorney
23+
for any legal advice.
24+
ScanCode is a free software code scanning tool from nexB Inc. and others.
25+
Visit https://github.com/nexB/scancode-toolkit/ for support and download.
26+
27+
28+
Third-party software licenses
29+
=============================
30+
31+
ScanCode embeds third-party free and open source software packages under various
32+
licenses including copyleft licenses. Some of the third-party software packages
33+
are delivered as pre-built binaries. The origin and license of these packages is
34+
documented by .ABOUT files.
35+
36+
The corresponding source code for pre-compiled third-party software is available
37+
for immediate download from the same release page where you obtained ScanCode at:
38+
https://github.com/nexB/scancode-toolkit/
39+
or https://github.com/nexB/scancode-thirdparty-src/
40+
41+
You may also contact us to request the source code by email at info@nexb.com or
42+
by postal mail at:
43+
44+
nexB Inc., ScanCode open source code request
45+
735 Industrial Road, Suite #101, 94070 San Carlos, CA, USA
46+
47+
Please indicate in your communication the ScanCode version for which you are
48+
requesting source code.
49+
50+
51+
License for ScanCode datasets
52+
=============================
53+
54+
ScanCode includes datasets (e.g. for license detection) that are dedicated
55+
to the Public Domain using the Creative Commons CC0 1.0 Universal (CC0 1.0)
56+
Public Domain Dedication: http://creativecommons.org/publicdomain/zero/1.0/

src/extractcode/api.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# http://nexb.com and https://github.com/nexB/scancode-toolkit/
4+
# The ScanCode software is licensed under the Apache License version 2.0.
5+
# Data generated with ScanCode require an acknowledgment.
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+
# When you publish or redistribute any data created with ScanCode or any ScanCode
16+
# derivative work, you must accompany this data with the following acknowledgment:
17+
#
18+
# Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
19+
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
20+
# ScanCode should be considered or used as legal advice. Consult an Attorney
21+
# for any legal advice.
22+
# ScanCode is a free software code scanning tool from nexB Inc. and others.
23+
# Visit https://github.com/nexB/scancode-toolkit/ for support and download.
24+
25+
from __future__ import absolute_import
26+
from __future__ import division
27+
from __future__ import print_function
28+
from __future__ import unicode_literals
29+
30+
31+
"""
32+
Note: this API is unstable and still evolving.
33+
"""
34+
35+
36+
def extract_archives(location, recurse=True, replace_originals=False, ignore_pattern=()):
37+
"""
38+
Yield ExtractEvent while extracting archive(s) and compressed files at
39+
`location`. If `recurse` is True, extract nested archives-in-archives
40+
recursively.
41+
Archives and compressed files are extracted in a directory named
42+
"<file_name>-extract" created in the same directory as the archive.
43+
Note: this API is returning an iterable and NOT a sequence.
44+
"""
45+
from extractcode.extract import extract
46+
from extractcode import default_kinds
47+
for xevent in extract(
48+
location=location,
49+
kinds=default_kinds,
50+
recurse=recurse,
51+
replace_originals=replace_originals,
52+
ignore_pattern=ignore_pattern
53+
):
54+
yield xevent

src/extractcode/cli.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,21 @@
2727
from __future__ import unicode_literals
2828

2929
from functools import partial
30-
import os
30+
from os import path
3131

3232
import click
3333
click.disable_unicode_literals_warning = True
3434

35+
from commoncode import cliutils
3536
from commoncode import compat
3637
from commoncode import fileutils
3738
from commoncode import filetype
3839
from commoncode.text import toascii
3940

40-
from scancode_config import __version__
41-
from scancode.api import extract_archives
42-
from scancode import print_about
43-
from commoncode import cliutils
41+
from extractcode.api import extract_archives
42+
43+
44+
__version__ = '2020.09.21'
4445

4546

4647
echo_stderr = partial(click.secho, err=True)
@@ -49,7 +50,37 @@
4950
def print_version(ctx, param, value):
5051
if not value or ctx.resilient_parsing:
5152
return
52-
echo_stderr('ScanCode extractcode version ' + __version__)
53+
echo_stderr('ExtractCode version ' + __version__)
54+
ctx.exit()
55+
56+
info_text = '''
57+
ExtractCode is a mostly universal archive and compressed files extractor, with
58+
a particular focus on code archives.
59+
Visit https://github.com/nexB/scancode-toolkit/ for support and download.
60+
61+
'''
62+
63+
notice_path = path.join(path.abspath(path.dirname(__file__)), 'NOTICE')
64+
notice_text = open(notice_path).read()
65+
66+
delimiter = '\n\n\n'
67+
[notice_text, extra_notice_text] = notice_text.split(delimiter, 1)
68+
extra_notice_text = delimiter + extra_notice_text
69+
70+
delimiter = '\n\n '
71+
[notice_text, acknowledgment_text] = notice_text.split(delimiter, 1)
72+
acknowledgment_text = delimiter + acknowledgment_text
73+
74+
notice = acknowledgment_text.strip().replace(' ', '')
75+
76+
77+
def print_about(ctx, param, value):
78+
"""
79+
Click callback to print a notice.
80+
"""
81+
if not value or ctx.resilient_parsing:
82+
return
83+
click.echo(info_text + notice_text + acknowledgment_text + extra_notice_text)
5384
ctx.exit()
5485

5586

@@ -93,17 +124,17 @@ class ExtractCommand(cliutils.BaseCommand):
93124
@click.option('--ignore', default=[], multiple=True, help='Ignore files/directories following a glob-pattern.')
94125

95126
@click.help_option('-h', '--help')
96-
@click.option('--about', is_flag=True, is_eager=True, callback=print_about, help='Show information about ScanCode and licensing and exit.')
127+
@click.option('--about', is_flag=True, is_eager=True, callback=print_about, help='Show information about ExtractCode and licensing and exit.')
97128
@click.option('--version', is_flag=True, is_eager=True, callback=print_version, help='Show the version and exit.')
98129
def extractcode(ctx, input, verbose, quiet, shallow, replace_originals, ignore, *args, **kwargs): # NOQA
99130
"""extract archives and compressed files found in the <input> file or directory tree.
100131
101-
Use this command before scanning proper as an <input> preparation step.
102132
Archives found inside an extracted archive are extracted recursively.
103-
Extraction is done in-place in a directory named '-extract' side-by-side with an archive.
133+
Extraction for each archive is done in-place in a new directory named
134+
'<archive file name>-extract' created side-by-side with an archive.
104135
"""
105136

106-
abs_location = fileutils.as_posixpath(os.path.abspath(os.path.expanduser(input)))
137+
abs_location = fileutils.as_posixpath(path.abspath(path.expanduser(input)))
107138

108139
def extract_event(item):
109140
"""
223 Bytes
Binary file not shown.
596 Bytes
Binary file not shown.
Binary file not shown.
429 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)