From c5eb041e1ebe53b78a75fda24f4d45fafd752786 Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Tue, 4 Feb 2025 14:26:29 +0100 Subject: [PATCH 1/5] chore: tools shebang Signed-off-by: Jan Kowalleck --- tools/schema-downloader.py | 2 ++ 1 file changed, 2 insertions(+) mode change 100644 => 100755 tools/schema-downloader.py diff --git a/tools/schema-downloader.py b/tools/schema-downloader.py old mode 100644 new mode 100755 index d9e4a31c6..7e6230068 --- a/tools/schema-downloader.py +++ b/tools/schema-downloader.py @@ -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"); From 7dee855df22888a28a3b2553d5d211dedb59f40a Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Tue, 4 Feb 2025 14:34:47 +0100 Subject: [PATCH 2/5] flake8 Signed-off-by: Jan Kowalleck --- .flake8 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.flake8 b/.flake8 index 459cc5571..fa51876f2 100644 --- a/.flake8 +++ b/.flake8 @@ -41,3 +41,6 @@ copyright-text = '#' '# SPDX-License-Identifier: Apache-2.0' '# Copyright (c) OWASP Foundation. All Rights Reserved.' +lines-to-exclude = + ## shebang + '#!' From 8867ec003f14f89928cfa956eff6c2259cee19bc Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Tue, 4 Feb 2025 14:41:52 +0100 Subject: [PATCH 3/5] output Signed-off-by: Jan Kowalleck --- tools/schema-downloader.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/schema-downloader.py b/tools/schema-downloader.py index 7e6230068..71e34baef 100755 --- a/tools/schema-downloader.py +++ b/tools/schema-downloader.py @@ -18,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'], @@ -101,8 +101,9 @@ source = dspec['sourcePattern'].replace('%s', version) target = dspec['targetPattern'].replace('%s', version) tempfile, _ = urlretrieve(source) # nosec B310 - with open(tempfile, 'r') as tmpf: - with open(target, 'w', newline='\n') as tarf: + print(source, '->', target) + with open(tempfile, 'r') as tmpf, \ + open(target, 'w', newline='\n') as tarf: text = tmpf.read() for search, replace in dspec['replace']: text = text.replace(search, replace) From fd8f8cb35f6e015b1132694e25526873794ea367 Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Tue, 4 Feb 2025 14:54:20 +0100 Subject: [PATCH 4/5] wip Signed-off-by: Jan Kowalleck --- tools/schema-downloader.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/schema-downloader.py b/tools/schema-downloader.py index 71e34baef..1c72947f6 100755 --- a/tools/schema-downloader.py +++ b/tools/schema-downloader.py @@ -103,13 +103,13 @@ tempfile, _ = urlretrieve(source) # nosec B310 print(source, '->', target) with open(tempfile, 'r') as tmpf, \ - 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) + 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) for source, target in OTHER_DOWNLOADABLES: urlretrieve(source, target) # nosec B310 From 4574dfe635b42e366c4b0b9ff414312bd8fc5280 Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Tue, 4 Feb 2025 14:59:51 +0100 Subject: [PATCH 5/5] wip Signed-off-by: Jan Kowalleck --- tools/schema-downloader.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/schema-downloader.py b/tools/schema-downloader.py index 1c72947f6..d795f4747 100755 --- a/tools/schema-downloader.py +++ b/tools/schema-downloader.py @@ -102,9 +102,9 @@ target = dspec['targetPattern'].replace('%s', version) tempfile, _ = urlretrieve(source) # nosec B310 print(source, '->', target) - with open(tempfile, 'r') as tmpf, \ - open(target, 'w', newline='\n') as tarf: + with open(tempfile, 'r') as tmpf: 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']: @@ -112,4 +112,5 @@ tarf.write(text) for source, target in OTHER_DOWNLOADABLES: + print(source, '->', target) urlretrieve(source, target) # nosec B310