annotate GenerateConfigurationForTests.py @ 39:7412a437ab47

test
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 21 Aug 2015 15:01:05 +0200
parents f2dcf96fec51
children 97acfdf0dbce
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
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 # Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
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
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 ##
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 ## Parse the command-line arguments
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 ##
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 parser = argparse.ArgumentParser(description = 'Generate the configuration file for the ' +
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 'instance of Orthanc to be checked against the integration tests.')
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 parser.add_argument('--target',
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 default = 'IntegrationTestsConfiguration.json',
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 help = 'Configuration file to generate')
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 parser.add_argument('--force',
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 help = 'Overwrite the file even if it already exists',
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 action = 'store_true')
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
31
e07deb07289d path to plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
43 parser.add_argument('--plugins',
e07deb07289d path to plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
44 help = 'Add a path to a folder containing plugins')
e07deb07289d path to plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
45
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 args = parser.parse_args()
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 ##
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 ## Check whether the file can be overwritten
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 ##
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 if os.path.exists(args.target) and not args.force:
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 print("""
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 WARNING: The file %s will be overwritten!
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 Are you sure ["yes" to go on]?""" % args.target)
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 sys.stdin.readline().strip() != 'yes':
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 print('Aborting...')
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 exit(0)
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 ##
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 ## Generate the configuration file
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 ##
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 # Retrieve the IP address of the localhost
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 ip = socket.gethostbyname(socket.gethostname())
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 subprocess.check_call([ 'Orthanc', '--config=%s' % args.target ])
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 with open(args.target, 'r') as f:
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 config = f.read()
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 config = re.sub(r'("DicomAet"\s*:)\s*".*?"', r'\1 "ORTHANC"', config)
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 config = re.sub(r'("RemoteAccessAllowed"\s*:)\s*false', r'\1 true', config)
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 config = re.sub(r'("AuthenticationEnabled"\s*:)\s*false', r'\1 true', config)
21
2a29bcff60a7 tests of image decoding
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 13
diff changeset
80 config = re.sub(r'("DicomAssociationCloseDelay"\s*:)\s*[0-9]*', r'\1 0', config)
22
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 21
diff changeset
81 config = re.sub(r'("DefaultEncoding"\s*:)\s*".*?"', r'\1 "Windows1251"', config) # For test_issue_32
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 config = re.sub(r'("RegisteredUsers"\s*:)\s*{', r'\1 { "alice" : "orthanctest"', config)
11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
83 config = re.sub(r'("DicomModalities"\s*:)\s*{', r'\1 { "orthanctest" : [ "%s", "%s", %d ]' %
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 ('ORTHANCTEST', ip, 5001), config)
11
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
85 config = re.sub(r'("OrthancPeers"\s*:)\s*{', r'\1 { "peer" : [ "http://%s:%d/", "%s", "%s" ]' %
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3
diff changeset
86 (ip, 5000, 'alice', 'orthanctest'), config)
35
f2dcf96fec51 parameter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
87 config = re.sub(r'("HttpCompressionEnabled"\s*:)\s*true', r'\1 false', config)
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
13
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
89 # Enable case-insensitive PN (the default on versions <= 0.8.6)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
90 config = re.sub(r'("CaseSensitivePN"\s*:)\s*true', r'\1 false', config)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 11
diff changeset
91
31
e07deb07289d path to plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
92 if args.plugins != None:
e07deb07289d path to plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
93 config = re.sub(r'("Plugins"\s*:\s*\[)', r'\1 "%s"' % args.plugins, config)
e07deb07289d path to plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
94
e07deb07289d path to plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 22
diff changeset
95
3
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 with open(args.target, 'wt') as f:
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 f.write(config)
2dbba2e6aa4b reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98