Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ copyright-text =
'#'
'# SPDX-License-Identifier: Apache-2.0'
'# Copyright (c) OWASP Foundation. All Rights Reserved.'
lines-to-exclude =
## shebang
'#!'
22 changes: 13 additions & 9 deletions tools/schema-downloader.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python3

# This file is part of CycloneDX Python Library
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,11 +18,11 @@
# Copyright (c) OWASP Foundation. All Rights Reserved.

import re
from os.path import dirname, join
from os.path import dirname, join, realpath
from urllib.request import urlretrieve

SOURCE_ROOT = 'https://raw.githubusercontent.com/CycloneDX/specification/refs/tags/1.6.1/schema/'
TARGET_ROOT = join(dirname(__file__), '..', 'cyclonedx', 'schema', '_res')
TARGET_ROOT = realpath(join(dirname(__file__), '..', 'cyclonedx', 'schema', '_res'))

BOM_XSD = {
'versions': ['1.6', '1.5', '1.4', '1.3', '1.2', '1.1', '1.0'],
Expand Down Expand Up @@ -99,14 +101,16 @@
source = dspec['sourcePattern'].replace('%s', version)
target = dspec['targetPattern'].replace('%s', version)
tempfile, _ = urlretrieve(source) # nosec B310
print(source, '->', target)
with open(tempfile, 'r') as tmpf:
with open(target, 'w', newline='\n') as tarf:
text = tmpf.read()
for search, replace in dspec['replace']:
text = text.replace(search, replace)
for search, replace in dspec['replaceRE']:
text = search.sub(replace, text)
tarf.write(text)
text = tmpf.read()
with open(target, 'w', newline='\n') as tarf:
for search, replace in dspec['replace']:
text = text.replace(search, replace)
for search, replace in dspec['replaceRE']:
text = search.sub(replace, text)
tarf.write(text)

for source, target in OTHER_DOWNLOADABLES:
print(source, '->', target)
urlretrieve(source, target) # nosec B310