Mercurial > hg > orthanc-tests
annotate GenerateConfigurationForTests.py @ 199:dd05820b9f44
history
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 08 Jan 2019 15:38:34 +0100 |
parents | af8e034f4262 |
children | 7a58288d1b27 |
rev | line source |
---|---|
3 | 1 #!/usr/bin/python |
2 | |
3 # Orthanc - A Lightweight, RESTful DICOM Store | |
73 | 4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
3 | 5 # Department, University Hospital of Liege, Belgium |
195 | 6 # Copyright (C) 2017-2019 Osimis S.A., Belgium |
3 | 7 # |
8 # This program is free software: you can redistribute it and/or | |
9 # modify it under the terms of the GNU General Public License as | |
10 # published by the Free Software Foundation, either version 3 of the | |
11 # License, or (at your option) any later version. | |
12 # | |
13 # This program is distributed in the hope that it will be useful, but | |
14 # WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 # General Public License for more details. | |
17 # | |
18 # You should have received a copy of the GNU General Public License | |
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | |
21 | |
22 import argparse | |
23 import os | |
24 import re | |
25 import socket | |
26 import subprocess | |
27 import sys | |
87
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
28 import json |
101
71bca28a4645
remove the dependency upon installing Orthanc to generate the default configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
29 import urllib |
71bca28a4645
remove the dependency upon installing Orthanc to generate the default configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
30 |
3 | 31 |
32 ## | |
33 ## Parse the command-line arguments | |
34 ## | |
35 | |
36 parser = argparse.ArgumentParser(description = 'Generate the configuration file for the ' + | |
37 'instance of Orthanc to be checked against the integration tests.') | |
38 | |
39 parser.add_argument('--target', | |
40 default = 'IntegrationTestsConfiguration.json', | |
41 help = 'Configuration file to generate') | |
42 | |
43 parser.add_argument('--force', | |
44 help = 'Overwrite the file even if it already exists', | |
45 action = 'store_true') | |
46 | |
31 | 47 parser.add_argument('--plugins', |
48 help = 'Add a path to a folder containing plugins') | |
49 | |
82 | 50 parser.add_argument('--dicom', |
51 type = int, | |
52 default = 4242, | |
53 help = 'DICOM port of the Orthanc server') | |
54 | |
3 | 55 args = parser.parse_args() |
56 | |
57 | |
58 ## | |
59 ## Check whether the file can be overwritten | |
60 ## | |
61 | |
62 if os.path.exists(args.target) and not args.force: | |
63 print(""" | |
64 WARNING: The file %s will be overwritten! | |
65 | |
66 Are you sure ["yes" to go on]?""" % args.target) | |
67 | |
68 if sys.stdin.readline().strip() != 'yes': | |
69 print('Aborting...') | |
70 exit(0) | |
71 | |
72 | |
73 ## | |
74 ## Generate the configuration file | |
75 ## | |
76 | |
77 | |
78 # Retrieve the IP address of the localhost | |
79 ip = socket.gethostbyname(socket.gethostname()) | |
80 | |
101
71bca28a4645
remove the dependency upon installing Orthanc to generate the default configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
81 |
71bca28a4645
remove the dependency upon installing Orthanc to generate the default configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
82 # Download the content of the default configuration file |
71bca28a4645
remove the dependency upon installing Orthanc to generate the default configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
83 with open(args.target, 'w') as f: |
71bca28a4645
remove the dependency upon installing Orthanc to generate the default configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
84 url = 'https://bitbucket.org/sjodogne/orthanc/raw/Orthanc-1.2.0/Resources/Configuration.json' |
71bca28a4645
remove the dependency upon installing Orthanc to generate the default configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
85 http = urllib.urlopen(url) |
71bca28a4645
remove the dependency upon installing Orthanc to generate the default configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
86 if http.getcode() != 200: |
71bca28a4645
remove the dependency upon installing Orthanc to generate the default configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
87 raise Exception('Cannot download: %s' % url) |
71bca28a4645
remove the dependency upon installing Orthanc to generate the default configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
88 |
71bca28a4645
remove the dependency upon installing Orthanc to generate the default configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
89 f.write(http.read()) |
71bca28a4645
remove the dependency upon installing Orthanc to generate the default configuration file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
100
diff
changeset
|
90 |
3 | 91 |
92 with open(args.target, 'r') as f: | |
87
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
93 # Remove the C++-style comments |
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
94 nocomment = re.sub('//.*$', '', f.read(), 0, re.MULTILINE) |
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
95 |
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
96 # Remove the C-style comments |
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
97 nocomment = re.sub('/\*.*?\*/', '', nocomment, 0, re.DOTALL | re.MULTILINE) |
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
98 |
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
99 config = json.loads(nocomment) |
3 | 100 |
92
dbcbffb889da
test_findscu_encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
90
diff
changeset
|
101 del config['DefaultEncoding'] |
dbcbffb889da
test_findscu_encoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
90
diff
changeset
|
102 |
95
a807a4699eb4
testing of metadata SopClassUid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
92
diff
changeset
|
103 config['AllowFindSopClassesInStudy'] = False |
87
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
104 config['AuthenticationEnabled'] = True |
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
105 config['DicomAet'] = 'ORTHANC' |
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
106 config['DicomAssociationCloseDelay'] = 0 |
188
7d585263808b
new test: test_queries_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
187
diff
changeset
|
107 config['DicomModalities'] = { |
7d585263808b
new test: test_queries_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
187
diff
changeset
|
108 'orthanctest' : [ 'ORTHANCTEST', ip, 5001 ], |
7d585263808b
new test: test_queries_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
187
diff
changeset
|
109 'self' : [ 'ORTHANC', '127.0.0.1', 4242 ] |
7d585263808b
new test: test_queries_hierarchy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
187
diff
changeset
|
110 } |
87
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
111 config['DicomPort'] = args.dicom |
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
112 config['HttpCompressionEnabled'] = False |
139 | 113 config['LogExportedResources'] = True |
87
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
114 config['OrthancPeers'] = { 'peer' : [ 'http://%s:%d/' % (ip, 5000), 'alice', 'orthanctest' ] } |
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
115 config['RegisteredUsers'] = { 'alice' : 'orthanctest' } |
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
116 config['RemoteAccessAllowed'] = True |
173 | 117 config['OverwriteInstances'] = True |
180
fcb0c14dadb8
increasing JobsHistorySize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
173
diff
changeset
|
118 config['JobsHistorySize'] = 1000 |
185
d4a5e4143d68
fixing value of SynchronousCMove
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
180
diff
changeset
|
119 config['SynchronousCMove'] = False |
187 | 120 config['MediaArchiveSize'] = 1 |
88
47a3d6c08413
easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
121 |
87
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
122 config['Dictionary'] = { |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
123 '00e1,10c2' : [ 'UI', 'PET-CT Multi Modality Name', 1, 1, 'ELSCINT1' ], |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
124 '7053,1003' : [ 'ST', 'Original Image Filename', 1, 1, 'Philips PET Private Group' ] |
87
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
125 } |
3 | 126 |
88
47a3d6c08413
easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
127 config['DicomWeb'] = { |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
128 'Servers' : { |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
129 'sample' : [ |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
130 'http://localhost:8042/dicom-web/', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
131 'alice', |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
132 'orthanctest' |
88
47a3d6c08413
easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
133 ] |
47a3d6c08413
easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
134 } |
47a3d6c08413
easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
135 } |
47a3d6c08413
easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
136 |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
137 config['Worklists'] = { |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
138 'Enable': True, |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
139 'Database': os.path.abspath(os.path.join(os.path.dirname(__file__), './Database/Worklists/Working')), |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
140 } |
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
141 |
99
37430f7430e3
config to test the PostgreSQL plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
142 config['PostgreSQL'] = { |
37430f7430e3
config to test the PostgreSQL plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
143 'EnableIndex' : True, |
37430f7430e3
config to test the PostgreSQL plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
144 'EnableStorage' : True, |
37430f7430e3
config to test the PostgreSQL plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
145 'Host' : 'localhost', |
37430f7430e3
config to test the PostgreSQL plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
146 'Port' : 5432, |
37430f7430e3
config to test the PostgreSQL plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
147 'Database' : 'orthanctest', |
37430f7430e3
config to test the PostgreSQL plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
148 'Username' : 'postgres', |
37430f7430e3
config to test the PostgreSQL plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
149 'Password' : 'postgres' |
37430f7430e3
config to test the PostgreSQL plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
150 } |
37430f7430e3
config to test the PostgreSQL plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
95
diff
changeset
|
151 |
140 | 152 config['MySQL'] = { |
153 'EnableIndex' : True, | |
154 'EnableStorage' : True, | |
155 'Host' : 'localhost', | |
156 'Port' : 3306, | |
157 'Database' : 'orthanctest', | |
158 'Username' : 'root', | |
159 'Password' : 'root', | |
153 | 160 'UnixSocket' : '', |
140 | 161 } |
162 | |
90
afbac3eb28a5
integration tests of worklists
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
163 |
88
47a3d6c08413
easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
164 |
13 | 165 # Enable case-insensitive PN (the default on versions <= 0.8.6) |
87
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
166 config['CaseSensitivePN'] = False |
82 | 167 |
31 | 168 if args.plugins != None: |
87
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
169 config['Plugins'] = [ args.plugins ] |
31 | 170 |
3 | 171 with open(args.target, 'wt') as f: |
87
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
172 f.write(json.dumps(config, indent = True, sort_keys = True)) |
4b24faec842b
test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
82
diff
changeset
|
173 f.write('\n') |