Skip to content

Commit f4c6200

Browse files
committed
Sub-project specification with excel file
1 parent 39e6d34 commit f4c6200

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

examples/client/multi-image/manage_project_structure.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
Project Version Name
5151
-sp SUBPROJECT_LIST, --subproject-list SUBPROJECT_LIST
5252
List of subprojects to generate with subproject:container:tag
53+
-ssf SUBPROJECT_SPEC_FILE, --subproject-spec-file SUBPROJECT_SPEC_FILE
54+
Excel file containing subproject specification
5355
-nv, --no-verify Disable TLS certificate verification
5456
-rm, --remove Remove project structure with all subprojects (DANGEROUS!)
5557
--clone-from CLONE_FROM
@@ -60,6 +62,11 @@
6062
if container name omited it will be set to subproject
6163
if tag omited it would be set to 'latest'
6264
65+
Subprojects an be specified in excel file with -ssf --subproject-spec-file parameter.
66+
Excel file should contain one worksheet with first row containing column names as following:
67+
Container Name, Image ID, Version, Project Name
68+
and subsequent rows containing data
69+
6370
Container image name scanned will be written into project version nickname field
6471
6572
@@ -197,9 +204,36 @@ def add_component_to_version_bom(child_version, version):
197204
data = { 'component': child_version['_meta']['href']}
198205
return bd.session.post(url, json=data)
199206

207+
def get_child_spec_list(args):
208+
if args.subproject_list:
209+
return args.subproject_list.split(',')
210+
else:
211+
print("processing excel")
212+
import openpyxl
213+
wb = openpyxl.load_workbook(args.subproject_spec_file)
214+
ws = wb.active
215+
project_list = []
216+
row_number = 0
217+
for row in ws.values:
218+
row_number += 1
219+
if (row_number == 1 and
220+
row[0] == 'Container Name' and
221+
row[1] == 'Image ID' and
222+
row[2] == 'Version' and
223+
row[3] == 'Project Name'):
224+
print("File Format checks out (kind of)")
225+
continue
226+
elif row_number > 1:
227+
project_list.append(f"{row[3]}:{row[0]}:{row[2]}")
228+
else:
229+
logging.error(f"Could not parse input file {args.subproject_spec_file}")
230+
sys.exit(1)
231+
return (project_list)
232+
200233
def create_and_add_child_projects(version, args):
201234
version_url = version['_meta']['href'] + '/components'
202-
for child_spec in [x.split(':') for x in args.subproject_list.split(",")]:
235+
child_spec_list = get_child_spec_list(args)
236+
for child_spec in [x.split(':') for x in child_spec_list]:
203237
i = iter(child_spec)
204238
child = next(i)
205239
repo = next(i, child)
@@ -299,7 +333,9 @@ def parse_command_args():
299333
parser.add_argument("-pg", "--project_group", required=False, default='Multi-Image', help="Project Group to be used")
300334
parser.add_argument("-p", "--project-name", required=True, help="Project Name")
301335
parser.add_argument("-pv", "--version-name", required=True, help="Project Version Name")
302-
parser.add_argument("-sp", "--subproject-list", required=False, help="List of subprojects to generate with subproject:container:tag")
336+
group = parser.add_mutually_exclusive_group()
337+
group.add_argument("-sp", "--subproject-list", required=False, help="List of subprojects to generate with subproject:container:tag")
338+
group.add_argument("-ssf", "--subproject-spec-file", required=False, help="Excel file containing subproject specification")
303339
parser.add_argument("-nv", "--no-verify", action='store_false', help="Disable TLS certificate verification")
304340
parser.add_argument("-rm", "--remove", action='store_true', required=False, help="Remove project structure with all subprojects (DANGEROUS!)")
305341
parser.add_argument("--clone-from", required=False, help="Main project version to use as template for cloning")

0 commit comments

Comments
 (0)