3
3
# ScanCode is a trademark of nexB Inc.
4
4
# SPDX-License-Identifier: Apache-2.0
5
5
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6
- # See https://github.com/nexB /extractcode for support or download.
6
+ # See https://github.com/aboutcode-org /extractcode for support or download.
7
7
# See https://aboutcode.org for more information about nexB OSS projects.
8
8
#
9
9
@@ -102,7 +102,7 @@ def should_extract(location, kinds, ignore_pattern=()):
102
102
"""
103
103
location = os .path .abspath (os .path .expanduser (location ))
104
104
ignore_pattern = {
105
- extension : 'User ignore: Supplied by --ignore'
105
+ extension : 'User ignore: Supplied by --ignore'
106
106
for extension in ignore_pattern
107
107
}
108
108
should_ignore = is_ignored (location , ignore_pattern )
@@ -218,10 +218,13 @@ def get_handlers(location):
218
218
raise Exception ('Maximum level of archive nesting is two.' )
219
219
220
220
# default to False
221
- type_matched = handler .filetypes and any (t in ftype for t in handler .filetypes )
221
+ type_matched = handler .filetypes and any (
222
+ t in ftype for t in handler .filetypes )
222
223
if TRACE_DEEP :
223
- logger .debug (f' get_handlers: handler.filetypes={ handler .filetypes } ' )
224
- mime_matched = handler .mimetypes and any (m in mtype for m in handler .mimetypes )
224
+ logger .debug (
225
+ f' get_handlers: handler.filetypes={ handler .filetypes } ' )
226
+ mime_matched = handler .mimetypes and any (
227
+ m in mtype for m in handler .mimetypes )
225
228
exts = handler .extensions
226
229
if exts :
227
230
extension_matched = exts and location .lower ().endswith (exts )
@@ -230,7 +233,7 @@ def get_handlers(location):
230
233
print (
231
234
f' get_handlers: matched type: { type_matched } , '
232
235
f'mime: { mime_matched } , ext: { extension_matched } ' % locals ()
233
- )
236
+ )
234
237
235
238
if (
236
239
handler .strict
@@ -247,7 +250,8 @@ def get_handlers(location):
247
250
if type_matched or mime_matched or extension_matched :
248
251
if TRACE_DEEP :
249
252
handler_name = handler .name
250
- logger .debug (' get_handlers: yielding handler: %(handler_name)r' % locals ())
253
+ logger .debug (
254
+ ' get_handlers: yielding handler: %(handler_name)r' % locals ())
251
255
yield handler , type_matched , mime_matched , extension_matched
252
256
253
257
@@ -267,7 +271,8 @@ def score_handlers(handlers):
267
271
# increment kind value: higher kinds numerical values are more
268
272
# specific by design
269
273
score += handler .kind
270
- if TRACE_DEEP : logger .debug (f' score_handlers: score += handler.kind { score } ' )
274
+ if TRACE_DEEP :
275
+ logger .debug (f' score_handlers: score += handler.kind { score } ' )
271
276
272
277
# increment score based on matched criteria
273
278
if type_matched and mime_matched and extension_matched :
@@ -384,13 +389,15 @@ def extract_twice(location, target_dir, extractor1, extractor2):
384
389
385
390
# extract this intermediate payload to the final target_dir
386
391
try :
387
- inner_archives = list (fileutils .resource_iter (temp_target , with_dirs = False ))
392
+ inner_archives = list (fileutils .resource_iter (
393
+ temp_target , with_dirs = False ))
388
394
if not inner_archives :
389
395
warnings .append (location + ': No files found in archive.' )
390
396
else :
391
397
for extracted1_loc in inner_archives :
392
398
if TRACE :
393
- logger .debug ('extract_twice: extractor2: %(extracted1_loc)r' % locals ())
399
+ logger .debug (
400
+ 'extract_twice: extractor2: %(extracted1_loc)r' % locals ())
394
401
warnings .extend (extractor2 (extracted1_loc , abs_target_dir ))
395
402
finally :
396
403
# cleanup the temporary output from extractor1
@@ -415,14 +422,17 @@ def extract_with_fallback(location, target_dir, extractor1, extractor2):
415
422
try :
416
423
warnings = extractor1 (abs_location , temp_target1 )
417
424
if TRACE :
418
- logger .debug ('extract_with_fallback: temp_target1: %(temp_target1)r' % locals ())
425
+ logger .debug (
426
+ 'extract_with_fallback: temp_target1: %(temp_target1)r' % locals ())
419
427
fileutils .copytree (temp_target1 , abs_target_dir )
420
428
except :
421
429
try :
422
- temp_target2 = str (fileutils .get_temp_dir (prefix = 'extractcode-extract2-' ))
430
+ temp_target2 = str (fileutils .get_temp_dir (
431
+ prefix = 'extractcode-extract2-' ))
423
432
warnings = extractor2 (abs_location , temp_target2 )
424
433
if TRACE :
425
- logger .debug ('extract_with_fallback: temp_target2: %(temp_target2)r' % locals ())
434
+ logger .debug (
435
+ 'extract_with_fallback: temp_target2: %(temp_target2)r' % locals ())
426
436
fileutils .copytree (temp_target2 , abs_target_dir )
427
437
finally :
428
438
fileutils .delete (temp_target2 )
@@ -446,7 +456,8 @@ def try_to_extract(location, target_dir, extractor):
446
456
try :
447
457
warnings = extractor (abs_location , temp_target )
448
458
if TRACE :
449
- logger .debug ('try_to_extract: temp_target: %(temp_target)r' % locals ())
459
+ logger .debug (
460
+ 'try_to_extract: temp_target: %(temp_target)r' % locals ())
450
461
fileutils .copytree (temp_target , abs_target_dir )
451
462
except :
452
463
return warnings
@@ -685,7 +696,7 @@ def try_to_extract(location, target_dir, extractor):
685
696
XzHandler = Handler (
686
697
name = 'xz' ,
687
698
filetypes = ('xz compressed' ,),
688
- mimetypes = ('application/x-xz' ,) ,
699
+ mimetypes = ('application/x-xz' ,),
689
700
extensions = ('.xz' ,),
690
701
kind = regular ,
691
702
extractors = [extract_xz ],
@@ -695,7 +706,7 @@ def try_to_extract(location, target_dir, extractor):
695
706
LzmaHandler = Handler (
696
707
name = 'lzma' ,
697
708
filetypes = ('lzma compressed' ,),
698
- mimetypes = ('application/x-xz' ,) ,
709
+ mimetypes = ('application/x-xz' ,),
699
710
extensions = ('.lzma' ,),
700
711
kind = regular ,
701
712
extractors = [extract_lzma ],
@@ -705,7 +716,7 @@ def try_to_extract(location, target_dir, extractor):
705
716
TarXzHandler = Handler (
706
717
name = 'Tar xz' ,
707
718
filetypes = ('xz compressed' ,),
708
- mimetypes = ('application/x-xz' ,) ,
719
+ mimetypes = ('application/x-xz' ,),
709
720
extensions = ('.tar.xz' , '.txz' , '.tarxz' ,),
710
721
kind = regular_nested ,
711
722
extractors = [extract_xz , extract_tar ],
@@ -715,7 +726,7 @@ def try_to_extract(location, target_dir, extractor):
715
726
TarLzmaHandler = Handler (
716
727
name = 'Tar lzma' ,
717
728
filetypes = ('lzma compressed' ,),
718
- mimetypes = ('application/x-lzma' ,) ,
729
+ mimetypes = ('application/x-lzma' ,),
719
730
extensions = ('tar.lzma' , '.tlz' , '.tarlz' , '.tarlzma' ,),
720
731
kind = regular_nested ,
721
732
extractors = [extract_lzma , extract_tar ],
@@ -726,7 +737,8 @@ def try_to_extract(location, target_dir, extractor):
726
737
name = 'Tar gzip' ,
727
738
filetypes = ('gzip compressed' ,),
728
739
mimetypes = ('application/gzip' ,),
729
- extensions = ('.tgz' , '.tar.gz' , '.tar.gzip' , '.targz' , '.targzip' , '.tgzip' ,),
740
+ extensions = ('.tgz' , '.tar.gz' , '.tar.gzip' ,
741
+ '.targz' , '.targzip' , '.tgzip' ,),
730
742
kind = regular_nested ,
731
743
extractors = [extract_tar ],
732
744
strict = False
@@ -735,7 +747,7 @@ def try_to_extract(location, target_dir, extractor):
735
747
TarLzipHandler = Handler (
736
748
name = 'Tar lzip' ,
737
749
filetypes = ('lzip compressed' ,),
738
- mimetypes = ('application/x-lzip' ,) ,
750
+ mimetypes = ('application/x-lzip' ,),
739
751
extensions = ('.tar.lz' , '.tar.lzip' ,),
740
752
kind = regular_nested ,
741
753
extractors = [extract_lzip , extract_tar ],
@@ -745,7 +757,7 @@ def try_to_extract(location, target_dir, extractor):
745
757
TarZstdHandler = Handler (
746
758
name = 'Tar zstd' ,
747
759
filetypes = ('zstandard compressed' ,),
748
- mimetypes = ('application/x-zstd' ,) ,
760
+ mimetypes = ('application/x-zstd' ,),
749
761
extensions = ('.tar.zst' , '.tar.zstd' ,),
750
762
kind = regular_nested ,
751
763
extractors = [extract_zstd , extract_tar ],
@@ -755,7 +767,7 @@ def try_to_extract(location, target_dir, extractor):
755
767
TarLz4Handler = Handler (
756
768
name = 'Tar lz4' ,
757
769
filetypes = ('lz4 compressed' ,),
758
- mimetypes = ('application/x-lz4' ,) ,
770
+ mimetypes = ('application/x-lz4' ,),
759
771
extensions = ('.tar.lz4' ,),
760
772
kind = regular_nested ,
761
773
extractors = [extract_lz4 , extract_tar ],
@@ -788,7 +800,7 @@ def try_to_extract(location, target_dir, extractor):
788
800
LzipHandler = Handler (
789
801
name = 'lzip' ,
790
802
filetypes = ('lzip compressed' ,),
791
- mimetypes = ('application/x-lzip' ,) ,
803
+ mimetypes = ('application/x-lzip' ,),
792
804
extensions = ('.lzip' ,),
793
805
kind = regular ,
794
806
extractors = [extract_lzip ],
@@ -798,7 +810,7 @@ def try_to_extract(location, target_dir, extractor):
798
810
ZstdHandler = Handler (
799
811
name = 'zstd' ,
800
812
filetypes = ('zstandard compressed' ,),
801
- mimetypes = ('application/x-zstd' ,) ,
813
+ mimetypes = ('application/x-zstd' ,),
802
814
extensions = ('.zst' , '.zstd' ,),
803
815
kind = regular_nested ,
804
816
extractors = [extract_zstd ],
@@ -808,7 +820,7 @@ def try_to_extract(location, target_dir, extractor):
808
820
Lz4Handler = Handler (
809
821
name = 'lz4' ,
810
822
filetypes = ('lz4 compressed' ,),
811
- mimetypes = ('application/x-lz4' ,) ,
823
+ mimetypes = ('application/x-lz4' ,),
812
824
extensions = ('.lz4' ,),
813
825
kind = regular_nested ,
814
826
extractors = [extract_lz4 ],
0 commit comments