Mercurial > hg > orthanc
comparison Resources/EmbedResources.py @ 325:71d30b9ce801
ignore upcase check
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 08 Jan 2013 09:54:22 +0100 |
parents | 052dede32761 |
children | e7276309b269 |
comparison
equal
deleted
inserted
replaced
324:64925c94825c | 325:71d30b9ce801 |
---|---|
34 import pprint | 34 import pprint |
35 import re | 35 import re |
36 | 36 |
37 if len(sys.argv) < 2 or len(sys.argv) % 2 != 0: | 37 if len(sys.argv) < 2 or len(sys.argv) % 2 != 0: |
38 print ('Usage:') | 38 print ('Usage:') |
39 print ('python %s <TargetBaseFilename> [ <Name> <Source> ]*' % sys.argv[0]) | 39 print ('python %s [--no-upcase-check] <TargetBaseFilename> [ <Name> <Source> ]*' % sys.argv[0]) |
40 exit(-1) | 40 exit(-1) |
41 | 41 |
42 UPCASE_CHECK = True | |
43 ARGS = [] | |
44 for i in range(len(sys.argv)): | |
45 if not sys.argv[i].startswith('--'): | |
46 ARGS.append(sys.argv[i]) | |
47 elif sys.argv[i].lower() == '--no-upcase-check': | |
48 UPCASE_CHECK = False | |
49 | |
50 TARGET_BASE_FILENAME = ARGS[1] | |
51 SOURCES = ARGS[2:] | |
42 | 52 |
43 try: | 53 try: |
44 # Make sure the destination directory exists | 54 # Make sure the destination directory exists |
45 os.makedirs(os.path.normpath(os.path.join(sys.argv[1], '..'))) | 55 os.makedirs(os.path.normpath(os.path.join(TARGET_BASE_FILENAME, '..'))) |
46 except: | 56 except: |
47 pass | 57 pass |
48 | 58 |
49 | 59 |
50 ##################################################################### | 60 ##################################################################### |
51 ## Read each resource file | 61 ## Read each resource file |
52 ##################################################################### | 62 ##################################################################### |
53 | 63 |
54 def CheckNoUpcase(s): | 64 def CheckNoUpcase(s): |
55 if re.search('[A-Z]', s) != None: | 65 global UPCASE_CHECK |
66 if (UPCASE_CHECK and | |
67 re.search('[A-Z]', s) != None): | |
56 raise Exception("Path in a directory with an upcase letter: %s" % s) | 68 raise Exception("Path in a directory with an upcase letter: %s" % s) |
57 | 69 |
58 resources = {} | 70 resources = {} |
59 | 71 |
60 counter = 0 | 72 counter = 0 |
61 i = 2 | 73 i = 0 |
62 while i < len(sys.argv): | 74 while i < len(SOURCES): |
63 resourceName = sys.argv[i].upper() | 75 resourceName = SOURCES[i].upper() |
64 pathName = sys.argv[i + 1] | 76 pathName = SOURCES[i + 1] |
65 | 77 |
66 if not os.path.exists(pathName): | 78 if not os.path.exists(pathName): |
67 raise Exception("Non existing path: %s" % pathName) | 79 raise Exception("Non existing path: %s" % pathName) |
68 | 80 |
69 if resourceName in resources: | 81 if resourceName in resources: |
115 | 127 |
116 ##################################################################### | 128 ##################################################################### |
117 ## Write .h header | 129 ## Write .h header |
118 ##################################################################### | 130 ##################################################################### |
119 | 131 |
120 header = open(sys.argv[1] + '.h', 'w') | 132 header = open(TARGET_BASE_FILENAME + '.h', 'w') |
121 | 133 |
122 header.write(""" | 134 header.write(""" |
123 #pragma once | 135 #pragma once |
124 | 136 |
125 #include <string> | 137 #include <string> |
212 | 224 |
213 cpp.write(' };\n') | 225 cpp.write(' };\n') |
214 cpp.write(' static const size_t resource%dSize = %d;\n' % (item['Index'], pos)) | 226 cpp.write(' static const size_t resource%dSize = %d;\n' % (item['Index'], pos)) |
215 | 227 |
216 | 228 |
217 cpp = open(sys.argv[1] + '.cpp', 'w') | 229 cpp = open(TARGET_BASE_FILENAME + '.cpp', 'w') |
218 | 230 |
219 cpp.write(""" | 231 cpp.write(""" |
220 #include "%s.h" | 232 #include "%s.h" |
221 #include "%s/Core/OrthancException.h" | 233 #include "%s/Core/OrthancException.h" |
222 | 234 |
225 | 237 |
226 namespace Orthanc | 238 namespace Orthanc |
227 { | 239 { |
228 namespace EmbeddedResources | 240 namespace EmbeddedResources |
229 { | 241 { |
230 """ % (os.path.basename(sys.argv[1]), | 242 """ % (os.path.basename(TARGET_BASE_FILENAME), |
231 os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))) | 243 os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))) |
232 | 244 |
233 | 245 |
234 for name in resources: | 246 for name in resources: |
235 if resources[name]['Type'] == 'File': | 247 if resources[name]['Type'] == 'File': |