Skip to content

Commit

Permalink
chore: tools shebang (#770)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <[email protected]>
  • Loading branch information
jkowalleck authored Feb 4, 2025
1 parent 472bded commit 3369a6a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
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

0 comments on commit 3369a6a

Please sign in to comment.