Mercurial > hg > orthanc-python
annotate CodeAnalysis/GenerateOrthancSDK.py @ 190:0cb98433a382 java-code-model
print statistics
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 02 Jul 2024 17:27:44 +0200 |
parents | 7e8085f80df5 |
children | b0f096d2339e |
rev | line source |
---|---|
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 ## |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 ## Python plugin for Orthanc |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 ## Copyright (C) 2020-2023 Osimis S.A., Belgium |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 ## Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 ## Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 ## |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 ## This program is free software: you can redistribute it and/or |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 ## modify it under the terms of the GNU Affero General Public License |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 ## as published by the Free Software Foundation, either version 3 of |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 ## the License, or (at your option) any later version. |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 ## |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 ## This program is distributed in the hope that it will be useful, but |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 ## Affero General Public License for more details. |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 ## |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 ## You should have received a copy of the GNU Affero General Public License |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 ## along with this program. If not, see <http://www.gnu.org/licenses/>. |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 ## |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 import argparse |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 import json |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 import os |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 import sys |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 import pystache |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 ROOT = os.path.dirname(os.path.realpath(sys.argv[0])) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 ## |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 ## Parse the command-line arguments |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 ## |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 parser = argparse.ArgumentParser(description = 'Generate Python code to wrap the Orthanc SDK.') |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 parser.add_argument('--model', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 default = os.path.join(os.path.dirname(__file__), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 '../Resources/Orthanc/Sdk-1.10.0/CodeModel.json'), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 help = 'Input code model, as generated by the orthanc-java project') |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 parser.add_argument('--target', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 default = os.path.join(os.path.dirname(__file__), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 '../Sources/Autogenerated'), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 help = 'Target folder') |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 args = parser.parse_args() |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 ## |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 ## Configuration of the custom primitives that are manually |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 ## implemented (not autogenerated) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 ## |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 |
183
d31f216c9462
extracted custom functions/methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
182
diff
changeset
|
56 TARGET = os.path.realpath(args.target) |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 |
183
d31f216c9462
extracted custom functions/methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
182
diff
changeset
|
59 with open(os.path.join(ROOT, 'CustomMethods.json'), 'r') as f: |
d31f216c9462
extracted custom functions/methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
182
diff
changeset
|
60 CUSTOM_METHODS = json.loads(f.read()) |
182
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
61 |
183
d31f216c9462
extracted custom functions/methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
182
diff
changeset
|
62 with open(os.path.join(ROOT, 'CustomFunctions.json'), 'r') as f: |
d31f216c9462
extracted custom functions/methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
182
diff
changeset
|
63 CUSTOM_FUNCTIONS = json.loads(f.read()) |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 partials = {} |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 with open(os.path.join(ROOT, 'FunctionBody.mustache'), 'r') as f: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 partials['function_body'] = f.read() |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 |
181
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
71 with open(os.path.join(ROOT, 'FunctionDocumentation.mustache'), 'r') as f: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
72 partials['function_documentation'] = f.read() |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
73 |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 renderer = pystache.Renderer( |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 escape = lambda u: u, # No escaping |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 partials = partials, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 ) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 with open(args.model, 'r') as f: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 model = json.loads(f.read()) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 def ToUpperCase(name): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 s = '' |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 for i in range(len(name)): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 if name[i].isupper(): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 if len(s) == 0: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 s += name[i] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 elif name[i - 1].islower(): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 s += '_' + name[i] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 elif (i + 1 < len(name) and |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 name[i - 1].islower() and |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 name[i + 1].isupper()): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 s += '_' + name[i] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 else: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 s += name[i] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 else: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 s += name[i].upper() |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 return s |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
104 def ToLowerCase(name): |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
105 s = '' |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
106 for i in range(len(name)): |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
107 if (name[i].isupper() and |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
108 len(s) != 0): |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
109 s += '_' |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
110 s += name[i].lower() |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
111 return s |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
112 |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
113 |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 def GetShortName(name): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 if not name.startswith('OrthancPlugin'): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 raise Exception() |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 else: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 return name[len('OrthancPlugin'):] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 ORTHANC_TO_PYTHON_NUMERIC_TYPES = { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 # https://docs.python.org/3/c-api/arg.html#numbers |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 # https://en.wikipedia.org/wiki/C_data_types |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 'uint8_t' : { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 'type' : 'unsigned char', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 'format' : 'b', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 }, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 'int32_t' : { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 'type' : 'long int', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 'format' : 'l', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 }, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 'uint16_t' : { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 'type' : 'unsigned short', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 'format' : 'H', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 }, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 'uint32_t' : { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 'type' : 'unsigned long', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 'format' : 'k', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 }, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 'uint64_t' : { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 'type' : 'unsigned long long', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 'format' : 'K', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 }, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 'float' : { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 'type' : 'float', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 'format' : 'f', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 } |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 } |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 |
181
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
152 def DocumentFunction(f): |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
153 documentation = {} |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
154 description = f['documentation'].get('description', []) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
155 if len(description) > 0: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
156 documentation['short_description'] = description[0].split('.') [0] |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
157 documentation['description'] = map(lambda x: { 'text' : x }, description) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
158 |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
159 args_declaration = [] |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
160 args_documentation = [] |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
161 for a in f['args']: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
162 arg_name = ToLowerCase(a['sdk_name']) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
163 if a['sdk_type'] == 'const char *': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
164 arg_type = 'str' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
165 elif a['sdk_type'] == 'float': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
166 arg_type = 'float' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
167 elif a['sdk_type'] in [ 'const_void_pointer_with_size', 'const void *' ]: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
168 arg_type = 'bytes' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
169 elif a['sdk_type'] == 'enumeration': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
170 arg_type = GetShortName(a['sdk_enumeration']) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
171 elif a['sdk_type'] == 'const_object': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
172 arg_type = GetShortName(a['sdk_class']) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
173 elif a['sdk_type'] in [ 'int32_t', 'uint32_t', 'uint8_t', 'uint16_t', 'uint64_t' ]: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
174 arg_type = 'int' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
175 else: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
176 raise Exception('Argument type not implemented: %s' % a['sdk_type']) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
177 args_declaration.append('%s: %s' % (arg_name, arg_type)) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
178 args_documentation.append({ |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
179 'name' : arg_name, |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
180 'type' : arg_type, |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
181 'text' : f['documentation']['args'] [a['sdk_name']], |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
182 }) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
183 |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
184 documentation['args_declaration'] = ', '.join(args_declaration) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
185 documentation['args'] = args_documentation |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
186 documentation['has_args'] = len(args_documentation) > 0 |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
187 documentation['has_return'] = True |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
188 |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
189 if f['return_sdk_type'] == 'enumeration': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
190 if f['return_sdk_enumeration'] == 'OrthancPluginErrorCode': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
191 documentation['has_return'] = False |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
192 documentation['return_type'] = 'None' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
193 else: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
194 documentation['return_type'] = GetShortName(f['return_sdk_enumeration']) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
195 elif f['return_sdk_type'] == 'object': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
196 documentation['return_type'] = GetShortName(f['return_sdk_class']) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
197 elif f['return_sdk_type'] == 'void': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
198 documentation['has_return'] = False |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
199 documentation['return_type'] = 'None' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
200 elif f['return_sdk_type'] == 'OrthancPluginMemoryBuffer *': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
201 documentation['return_type'] = 'bytes' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
202 elif f['return_sdk_type'] in [ 'char *', 'const char *' ]: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
203 documentation['return_type'] = 'str' |
182
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
204 elif f['return_sdk_type'] in [ 'int32_t', 'uint32_t', 'uint16_t', 'int64_t' ]: |
181
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
205 documentation['return_type'] = 'int' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
206 else: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
207 raise Exception('Return type not implemented: %s' % f['return_sdk_type']) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
208 |
182
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
209 if documentation['has_return']: |
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
210 documentation['return_text'] = f['documentation']['return'] |
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
211 |
181
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
212 return documentation |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
213 |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
214 |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
215 def FormatFunction(f): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 answer = { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 'c_function' : f['c_function'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 'short_name' : GetShortName(f['c_function']), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 'has_args' : len(f['args']) > 0, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 'count_args' : len(f['args']), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 } |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 tuple_format = '' |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 tuple_target = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 call_args = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 args = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 for arg in f['args']: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 # https://docs.python.org/3/c-api/arg.html |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 if arg['sdk_type'] in [ 'const void *', 'const_void_pointer_with_size' ]: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 args.append({ |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 'name' : arg['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 'python_type' : 'Py_buffer', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 'release' : 'PyBuffer_Release(&%s);' % arg['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 tuple_format += 's*' |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 elif arg['sdk_type'] == 'const char *': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 args.append({ |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 'name' : arg['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
240 'python_type' : 'const char*', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 'initialization' : ' = NULL', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
242 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
243 tuple_format += 's' |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 elif arg['sdk_type'] == 'enumeration': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 args.append({ |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 'name' : arg['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 'python_type' : 'long int', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 'initialization' : ' = 0', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
249 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 tuple_format += 'l' |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 elif arg['sdk_type'] == 'const_object': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 args.append({ |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 'name' : arg['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 'python_type' : 'PyObject*', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 'initialization' : ' = NULL', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 'check_object_type' : arg['sdk_class'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 tuple_format += 'O' |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 elif arg['sdk_type'] in ORTHANC_TO_PYTHON_NUMERIC_TYPES: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
260 t = ORTHANC_TO_PYTHON_NUMERIC_TYPES[arg['sdk_type']] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
261 args.append({ |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
262 'name' : arg['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
263 'python_type' : t['type'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 'initialization' : ' = 0', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 tuple_format += t['format'] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 else: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 print('Ignoring function with unsupported argument type: %s(), type = %s' % (f['c_function'], arg['sdk_type'])) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 return None |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
270 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
271 tuple_target.append('&' + arg['name']) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
272 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
273 if arg['sdk_type'] == 'const void *': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
274 call_args.append(arg['name'] + '.buf') |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
275 elif arg['sdk_type'] == 'const_void_pointer_with_size': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
276 call_args.append(arg['name'] + '.buf') |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
277 call_args.append(arg['name'] + '.len') |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
278 elif arg['sdk_type'] == 'enumeration': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
279 call_args.append('static_cast<%s>(%s)' % (arg['sdk_enumeration'], arg['name'])) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
280 elif arg['sdk_type'] == 'const_object': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
281 call_args.append('%s == Py_None ? NULL : reinterpret_cast<sdk_%s_Object*>(%s)->object_' % ( |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
282 arg['name'], arg['sdk_class'], arg['name'])) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
283 else: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
284 call_args.append(arg['name']) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
285 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
286 answer['args'] = args |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
287 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
288 if f['return_sdk_type'] == 'void': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
289 answer['return_void'] = True |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
290 elif f['return_sdk_type'] in [ 'int32_t', 'uint32_t', 'int64_t' ]: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
291 answer['return_long'] = True |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
292 elif f['return_sdk_type'] == 'OrthancPluginMemoryBuffer *': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 answer['return_bytes'] = True |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
294 elif f['return_sdk_type'] == 'enumeration': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
295 if f['return_sdk_enumeration'] == 'OrthancPluginErrorCode': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
296 answer['return_error'] = True |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
297 else: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
298 answer['return_enumeration'] = f['return_sdk_enumeration'] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
299 elif f['return_sdk_type'] == 'char *': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
300 answer['return_dynamic_string'] = True |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
301 elif f['return_sdk_type'] == 'const char *': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
302 answer['return_static_string'] = True |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
303 elif f['return_sdk_type'] == 'object': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
304 answer['return_object'] = f['return_sdk_class'] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
305 else: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
306 print('Ignoring function with unsupported return type: %s(), type = %s' % (f['c_function'], f['return_sdk_type'])) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
307 return None |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
308 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
309 answer['tuple_format'] = ', '.join([ '"' + tuple_format + '"' ] + tuple_target) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
310 |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
311 if 'documentation' in f: |
181
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
312 answer['documentation'] = DocumentFunction(f) |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
313 |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 if len(call_args) > 0: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
315 answer['call_args'] = ', ' + ', '.join(call_args) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
316 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 return answer |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
318 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
319 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
320 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
321 globalFunctions = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
322 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
323 for f in model['global_functions']: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
324 g = FormatFunction(f) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
325 if g != None: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
326 globalFunctions.append(g) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
327 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
328 for f in CUSTOM_FUNCTIONS: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
329 g = FormatFunction(f) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
330 if g != None: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
331 globalFunctions.append(g) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
332 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
333 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
334 enumerations = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
335 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
336 with open(os.path.join(ROOT, 'Enumeration.mustache'), 'r') as f: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
337 ENUMERATION_TEMPLATE = f.read() |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
338 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
339 for e in model['enumerations']: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
340 values = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
341 for value in e['values']: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
342 values.append({ |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
343 'key' : ToUpperCase(value['key']), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
344 'value' : value['value'], |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
345 'documentation' : value['documentation'], |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
346 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
347 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
348 enumerations.append({ |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
349 'name' : e['name'], |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
350 'short_name' : GetShortName(e['name']), |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
351 'path' : 'sdk_%s.impl.h' % e['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
352 'values' : values, |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
353 'documentation' : e['documentation'], |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
354 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
355 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
356 path = 'sdk_%s.impl.h' % e['name'] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
357 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
358 with open(os.path.join(TARGET, path), 'w') as f: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
359 f.write(pystache.render(ENUMERATION_TEMPLATE, { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
360 'name' : e['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
361 'short_name' : GetShortName(e['name']), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
362 'values' : values, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
363 })) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
364 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
365 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
366 classes = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
367 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
368 for c in model['classes']: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
369 methods = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
370 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
371 for m in c['methods']: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
372 g = FormatFunction(m) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
373 if g != None: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
374 g['self'] = ', self->object_' |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
375 methods.append(g) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
376 |
182
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
377 custom_methods = [] |
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
378 |
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
379 if c['name'] in CUSTOM_METHODS: |
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
380 for custom_method in CUSTOM_METHODS[c['name']]: |
185 | 381 custom_method['self'] = True # Indicates that this is a method |
182
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
382 custom_method['documentation'] = DocumentFunction(custom_method) |
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
383 custom_methods.append(custom_method) |
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
384 |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
385 classes.append({ |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
386 'class_name' : c['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
387 'short_name' : GetShortName(c['name']), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
388 'methods' : methods, |
182
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
389 'custom_methods' : custom_methods, |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
390 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
391 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
392 if 'destructor' in c: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
393 classes[-1]['destructor'] = c['destructor'] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
394 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
395 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
396 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
397 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
398 with open(os.path.join(ROOT, 'Class.mustache'), 'r') as f: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
399 with open(os.path.join(ROOT, 'ClassMethods.mustache'), 'r') as g: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
400 classDefinition = f.read() |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
401 classMethods = g.read() |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
402 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
403 for c in classes: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
404 with open(os.path.join(TARGET, 'sdk_%s.impl.h' % c['class_name']), 'w') as h: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
405 h.write(renderer.render(classDefinition, c)) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
406 with open(os.path.join(TARGET, 'sdk_%s.methods.h' % c['class_name']), 'w') as h: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
407 h.write(renderer.render(classMethods, c)) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
408 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
409 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
410 sortedClasses = sorted(classes, key = lambda x: x['class_name']) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
411 sortedEnumerations = sorted(enumerations, key = lambda x: x['name']) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
412 sortedGlobalFunctions = sorted(globalFunctions, key = lambda x: x['c_function']) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
413 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
414 with open(os.path.join(ROOT, 'GlobalFunctions.mustache'), 'r') as f: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
415 with open(os.path.join(TARGET, 'sdk_GlobalFunctions.impl.h'), 'w') as h: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
416 h.write(renderer.render(f.read(), { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
417 'global_functions' : sortedGlobalFunctions, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
418 })) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
419 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
420 with open(os.path.join(ROOT, 'sdk.cpp.mustache'), 'r') as f: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
421 with open(os.path.join(TARGET, 'sdk.cpp'), 'w') as h: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
422 h.write(renderer.render(f.read(), { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
423 'classes' : sortedClasses, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
424 'enumerations' : sortedEnumerations, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
425 'global_functions' : sortedGlobalFunctions, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
426 })) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
427 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
428 with open(os.path.join(ROOT, 'sdk.h.mustache'), 'r') as f: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
429 with open(os.path.join(TARGET, 'sdk.h'), 'w') as h: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
430 h.write(renderer.render(f.read(), { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
431 'classes' : sortedClasses, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
432 })) |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
433 |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
434 with open(os.path.join(ROOT, 'PythonDocumentation.mustache'), 'r') as f: |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
435 with open(os.path.join(TARGET, 'orthanc.pyi'), 'w') as h: |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
436 h.write(renderer.render(f.read(), { |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
437 'classes' : sortedClasses, |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
438 'enumerations' : sortedEnumerations, |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
439 'global_functions' : sortedGlobalFunctions, |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
440 })) |
190 | 441 |
442 | |
443 countMethods = 0 | |
444 for c in sortedClasses: | |
445 countMethods += len(c['methods']) | |
446 | |
447 print('\nNumber of wrapped global functions: %d' % len(sortedGlobalFunctions)) | |
448 print('Number of wrapped methods: %d\n' % countMethods) | |
449 print('Total number of wrapped global functions or methods: %d\n' % (len(sortedGlobalFunctions) + countMethods)) |