| 
 | 1 | +#!/usr/bin/env python3  | 
 | 2 | + | 
1 | 3 | # This file is part of CycloneDX Python Library  | 
2 | 4 | #  | 
3 | 5 | # Licensed under the Apache License, Version 2.0 (the "License");  | 
 | 
16 | 18 | # Copyright (c) OWASP Foundation. All Rights Reserved.  | 
17 | 19 | 
 
  | 
18 | 20 | import re  | 
19 |  | -from os.path import dirname, join  | 
 | 21 | +from os.path import dirname, join, realpath  | 
20 | 22 | from urllib.request import urlretrieve  | 
21 | 23 | 
 
  | 
22 | 24 | SOURCE_ROOT = 'https://raw.githubusercontent.com/CycloneDX/specification/refs/tags/1.6.1/schema/'  | 
23 |  | -TARGET_ROOT = join(dirname(__file__), '..', 'cyclonedx', 'schema', '_res')  | 
 | 25 | +TARGET_ROOT = realpath(join(dirname(__file__), '..', 'cyclonedx', 'schema', '_res'))  | 
24 | 26 | 
 
  | 
25 | 27 | BOM_XSD = {  | 
26 | 28 |     'versions': ['1.6', '1.5', '1.4', '1.3', '1.2', '1.1', '1.0'],  | 
 | 
99 | 101 |         source = dspec['sourcePattern'].replace('%s', version)  | 
100 | 102 |         target = dspec['targetPattern'].replace('%s', version)  | 
101 | 103 |         tempfile, _ = urlretrieve(source)  # nosec B310  | 
 | 104 | +        print(source, '->', target)  | 
102 | 105 |         with open(tempfile, 'r') as tmpf:  | 
103 |  | -            with open(target, 'w', newline='\n') as tarf:  | 
104 |  | -                text = tmpf.read()  | 
105 |  | -                for search, replace in dspec['replace']:  | 
106 |  | -                    text = text.replace(search, replace)  | 
107 |  | -                for search, replace in dspec['replaceRE']:  | 
108 |  | -                    text = search.sub(replace, text)  | 
109 |  | -                tarf.write(text)  | 
 | 106 | +            text = tmpf.read()  | 
 | 107 | +        with open(target, 'w', newline='\n') as tarf:  | 
 | 108 | +            for search, replace in dspec['replace']:  | 
 | 109 | +                text = text.replace(search, replace)  | 
 | 110 | +            for search, replace in dspec['replaceRE']:  | 
 | 111 | +                text = search.sub(replace, text)  | 
 | 112 | +            tarf.write(text)  | 
110 | 113 | 
 
  | 
111 | 114 | for source, target in OTHER_DOWNLOADABLES:  | 
 | 115 | +    print(source, '->', target)  | 
112 | 116 |     urlretrieve(source, target)  # nosec B310  | 
0 commit comments