Skip to content

Commit 3e53a4b

Browse files
Change version name in the link in the header file to the target version.
1 parent 0a44916 commit 3e53a4b

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

examples/bdio_update_project_name_and_version.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def zip_create_archive(zip_file, dir_name):
8585

8686
def jsonld_update_project_name(data, name):
8787
content_array = data['@graph']
88-
88+
if not content_array:
89+
return
8990
for counter, array_entry in enumerate(content_array):
9091
if array_entry['@type'][0] == 'https://blackducksoftware.github.io/bdio#Project':
9192
logging.debug(counter)
@@ -94,10 +95,19 @@ def jsonld_update_project_name(data, name):
9495
content_array[counter]["https://blackducksoftware.github.io/bdio#hasName"][0]['@value'] = name
9596
logging.debug(content_array[counter])
9697

98+
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'}
100+
if not scan_name_dict:
101+
return
102+
version_link = scan_name_dict.popitem()[1].split('/')
103+
version_link[1] = version
104+
version_list = [{'@value':'/'.join(version_link)}]
105+
data.update({'https://blackducksoftware.github.io/bdio#hasName':version_list})
97106

98107
def jsonld_update_project_version(data, version):
99108
content_array = data['@graph']
100-
109+
if not content_array:
110+
return
101111
for counter, array_entry in enumerate(content_array):
102112
if array_entry['@type'][0] == 'https://blackducksoftware.github.io/bdio#Project':
103113
logging.debug(counter)
@@ -131,14 +141,17 @@ def bdio_update_project_version():
131141
zip_extract_files(os.path.join(bdio_dir, file), temp_dir)
132142
os.chdir(temp_dir)
133143
output_bdio = os.path.join(temp_dir, file)
134-
jsonld_files = [y for y in os.listdir(temp_dir) if y.split('-').pop(1) == 'entry']
144+
jsonld_files = [y for y in os.listdir(temp_dir) if y.endswith('.jsonld')]
135145
for jsonld_file in jsonld_files:
136146
jsonld_path = os.path.join(temp_dir, jsonld_file)
137147
data = read_json_object(jsonld_path)
138148
jsonld_update_project_name(data, project_name)
139-
jsonld_update_project_version(data, target_version)
149+
if jsonld_file.split('-')[1] == 'header.jsonld':
150+
jsonld_update_version_name_in_header(data, target_version)
151+
else:
152+
jsonld_update_project_version(data,target_version)
140153
write_json_file(jsonld_path, data)
141-
zip_create_archive(output_bdio, temp_dir)
154+
zip_create_archive(output_bdio, temp_dir)
142155
shutil.copy(output_bdio, renamed_directory)
143156
print('Cleaning up temp directory ')
144157
do_refresh('temp')

0 commit comments

Comments
 (0)