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