Mercurial > hg > orthanc-ohif
comparison Resources/EmbedStaticAssets.py @ 17:154cb76a042f
make the build of static assets reproducible
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 05 Aug 2023 11:36:33 +0200 |
parents | 39585ba26f20 |
children | 36049c04ee27 |
comparison
equal
deleted
inserted
replaced
16:496bac7a275b | 17:154cb76a042f |
---|---|
93 | 93 |
94 index = {} | 94 index = {} |
95 count = 0 | 95 count = 0 |
96 | 96 |
97 for root, dirs, files in os.walk(SOURCE): | 97 for root, dirs, files in os.walk(SOURCE): |
98 files.sort() | |
99 dirs.sort() | |
100 | |
98 for f in files: | 101 for f in files: |
99 fullPath = os.path.join(root, f) | 102 fullPath = os.path.join(root, f) |
100 relativePath = os.path.relpath(os.path.join(root, f), SOURCE) | 103 relativePath = os.path.relpath(os.path.join(root, f), SOURCE) |
101 variable = 'data_%06d' % count | 104 variable = 'data_%06d' % count |
102 | 105 |
104 content = source.read() | 107 content = source.read() |
105 | 108 |
106 if sys.version_info < (3, 0): | 109 if sys.version_info < (3, 0): |
107 # Python 2.7 | 110 # Python 2.7 |
108 fileobj = io.BytesIO() | 111 fileobj = io.BytesIO() |
109 gzip.GzipFile(fileobj=fileobj, mode='w').write(content) | 112 gzip.GzipFile(fileobj=fileobj, mode='w', mtime=0).write(content) |
110 compressed = fileobj.getvalue() | 113 compressed = fileobj.getvalue() |
111 else: | 114 else: |
112 # Python 3.x | 115 # Python 3.x |
113 compressed = gzip.compress(content) | 116 compressed = gzip.compress(content, mtime=0) |
114 | 117 |
115 EncodeFileAsCString(g, variable, compressed) | 118 EncodeFileAsCString(g, variable, compressed) |
116 WriteChecksum(g, variable + '_md5', content) | 119 WriteChecksum(g, variable + '_md5', content) |
117 | 120 |
118 index[relativePath] = variable | 121 index[relativePath] = variable |
119 | 122 |
120 count += 1 | 123 count += 1 |
121 | 124 |
122 g.write('void ReadStaticAsset(std::string& target, const std::string& path)\n') | 125 g.write('void ReadStaticAsset(std::string& target, const std::string& path)\n') |
123 g.write('{\n') | 126 g.write('{\n') |
124 for (path, variable) in index.items(): | 127 for (path, variable) in sorted(index.items()): |
125 g.write(' if (path == "%s")\n' % path) | 128 g.write(' if (path == "%s")\n' % path) |
126 g.write(' {\n') | 129 g.write(' {\n') |
127 g.write(' Uncompress(target, %s, sizeof(%s) - 1, %s_md5);\n' % (variable, variable, variable)) | 130 g.write(' Uncompress(target, %s, sizeof(%s) - 1, %s_md5);\n' % (variable, variable, variable)) |
128 g.write(' return;\n') | 131 g.write(' return;\n') |
129 g.write(' }\n\n') | 132 g.write(' }\n\n') |