1
1
#!/usr/bin/env python
2
-
3
2
'''
3
+ Created on June 6, 2023
4
+ @author: emcleod
5
+
6
+ Copyright (C) 2023 Synopsys, Inc.
7
+ http://www.blackducksoftware.com/
8
+
9
+ Licensed to the Apache Software Foundation (ASF) under one
10
+ or more contributor license agreements. See the NOTICE file
11
+ distributed with this work for additional information
12
+ regarding copyright ownership. The ASF licenses this file
13
+ to you under the Apache License, Version 2.0 (the
14
+ "License"); you may not use this file except in compliance
15
+ with the License. You may obtain a copy of the License at
16
+
17
+ http://www.apache.org/licenses/LICENSE-2.0
18
+
19
+ Unless required by applicable law or agreed to in writing,
20
+ software distributed under the License is distributed on an
21
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22
+ KIND, either express or implied. See the License for the
23
+ specific language governing permissions and limitations
24
+ under the License.
25
+
26
+ This script will perform bulk update of Project version PHASE based on
27
+ the content of an EXCEL file. Each row of a file is expected to contain
28
+ a field for Project Name Project Version and desired phase.
29
+ Script will iterate through the rows of a spreadsheet and issue an API
30
+ call per row.
31
+
4
32
Purpose: Update project versions with licenses of their subprojects (components)
5
33
6
- usage: update_project_with_component_licenses.py [-h] -u BASE_URL -t TOKEN_FILE [-nv]
34
+ Requirements
35
+
36
+ - python3 version 3.8 or newer recommended
37
+ - the following packages are used by the script and should be installed
38
+ prior to use:
39
+ argparse
40
+ json
41
+ logging
42
+ requests
43
+ sys
44
+ blackduck
45
+ pprint
46
+ - Blackduck instance
47
+ - API token with sufficient privileges to perform project version phase
48
+ change.
49
+
50
+ Install python packages with the following command:
51
+
52
+ pip3 install argparse json logging requests sys blackduck pprint
53
+
54
+ Usage: update_project_with_component_licenses.py [-h] -u BASE_URL -t TOKEN_FILE [-nv] -p PROJECT_NAME -pv VERSION_NAME
7
55
8
56
options:
9
57
-h, --help show this help message and exit
@@ -123,7 +171,7 @@ def process_project_version(args):
123
171
assert len (versions ) == 1 , f"There should be one, and only one version named { args .version_name } . We found { len (versions )} "
124
172
version = versions [0 ]
125
173
126
- pprint ("Currently processing SubProjectes of Project " + project ['name' ] + " version " + version ['versionName' ])
174
+ pprint ("Currently processing SubProjectes of Project ' " + project ['name' ] + "' version ' " + version ['versionName' ] + "'" )
127
175
#Return only sub-projects, not components
128
176
components = getcomponents (version , "Version" )
129
177
@@ -144,7 +192,7 @@ def process_project_version(args):
144
192
subproject ['licenses' ]= licenseblock
145
193
try :
146
194
r = bd .session .put (url ,json = subproject )
147
- print ("Updated SubProject " + subproject ['componentName' ] + " with child licenses" )
195
+ print ("Updated SubProject ' " + subproject ['componentName' ] + "' with child licenses" )
148
196
except KeyError as err :
149
197
pprint (err )
150
198
0 commit comments