Mercurial > hg > orthanc-tests
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 |
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 |
6 # | |
7 # This program is free software: you can redistribute it and/or | |
8 # modify it under the terms of the GNU General Public License as | |
9 # published by the Free Software Foundation, either version 3 of the | |
10 # License, or (at your option) any later version. | |
11 # | |
12 # This program is distributed in the hope that it will be useful, but | |
13 # WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 # General Public License for more details. | |
16 # | |
17 # You should have received a copy of the GNU General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 import argparse | |
22 import os | |
23 import re | |
24 import socket | |
25 import subprocess | |
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 | 28 |
29 ## | |
30 ## Parse the command-line arguments | |
31 ## | |
32 | |
33 parser = argparse.ArgumentParser(description = 'Generate the configuration file for the ' + | |
34 'instance of Orthanc to be checked against the integration tests.') | |
35 | |
36 parser.add_argument('--target', | |
37 default = 'IntegrationTestsConfiguration.json', | |
38 help = 'Configuration file to generate') | |
39 | |
40 parser.add_argument('--force', | |
41 help = 'Overwrite the file even if it already exists', | |
42 action = 'store_true') | |
43 | |
31 | 44 parser.add_argument('--plugins', |
45 help = 'Add a path to a folder containing plugins') | |
46 | |
82 | 47 parser.add_argument('--dicom', |
48 type = int, | |
49 default = 4242, | |
50 help = 'DICOM port of the Orthanc server') | |
51 | |
3 | 52 args = parser.parse_args() |
53 | |
54 | |
55 ## | |
56 ## Check whether the file can be overwritten | |
57 ## | |
58 | |
59 if os.path.exists(args.target) and not args.force: | |
60 print(""" | |
61 WARNING: The file %s will be overwritten! | |
62 | |
63 Are you sure ["yes" to go on]?""" % args.target) | |
64 | |
65 if sys.stdin.readline().strip() != 'yes': | |
66 print('Aborting...') | |
67 exit(0) | |
68 | |
69 | |
70 ## | |
71 ## Generate the configuration file | |
72 ## | |
73 | |
74 | |
75 # Retrieve the IP address of the localhost | |
76 ip = socket.gethostbyname(socket.gethostname()) | |
77 | |
78 subprocess.check_call([ 'Orthanc', '--config=%s' % args.target ]) | |
79 | |
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 | 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 | 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 | 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 | 119 |
31 | 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 | 122 |
3 | 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') |