Mercurial > hg > orthanc-python
annotate CodeAnalysis/GenerateOrthancSDK.py @ 197:cf15599a1608 java-code-model
integration mainline->java-code-model
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 02 Jul 2024 19:03:56 +0200 |
parents | 0c5da632f34d |
children | 65ad095c25d8 |
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') |
194
0c5da632f34d
added description of classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
42 parser.add_argument('--classes', |
0c5da632f34d
added description of classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
43 default = os.path.join(os.path.dirname(__file__), |
0c5da632f34d
added description of classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
44 '../Resources/Orthanc/Sdk-1.10.0/ClassDocumentation.json'), |
0c5da632f34d
added description of classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
45 help = 'Input description of classes, as defined in the orthanc-java project') |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 parser.add_argument('--target', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 default = os.path.join(os.path.dirname(__file__), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 '../Sources/Autogenerated'), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 help = 'Target folder') |
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 args = parser.parse_args() |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 |
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 ## |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 ## Configuration of the custom primitives that are manually |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 ## implemented (not autogenerated) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 ## |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 |
183
d31f216c9462
extracted custom functions/methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
182
diff
changeset
|
60 TARGET = os.path.realpath(args.target) |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 |
183
d31f216c9462
extracted custom functions/methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
182
diff
changeset
|
63 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
|
64 CUSTOM_METHODS = json.loads(f.read()) |
182
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
65 |
183
d31f216c9462
extracted custom functions/methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
182
diff
changeset
|
66 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
|
67 CUSTOM_FUNCTIONS = json.loads(f.read()) |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 partials = {} |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 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
|
73 partials['function_body'] = f.read() |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 |
181
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
75 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
|
76 partials['function_documentation'] = f.read() |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
77 |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 renderer = pystache.Renderer( |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 escape = lambda u: u, # No escaping |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 partials = partials, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 ) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 |
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 with open(args.model, 'r') as f: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 model = json.loads(f.read()) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 |
194
0c5da632f34d
added description of classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
88 with open(args.classes, 'r') as f: |
0c5da632f34d
added description of classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
89 classes_description = json.loads(f.read()) |
0c5da632f34d
added description of classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
90 |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 def ToUpperCase(name): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 s = '' |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 for i in range(len(name)): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 if name[i].isupper(): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 if len(s) == 0: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 s += name[i] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 elif name[i - 1].islower(): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 s += '_' + name[i] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 elif (i + 1 < len(name) and |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 name[i - 1].islower() and |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 name[i + 1].isupper()): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 s += '_' + name[i] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 else: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 s += name[i] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 else: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 s += name[i].upper() |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 return s |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
111 def ToLowerCase(name): |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
112 s = '' |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
113 for i in range(len(name)): |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
114 if (name[i].isupper() and |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
115 len(s) != 0): |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
116 s += '_' |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
117 s += name[i].lower() |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
118 return s |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
119 |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
120 |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 def GetShortName(name): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 if not name.startswith('OrthancPlugin'): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 raise Exception() |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 else: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 return name[len('OrthancPlugin'):] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 |
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 ORTHANC_TO_PYTHON_NUMERIC_TYPES = { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 # https://docs.python.org/3/c-api/arg.html#numbers |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 # https://en.wikipedia.org/wiki/C_data_types |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 'uint8_t' : { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 'type' : 'unsigned char', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 'format' : 'b', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 }, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 'int32_t' : { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 'type' : 'long int', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 'format' : 'l', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 }, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 'uint16_t' : { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 'type' : 'unsigned short', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 'format' : 'H', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 }, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 'uint32_t' : { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 'type' : 'unsigned long', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 'format' : 'k', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 }, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 'uint64_t' : { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 'type' : 'unsigned long long', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 'format' : 'K', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 }, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 'float' : { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 'type' : 'float', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 'format' : 'f', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 } |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 } |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 |
181
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
159 def DocumentFunction(f): |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
160 documentation = {} |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
161 description = f['documentation'].get('description', []) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
162 if len(description) > 0: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
163 documentation['short_description'] = description[0].split('.') [0] |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
164 documentation['description'] = map(lambda x: { 'text' : x }, description) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
165 |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
166 args_declaration = [] |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
167 args_documentation = [] |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
168 for a in f['args']: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
169 arg_name = ToLowerCase(a['sdk_name']) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
170 if a['sdk_type'] == 'const char *': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
171 arg_type = 'str' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
172 elif a['sdk_type'] == 'float': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
173 arg_type = 'float' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
174 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
|
175 arg_type = 'bytes' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
176 elif a['sdk_type'] == 'enumeration': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
177 arg_type = GetShortName(a['sdk_enumeration']) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
178 elif a['sdk_type'] == 'const_object': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
179 arg_type = GetShortName(a['sdk_class']) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
180 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
|
181 arg_type = 'int' |
192
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
182 elif a['sdk_type'] == 'Callable': |
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
183 arg_type = a['callable_type'] |
181
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
184 else: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
185 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
|
186 args_declaration.append('%s: %s' % (arg_name, arg_type)) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
187 args_documentation.append({ |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
188 'name' : arg_name, |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
189 'type' : arg_type, |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
190 'text' : f['documentation']['args'] [a['sdk_name']], |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
191 }) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
192 |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
193 documentation['args_declaration'] = ', '.join(args_declaration) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
194 documentation['args'] = args_documentation |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
195 documentation['has_args'] = len(args_documentation) > 0 |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
196 documentation['has_return'] = True |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
197 |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
198 if f['return_sdk_type'] == 'enumeration': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
199 if f['return_sdk_enumeration'] == 'OrthancPluginErrorCode': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
200 documentation['has_return'] = False |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
201 documentation['return_type'] = 'None' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
202 else: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
203 documentation['return_type'] = GetShortName(f['return_sdk_enumeration']) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
204 elif f['return_sdk_type'] == 'object': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
205 documentation['return_type'] = GetShortName(f['return_sdk_class']) |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
206 elif f['return_sdk_type'] == 'void': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
207 documentation['has_return'] = False |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
208 documentation['return_type'] = 'None' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
209 elif f['return_sdk_type'] == 'OrthancPluginMemoryBuffer *': |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
210 documentation['return_type'] = 'bytes' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
211 elif f['return_sdk_type'] in [ 'char *', 'const char *' ]: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
212 documentation['return_type'] = 'str' |
182
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
213 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
|
214 documentation['return_type'] = 'int' |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
215 else: |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
216 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
|
217 |
182
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
218 if documentation['has_return']: |
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
219 documentation['return_text'] = f['documentation']['return'] |
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
220 |
181
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
221 return documentation |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
222 |
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
223 |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 def FormatFunction(f): |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 answer = { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 'c_function' : f['c_function'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 'short_name' : GetShortName(f['c_function']), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 'has_args' : len(f['args']) > 0, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
229 'count_args' : len(f['args']), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 } |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 tuple_format = '' |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 tuple_target = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
234 call_args = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
235 args = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
236 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
237 for arg in f['args']: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 # https://docs.python.org/3/c-api/arg.html |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
239 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
|
240 args.append({ |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
241 'name' : arg['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
242 'python_type' : 'Py_buffer', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
243 'release' : 'PyBuffer_Release(&%s);' % arg['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
244 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
245 tuple_format += 's*' |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
246 elif arg['sdk_type'] == 'const char *': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
247 args.append({ |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
248 'name' : arg['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
249 'python_type' : 'const char*', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
250 'initialization' : ' = NULL', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
251 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
252 tuple_format += 's' |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
253 elif arg['sdk_type'] == 'enumeration': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
254 args.append({ |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
255 'name' : arg['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
256 'python_type' : 'long int', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
257 'initialization' : ' = 0', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
258 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
259 tuple_format += 'l' |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
260 elif arg['sdk_type'] == 'const_object': |
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' : 'PyObject*', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
264 'initialization' : ' = NULL', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
265 'check_object_type' : arg['sdk_class'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
266 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
267 tuple_format += 'O' |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
268 elif arg['sdk_type'] in ORTHANC_TO_PYTHON_NUMERIC_TYPES: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
269 t = ORTHANC_TO_PYTHON_NUMERIC_TYPES[arg['sdk_type']] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
270 args.append({ |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
271 'name' : arg['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
272 'python_type' : t['type'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
273 'initialization' : ' = 0', |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
274 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
275 tuple_format += t['format'] |
192
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
276 elif arg['sdk_type'] == 'Callable': |
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
277 # This is only used to generate the documentation file "orthanc.pyi" |
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
278 args.append({ |
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
279 'name' : arg['name'], |
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
280 }) |
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
281 tuple_format += 'O' |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
282 else: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
283 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
|
284 return None |
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 tuple_target.append('&' + arg['name']) |
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 arg['sdk_type'] == 'const void *': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
289 call_args.append(arg['name'] + '.buf') |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
290 elif arg['sdk_type'] == 'const_void_pointer_with_size': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
291 call_args.append(arg['name'] + '.buf') |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
292 call_args.append(arg['name'] + '.len') |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
293 elif arg['sdk_type'] == 'enumeration': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
294 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
|
295 elif arg['sdk_type'] == 'const_object': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
296 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
|
297 arg['name'], arg['sdk_class'], arg['name'])) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
298 else: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
299 call_args.append(arg['name']) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
300 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
301 answer['args'] = args |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
302 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
303 if f['return_sdk_type'] == 'void': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
304 answer['return_void'] = True |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
305 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
|
306 answer['return_long'] = True |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
307 elif f['return_sdk_type'] == 'OrthancPluginMemoryBuffer *': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
308 answer['return_bytes'] = True |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
309 elif f['return_sdk_type'] == 'enumeration': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
310 if f['return_sdk_enumeration'] == 'OrthancPluginErrorCode': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
311 answer['return_error'] = True |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
312 else: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
313 answer['return_enumeration'] = f['return_sdk_enumeration'] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
314 elif f['return_sdk_type'] == 'char *': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
315 answer['return_dynamic_string'] = True |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
316 elif f['return_sdk_type'] == 'const char *': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
317 answer['return_static_string'] = True |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
318 elif f['return_sdk_type'] == 'object': |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
319 answer['return_object'] = f['return_sdk_class'] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
320 else: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
321 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
|
322 return None |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
323 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
324 answer['tuple_format'] = ', '.join([ '"' + tuple_format + '"' ] + tuple_target) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
325 |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
326 if 'documentation' in f: |
181
faaa3fec799a
refactoring using FunctionDocumentation.mustache
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
327 answer['documentation'] = DocumentFunction(f) |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
328 |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
329 if len(call_args) > 0: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
330 answer['call_args'] = ', ' + ', '.join(call_args) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
331 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
332 return answer |
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 |
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 globalFunctions = [] |
192
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
337 customFunctions = [] |
172
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 f in model['global_functions']: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
340 g = FormatFunction(f) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
341 if g != None: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
342 globalFunctions.append(g) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
343 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
344 for f in CUSTOM_FUNCTIONS: |
192
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
345 f['documentation'] = DocumentFunction(f) |
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
346 customFunctions.append(f) |
172
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 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
349 enumerations = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
350 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
351 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
|
352 ENUMERATION_TEMPLATE = f.read() |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
353 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
354 for e in model['enumerations']: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
355 values = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
356 for value in e['values']: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
357 values.append({ |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
358 'key' : ToUpperCase(value['key']), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
359 'value' : value['value'], |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
360 'documentation' : value['documentation'], |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
361 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
362 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
363 enumerations.append({ |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
364 'name' : e['name'], |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
365 'short_name' : GetShortName(e['name']), |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
366 'path' : 'sdk_%s.impl.h' % e['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
367 'values' : values, |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
368 'documentation' : e['documentation'], |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
369 }) |
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 path = 'sdk_%s.impl.h' % e['name'] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
372 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
373 with open(os.path.join(TARGET, path), 'w') as f: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
374 f.write(pystache.render(ENUMERATION_TEMPLATE, { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
375 'name' : e['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
376 'short_name' : GetShortName(e['name']), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
377 'values' : values, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
378 })) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
379 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
380 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
381 classes = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
382 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
383 for c in model['classes']: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
384 methods = [] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
385 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
386 for m in c['methods']: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
387 g = FormatFunction(m) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
388 if g != None: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
389 g['self'] = ', self->object_' |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
390 methods.append(g) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
391 |
182
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
392 custom_methods = [] |
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
393 |
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
394 if c['name'] in CUSTOM_METHODS: |
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
395 for custom_method in CUSTOM_METHODS[c['name']]: |
185 | 396 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
|
397 custom_method['documentation'] = DocumentFunction(custom_method) |
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
398 custom_methods.append(custom_method) |
20b004998fc2
documentation of custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
181
diff
changeset
|
399 |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
400 classes.append({ |
194
0c5da632f34d
added description of classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
193
diff
changeset
|
401 'description' : classes_description[c['name']], |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
402 'class_name' : c['name'], |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
403 'short_name' : GetShortName(c['name']), |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
404 'methods' : methods, |
193
66cd20e970d8
simplification for custom methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
192
diff
changeset
|
405 'custom_methods' : sorted(custom_methods, key = lambda x: x['short_name']), |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
406 }) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
407 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
408 if 'destructor' in c: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
409 classes[-1]['destructor'] = c['destructor'] |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
410 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
411 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
412 |
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, 'Class.mustache'), 'r') as f: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
415 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
|
416 classDefinition = f.read() |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
417 classMethods = g.read() |
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 for c in classes: |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
420 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
|
421 h.write(renderer.render(classDefinition, c)) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
422 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
|
423 h.write(renderer.render(classMethods, c)) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
424 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
425 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
426 sortedClasses = sorted(classes, key = lambda x: x['class_name']) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
427 sortedEnumerations = sorted(enumerations, key = lambda x: x['name']) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
428 sortedGlobalFunctions = sorted(globalFunctions, key = lambda x: x['c_function']) |
192
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
429 sortedCustomFunctions = sorted(customFunctions, key = lambda x: x['short_name']) |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
430 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
431 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
|
432 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
|
433 h.write(renderer.render(f.read(), { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
434 'global_functions' : sortedGlobalFunctions, |
192
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
435 'custom_functions' : sortedCustomFunctions, |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
436 })) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
437 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
438 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
|
439 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
|
440 h.write(renderer.render(f.read(), { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
441 'classes' : sortedClasses, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
442 'enumerations' : sortedEnumerations, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
443 'global_functions' : sortedGlobalFunctions, |
192
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
444 'custom_functions' : sortedCustomFunctions, |
172
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
445 })) |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
446 |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
447 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
|
448 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
|
449 h.write(renderer.render(f.read(), { |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
450 'classes' : sortedClasses, |
8382c7dea471
created CodeAnalysis/GenerateOrthancSDK.py
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
451 })) |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
452 |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
453 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
|
454 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
|
455 h.write(renderer.render(f.read(), { |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
456 'classes' : sortedClasses, |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
457 'enumerations' : sortedEnumerations, |
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
458 'global_functions' : sortedGlobalFunctions, |
192
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
459 'custom_functions' : sortedCustomFunctions, |
180
ddf3e987827f
created Python documentation for the Orthanc interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
179
diff
changeset
|
460 })) |
190 | 461 |
462 | |
463 countMethods = 0 | |
464 for c in sortedClasses: | |
465 countMethods += len(c['methods']) | |
466 | |
192
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
467 print('\nNumber of wrapped global functions: %d' % len(sortedGlobalFunctions + sortedCustomFunctions)) |
190 | 468 print('Number of wrapped methods: %d\n' % countMethods) |
192
b0f096d2339e
documentation of orthanc.RegisterRestCallback()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
190
diff
changeset
|
469 print('Total number of wrapped global functions or methods: %d\n' % (len(sortedGlobalFunctions + sortedCustomFunctions) + countMethods)) |