annotate GenerateConfigurationForTests.py @ 88:47a3d6c08413

easier dicomweb setup
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 09 Nov 2016 17:16:35 +0100
parents 4b24faec842b
children afbac3eb28a5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/python
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 # Orthanc - A Lightweight, RESTful DICOM Store
73
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 35
diff changeset
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 # Department, University Hospital of Liege, Belgium
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 #
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 # modify it under the terms of the GNU General Public License as
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 # published by the Free Software Foundation, either version 3 of the
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 # License, or (at your option) any later version.
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 #
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful, but
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 # General Public License for more details.
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 #
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 # You should have received a copy of the GNU General Public License
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 import argparse
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 import os
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 import re
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 import socket
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 import subprocess
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 import sys
87
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
27 import json
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 ##
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 ## Parse the command-line arguments
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 ##
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 parser = argparse.ArgumentParser(description = 'Generate the configuration file for the ' +
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 'instance of Orthanc to be checked against the integration tests.')
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 parser.add_argument('--target',
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 default = 'IntegrationTestsConfiguration.json',
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 help = 'Configuration file to generate')
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 parser.add_argument('--force',
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 help = 'Overwrite the file even if it already exists',
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 action = 'store_true')
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
31
e07deb07289d path to plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
44 parser.add_argument('--plugins',
e07deb07289d path to plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
45 help = 'Add a path to a folder containing plugins')
e07deb07289d path to plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
46
82
91e2ed032f96 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
47 parser.add_argument('--dicom',
91e2ed032f96 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
48 type = int,
91e2ed032f96 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
49 default = 4242,
91e2ed032f96 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
50 help = 'DICOM port of the Orthanc server')
91e2ed032f96 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
51
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 args = parser.parse_args()
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 ##
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 ## Check whether the file can be overwritten
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 ##
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 if os.path.exists(args.target) and not args.force:
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 print("""
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 WARNING: The file %s will be overwritten!
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 Are you sure ["yes" to go on]?""" % args.target)
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 if sys.stdin.readline().strip() != 'yes':
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 print('Aborting...')
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 exit(0)
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 ##
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 ## Generate the configuration file
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 ##
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 # Retrieve the IP address of the localhost
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 ip = socket.gethostbyname(socket.gethostname())
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 subprocess.check_call([ 'Orthanc', '--config=%s' % args.target ])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 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
81 # Remove the C++-style comments
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
82 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
83
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
84 # Remove the C-style comments
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
85 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
86
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
87 config = json.loads(nocomment)
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
87
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
89 config['AllowFindSopClassesInStudy'] = True
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
90 config['AuthenticationEnabled'] = True
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
91 config['DefaultEncoding'] = 'Windows1251' # For test_issue_32
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
92 config['DicomAet'] = 'ORTHANC'
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
93 config['DicomAssociationCloseDelay'] = 0
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
94 config['DicomModalities'] = { 'orthanctest' : [ 'ORTHANCTEST', ip, 5001 ] }
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
95 config['DicomPort'] = args.dicom
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
96 config['HttpCompressionEnabled'] = False
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
97 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
98 config['RegisteredUsers'] = { 'alice' : 'orthanctest' }
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
99 config['RemoteAccessAllowed'] = True
88
47a3d6c08413 easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
100
87
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
101 config['Dictionary'] = {
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
102 "00e1,10c2" : [ "UI", "PET-CT Multi Modality Name", 1, 1, "ELSCINT1" ],
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
103 "7053,1003" : [ "ST", "Original Image Filename", 1, 1, "Philips PET Private Group" ]
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
104 }
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
88
47a3d6c08413 easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
106 config['DicomWeb'] = {
47a3d6c08413 easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
107 "Servers" : {
47a3d6c08413 easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
108 "sample" : [
47a3d6c08413 easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
109 "http://localhost:8042/dicom-web/",
47a3d6c08413 easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
110 "alice",
47a3d6c08413 easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
111 "orthanctest"
47a3d6c08413 easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
112 ]
47a3d6c08413 easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
113 }
47a3d6c08413 easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
114 }
47a3d6c08413 easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
115
47a3d6c08413 easier dicomweb setup
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 87
diff changeset
116
13
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
117 # 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
118 config['CaseSensitivePN'] = False
82
91e2ed032f96 fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
119
31
e07deb07289d path to plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
120 if args.plugins != None:
87
4b24faec842b test_reconstruct_json2 + test_private_tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 82
diff changeset
121 config['Plugins'] = [ args.plugins ]
31
e07deb07289d path to plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
122
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 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
124 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
125 f.write('\n')