MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / parse_copyright_file

Function parse_copyright_file

src/packagedcode/debian_copyright.py:342–399  ·  view source on GitHub ↗

Return a DebianDetector Object containing copyright and license detections extracted from the debian copyright file at ``location``. If ``check_consistency`` is True, check if debian copyright file is consistently structured according to the guidelines specified at https://www.

(location, check_consistency=False)

Source from the content-addressed store, hash-verified

340
341
342def parse_copyright_file(location, check_consistency=False):
343 """
344 Return a DebianDetector Object containing copyright and license detections
345 extracted from the debian copyright file at ``location``.
346
347 If ``check_consistency`` is True, check if debian copyright file is
348 consistently structured according to the guidelines specified at
349 https://www.debian.org/doc/packaging-manuals/copyright-format/1.0
350 """
351 if not location or not location.endswith('copyright'):
352 return
353
354 # FIXME: we should not read the whole files here and then discard it!
355 text = unicode_text(location)
356 if EnhancedDebianCopyright.is_machine_readable_copyright(text):
357 try:
358 dc = StructuredCopyrightProcessor.from_file(
359 location=location,
360 check_consistency=check_consistency,
361 )
362 except NotReallyStructuredCopyrightFile:
363 if TRACE:
364 logger_debug(
365 'StructuredCopyrightProcessor.from_file: '
366 'file is not really structured:',
367 location
368 )
369 dc = UnstructuredCopyrightProcessor.from_file(
370 location=location,
371 check_consistency=check_consistency,
372 )
373 else:
374 dc = UnstructuredCopyrightProcessor.from_file(
375 location=location,
376 check_consistency=check_consistency,
377 )
378
379 if check_consistency and dc.consistency_errors:
380 msg = (
381 f'Debian Copyright file in not consistent, because of the following:'
382 f' {dc.consistency_errors}'
383 )
384 raise DebianCopyrightStructureError(msg)
385
386 if TRACE:
387 logger_debug(f'parse_copyright_file: {type(dc)}')
388 if isinstance(dc, StructuredCopyrightProcessor):
389 for det in dc.license_detections:
390 print()
391 print(type(det.paragraph))
392 for f in det.paragraph.get_field_names():
393 print(f' {f}: {getattr(det.paragraph, f)}')
394 print()
395 for m in det.license_matches:
396 print(m)
397 print()
398
399 return dc

Callers 1

parseMethod · 0.85

Calls 6

unicode_textFunction · 0.90
logger_debugFunction · 0.70
typeClass · 0.50
from_fileMethod · 0.45

Tested by

no test coverage detected