12
12
from io import BytesIO
13
13
from io import StringIO
14
14
15
- from spdx .checksum import Algorithm
15
+ from spdx .checksum import Checksum
16
+ from spdx .checksum import ChecksumAlgorithm
16
17
from spdx .creationinfo import Tool
17
18
from spdx .document import ExtractedLicense
18
19
from spdx .document import Document
19
- from spdx .document import License
20
+ from spdx .license import License
20
21
from spdx .file import File
21
22
from spdx .package import Package
23
+ from spdx .relationship import Relationship
24
+ from spdx .utils import calc_verif_code
22
25
from spdx .utils import NoAssert
23
26
from spdx .utils import SPDXNone
24
27
from spdx .version import Version
@@ -280,9 +283,8 @@ def write_spdx(
280
283
name = './' + file_data .get ('path' )
281
284
file_entry = File (
282
285
spdx_id = f'SPDXRef-{ sid } ' ,
283
- name = name ,
284
- chk_sum = Algorithm ('SHA1' , file_data .get ('sha1' ) or '' )
285
- )
286
+ name = name )
287
+ file_entry .set_checksum (Checksum (ChecksumAlgorithm .SHA1 , file_data .get ('sha1' ) or '' ))
286
288
287
289
file_license_detections = file_data .get ('license_detections' )
288
290
license_matches = get_matches_from_detection_mappings (file_license_detections )
@@ -357,9 +359,11 @@ def write_spdx(
357
359
else :
358
360
file_entry .copyright = SPDXNone ()
359
361
360
- package .add_file (file_entry )
362
+ doc .add_file (file_entry )
363
+ relationship = Relationship (f'{ package .spdx_id } CONTAINS { file_entry .spdx_id } ' )
364
+ doc .add_relationship (relationship )
361
365
362
- if len ( package .files ) == 0 :
366
+ if not doc .files :
363
367
if as_tagvalue :
364
368
msg = "# No results for package '{}'.\n " .format (package .name )
365
369
else :
@@ -392,7 +396,7 @@ def write_spdx(
392
396
# statements for the package.
393
397
package .cr_text = '\n ' .join (sorted (package .cr_text )) + '\n '
394
398
395
- package .verif_code = doc . package . calc_verif_code ()
399
+ package .verif_code = calc_verif_code (doc . files )
396
400
package .license_declared = NoAssert ()
397
401
package .conc_lics = NoAssert ()
398
402
@@ -404,7 +408,7 @@ def write_spdx(
404
408
# one case we do need to deal with bytes and decode before writing (rdf) and
405
409
# in the other case we deal with text all the way.
406
410
407
- if package .files :
411
+ if doc .files :
408
412
409
413
if as_tagvalue :
410
414
from spdx .writers .tagvalue import write_document # NOQA
0 commit comments