Skip to content

Commit bbf1b16

Browse files
For each bdio file, change the UUID in the jsonld files so Black Duck treats them as a net new scan.
1 parent 3e53a4b commit bbf1b16

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

examples/bdio_update_project_name_and_version.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
import logging
77
import zipfile
8+
import uuid
89
from zipfile import ZIP_DEFLATED
910

1011
parser = argparse.ArgumentParser("Take a directory of bdio files, copy and unzip each file,"
@@ -95,14 +96,22 @@ def jsonld_update_project_name(data, name):
9596
content_array[counter]["https://blackducksoftware.github.io/bdio#hasName"][0]['@value'] = name
9697
logging.debug(content_array[counter])
9798

99+
100+
def jsonld_update_uuid(data, new_uuid):
101+
logging.debug("Updating jsonld file to new UUID: {}".format(new_uuid))
102+
data.update({'@id': new_uuid})
103+
104+
98105
def jsonld_update_version_name_in_header(data, version):
99-
scan_name_dict = {k:v[0].get('@value') for (k,v) in data.items() if k == 'https://blackducksoftware.github.io/bdio#hasName'}
106+
scan_name_dict = {k: v[0].get('@value') for (k, v) in data.items() if
107+
k == 'https://blackducksoftware.github.io/bdio#hasName'}
100108
if not scan_name_dict:
101109
return
102110
version_link = scan_name_dict.popitem()[1].split('/')
103111
version_link[1] = version
104-
version_list = [{'@value':'/'.join(version_link)}]
105-
data.update({'https://blackducksoftware.github.io/bdio#hasName':version_list})
112+
version_list = [{'@value': '/'.join(version_link)}]
113+
data.update({'https://blackducksoftware.github.io/bdio#hasName': version_list})
114+
106115

107116
def jsonld_update_project_version(data, version):
108117
content_array = data['@graph']
@@ -142,14 +151,16 @@ def bdio_update_project_version():
142151
os.chdir(temp_dir)
143152
output_bdio = os.path.join(temp_dir, file)
144153
jsonld_files = [y for y in os.listdir(temp_dir) if y.endswith('.jsonld')]
154+
new_uuid = uuid.uuid1()
145155
for jsonld_file in jsonld_files:
146156
jsonld_path = os.path.join(temp_dir, jsonld_file)
147157
data = read_json_object(jsonld_path)
148158
jsonld_update_project_name(data, project_name)
159+
jsonld_update_uuid(data, "urn:uuid:{}".format(new_uuid))
149160
if jsonld_file.split('-')[1] == 'header.jsonld':
150161
jsonld_update_version_name_in_header(data, target_version)
151162
else:
152-
jsonld_update_project_version(data,target_version)
163+
jsonld_update_project_version(data, target_version)
153164
write_json_file(jsonld_path, data)
154165
zip_create_archive(output_bdio, temp_dir)
155166
shutil.copy(output_bdio, renamed_directory)
@@ -159,7 +170,6 @@ def bdio_update_project_version():
159170
shutil.rmtree('temp')
160171

161172

162-
163173
def main():
164174
check_dirs()
165175
bdio_update_project_version()

0 commit comments

Comments
 (0)