annotate Resources/EmbedResources.py @ 408:5a3a4a25e568 lua-scripting

reintegration from mainline
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 02 May 2013 16:51:40 +0200
parents 5962898fb7c8
children 2d0a347e8cfc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
143
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
1 # Orthanc - A Lightweight, RESTful DICOM Store
401
5962898fb7c8 copyright update
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 326
diff changeset
2 # Copyright (C) 2012-2013 Medical Physics Department, CHU of Liege,
143
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
3 # Belgium
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
4 #
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
5 # This program is free software: you can redistribute it and/or
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
6 # modify it under the terms of the GNU General Public License as
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
7 # published by the Free Software Foundation, either version 3 of the
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
8 # License, or (at your option) any later version.
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
9 #
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
10 # In addition, as a special exception, the copyright holders of this
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
11 # program give permission to link the code of its release with the
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
12 # OpenSSL project's "OpenSSL" library (or with modified versions of it
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
13 # that use the same license as the "OpenSSL" library), and distribute
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
14 # the linked executables. You must obey the GNU General Public License
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
15 # in all respects for all of the code used other than "OpenSSL". If you
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
16 # modify file(s) with this exception, you may extend this exception to
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
17 # your version of the file(s), but you are not obligated to do so. If
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
18 # you do not wish to do so, delete this exception statement from your
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
19 # version. If you delete this exception statement from all source files
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
20 # in the program, then also delete it here.
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
21 #
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
22 # This program is distributed in the hope that it will be useful, but
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
23 # WITHOUT ANY WARRANTY; without even the implied warranty of
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
25 # General Public License for more details.
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
26 #
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
27 # You should have received a copy of the GNU General Public License
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
28 # along with this program. If not, see <http://www.gnu.org/licenses/>.
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
29
f1aeec53795b missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 129
diff changeset
30
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 import sys
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 import os
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 import os.path
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 import pprint
129
5133cfc8db86 fix standalone build
jodogne
parents: 64
diff changeset
35 import re
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
325
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
37 UPCASE_CHECK = True
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
38 ARGS = []
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
39 for i in range(len(sys.argv)):
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
40 if not sys.argv[i].startswith('--'):
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
41 ARGS.append(sys.argv[i])
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
42 elif sys.argv[i].lower() == '--no-upcase-check':
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
43 UPCASE_CHECK = False
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
44
326
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 325
diff changeset
45 if len(ARGS) < 2 or len(ARGS) % 2 != 0:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 325
diff changeset
46 print ('Usage:')
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 325
diff changeset
47 print ('python %s [--no-upcase-check] <TargetBaseFilename> [ <Name> <Source> ]*' % sys.argv[0])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 325
diff changeset
48 exit(-1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 325
diff changeset
49
325
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
50 TARGET_BASE_FILENAME = ARGS[1]
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
51 SOURCES = ARGS[2:]
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 try:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 # Make sure the destination directory exists
325
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
55 os.makedirs(os.path.normpath(os.path.join(TARGET_BASE_FILENAME, '..')))
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 except:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 pass
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 #####################################################################
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 ## Read each resource file
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 #####################################################################
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
129
5133cfc8db86 fix standalone build
jodogne
parents: 64
diff changeset
64 def CheckNoUpcase(s):
325
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
65 global UPCASE_CHECK
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
66 if (UPCASE_CHECK and
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
67 re.search('[A-Z]', s) != None):
129
5133cfc8db86 fix standalone build
jodogne
parents: 64
diff changeset
68 raise Exception("Path in a directory with an upcase letter: %s" % s)
5133cfc8db86 fix standalone build
jodogne
parents: 64
diff changeset
69
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 resources = {}
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 counter = 0
325
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
73 i = 0
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
74 while i < len(SOURCES):
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
75 resourceName = SOURCES[i].upper()
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
76 pathName = SOURCES[i + 1]
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 if not os.path.exists(pathName):
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 raise Exception("Non existing path: %s" % pathName)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 if resourceName in resources:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 raise Exception("Twice the same resource: " + resourceName)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 if os.path.isdir(pathName):
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 # The resource is a directory: Recursively explore its files
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 content = {}
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 for root, dirs, files in os.walk(pathName):
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 base = os.path.relpath(root, pathName)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 for f in files:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 if f.find('~') == -1: # Ignore Emacs backup files
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 if base == '.':
129
5133cfc8db86 fix standalone build
jodogne
parents: 64
diff changeset
92 r = f
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 else:
129
5133cfc8db86 fix standalone build
jodogne
parents: 64
diff changeset
94 r = os.path.join(base, f)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
129
5133cfc8db86 fix standalone build
jodogne
parents: 64
diff changeset
96 CheckNoUpcase(r)
20
a56b6a8b89ba fix for windows
jodogne
parents: 0
diff changeset
97 r = '/' + r.replace('\\', '/')
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 if r in content:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 raise Exception("Twice the same filename (check case): " + r)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 content[r] = {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 'Filename' : os.path.join(root, f),
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 'Index' : counter
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 counter += 1
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 resources[resourceName] = {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 'Type' : 'Directory',
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 'Files' : content
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 elif os.path.isfile(pathName):
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 resources[resourceName] = {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 'Type' : 'File',
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 'Index' : counter,
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 'Filename' : pathName
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 counter += 1
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 else:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 raise Exception("Not a regular file, nor a directory: " + pathName)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 i += 2
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 #pprint.pprint(resources)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 #####################################################################
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 ## Write .h header
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 #####################################################################
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
325
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
132 header = open(TARGET_BASE_FILENAME + '.h', 'w')
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 header.write("""
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 #pragma once
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 #include <string>
323
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
138 #include <list>
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
64
71c4a4abe90b renaming of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
140 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 namespace EmbeddedResources
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 enum FileResourceId
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 """)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 isFirst = True
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 for name in resources:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 if resources[name]['Type'] == 'File':
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 if isFirst:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 isFirst = False
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 else:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 header.write(',\n')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 header.write(' %s' % name)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 header.write("""
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 enum DirectoryResourceId
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 """)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 isFirst = True
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 for name in resources:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 if resources[name]['Type'] == 'Directory':
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 if isFirst:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 isFirst = False
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 else:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 header.write(',\n')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 header.write(' %s' % name)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 header.write("""
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 };
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 const void* GetFileResourceBuffer(FileResourceId id);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 size_t GetFileResourceSize(FileResourceId id);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 void GetFileResource(std::string& result, FileResourceId id);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 const void* GetDirectoryResourceBuffer(DirectoryResourceId id, const char* path);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 size_t GetDirectoryResourceSize(DirectoryResourceId id, const char* path);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 void GetDirectoryResource(std::string& result, DirectoryResourceId id, const char* path);
323
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
183
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
184 void ListResources(std::list<std::string>& result, DirectoryResourceId id);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 """)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 header.close()
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 #####################################################################
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 ## Write the resource content in the .cpp source
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 #####################################################################
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195
55
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 49
diff changeset
196 PYTHON_MAJOR_VERSION = sys.version_info[0]
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 49
diff changeset
197
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 def WriteResource(cpp, item):
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 cpp.write(' static const uint8_t resource%dBuffer[] = {' % item['Index'])
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 f = open(item['Filename'], "rb")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 content = f.read()
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 f.close()
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 # http://stackoverflow.com/a/1035360
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 pos = 0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 for b in content:
55
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 49
diff changeset
208 if PYTHON_MAJOR_VERSION == 2:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 49
diff changeset
209 c = ord(b[0])
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 49
diff changeset
210 else:
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 49
diff changeset
211 c = b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 49
diff changeset
212
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 if pos > 0:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 cpp.write(', ')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 if (pos % 16) == 0:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 cpp.write('\n ')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
55
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 49
diff changeset
219 if c < 0:
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 raise Exception("Internal error")
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
55
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 49
diff changeset
222 cpp.write("0x%02x" % c)
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 pos += 1
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 cpp.write(' };\n')
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 cpp.write(' static const size_t resource%dSize = %d;\n' % (item['Index'], pos))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
325
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
229 cpp = open(TARGET_BASE_FILENAME + '.cpp', 'w')
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 cpp.write("""
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 #include "%s.h"
64
71c4a4abe90b renaming of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
233 #include "%s/Core/OrthancException.h"
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 #include <stdint.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 #include <string.h>
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
64
71c4a4abe90b renaming of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
238 namespace Orthanc
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 namespace EmbeddedResources
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
325
71d30b9ce801 ignore upcase check
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 323
diff changeset
242 """ % (os.path.basename(TARGET_BASE_FILENAME),
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))))
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 for name in resources:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 if resources[name]['Type'] == 'File':
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 WriteResource(cpp, resources[name])
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 else:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 for f in resources[name]['Files']:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 WriteResource(cpp, resources[name]['Files'][f])
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 #####################################################################
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 ## Write the accessors to the file resources in .cpp
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 #####################################################################
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 cpp.write("""
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 const void* GetFileResourceBuffer(FileResourceId id)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 switch (id)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 """)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 for name in resources:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 if resources[name]['Type'] == 'File':
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 cpp.write(' case %s:\n' % name)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 cpp.write(' return resource%dBuffer;\n' % resources[name]['Index'])
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 cpp.write("""
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 default:
64
71c4a4abe90b renaming of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
272 throw OrthancException(ErrorCode_ParameterOutOfRange);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 size_t GetFileResourceSize(FileResourceId id)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 switch (id)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 """)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 for name in resources:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 if resources[name]['Type'] == 'File':
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 cpp.write(' case %s:\n' % name)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 cpp.write(' return resource%dSize;\n' % resources[name]['Index'])
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 cpp.write("""
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 default:
64
71c4a4abe90b renaming of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
289 throw OrthancException(ErrorCode_ParameterOutOfRange);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 """)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 #####################################################################
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 ## Write the accessors to the directory resources in .cpp
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 #####################################################################
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 cpp.write("""
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 const void* GetDirectoryResourceBuffer(DirectoryResourceId id, const char* path)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 switch (id)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 """)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 for name in resources:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 if resources[name]['Type'] == 'Directory':
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 cpp.write(' case %s:\n' % name)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 isFirst = True
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 for path in resources[name]['Files']:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 cpp.write(' if (!strcmp(path, "%s"))\n' % path)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 cpp.write(' return resource%dBuffer;\n' % resources[name]['Files'][path]['Index'])
64
71c4a4abe90b renaming of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
314 cpp.write(' throw OrthancException("Unknown path in a directory resource");\n\n')
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 cpp.write(""" default:
64
71c4a4abe90b renaming of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
317 throw OrthancException(ErrorCode_ParameterOutOfRange);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 size_t GetDirectoryResourceSize(DirectoryResourceId id, const char* path)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 switch (id)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 """)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 for name in resources:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 if resources[name]['Type'] == 'Directory':
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 cpp.write(' case %s:\n' % name)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 isFirst = True
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 for path in resources[name]['Files']:
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 cpp.write(' if (!strcmp(path, "%s"))\n' % path)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 cpp.write(' return resource%dSize;\n' % resources[name]['Files'][path]['Index'])
64
71c4a4abe90b renaming of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
334 cpp.write(' throw OrthancException("Unknown path in a directory resource");\n\n')
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 cpp.write(""" default:
64
71c4a4abe90b renaming of resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 55
diff changeset
337 throw OrthancException(ErrorCode_ParameterOutOfRange);
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 """)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 #####################################################################
323
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
346 ## List the resources in a directory
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
347 #####################################################################
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
348
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
349 cpp.write("""
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
350 void ListResources(std::list<std::string>& result, DirectoryResourceId id)
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
351 {
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
352 result.clear();
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
353
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
354 switch (id)
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
355 {
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
356 """)
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
357
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
358 for name in resources:
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
359 if resources[name]['Type'] == 'Directory':
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
360 cpp.write(' case %s:\n' % name)
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
361 for path in sorted(resources[name]['Files']):
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
362 cpp.write(' result.push_back("%s");\n' % path)
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
363 cpp.write(' break;\n\n')
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
364
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
365 cpp.write(""" default:
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
366 throw OrthancException(ErrorCode_ParameterOutOfRange);
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
367 }
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
368 }
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
369 """)
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
370
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
371
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
372
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
373
052dede32761 list files in resource directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 143
diff changeset
374 #####################################################################
0
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 ## Write the convenience wrappers in .cpp
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 #####################################################################
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 cpp.write("""
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 void GetFileResource(std::string& result, FileResourceId id)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 size_t size = GetFileResourceSize(id);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 result.resize(size);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 if (size > 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 memcpy(&result[0], GetFileResourceBuffer(id), size);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 void GetDirectoryResource(std::string& result, DirectoryResourceId id, const char* path)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 {
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 size_t size = GetDirectoryResourceSize(id, path);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 result.resize(size);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 if (size > 0)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 memcpy(&result[0], GetDirectoryResourceBuffer(id, path), size);
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 }
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 """)
3959d33612cc initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 cpp.close()