comparison GenerateConfigurationForTests.py @ 3:2dbba2e6aa4b

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 17 Jun 2015 10:03:49 +0200
parents
children c660a64ce2dd
comparison
equal deleted inserted replaced
2:a15734e7f0af 3:2dbba2e6aa4b
1 #!/usr/bin/python
2
3 # Orthanc - A Lightweight, RESTful DICOM Store
4 # Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
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
27
28 ##
29 ## Parse the command-line arguments
30 ##
31
32 parser = argparse.ArgumentParser(description = 'Generate the configuration file for the ' +
33 'instance of Orthanc to be checked against the integration tests.')
34
35 parser.add_argument('--target',
36 default = 'IntegrationTestsConfiguration.json',
37 help = 'Configuration file to generate')
38
39 parser.add_argument('--force',
40 help = 'Overwrite the file even if it already exists',
41 action = 'store_true')
42
43 args = parser.parse_args()
44
45
46 ##
47 ## Check whether the file can be overwritten
48 ##
49
50 if os.path.exists(args.target) and not args.force:
51 print("""
52 WARNING: The file %s will be overwritten!
53
54 Are you sure ["yes" to go on]?""" % args.target)
55
56 if sys.stdin.readline().strip() != 'yes':
57 print('Aborting...')
58 exit(0)
59
60
61 ##
62 ## Generate the configuration file
63 ##
64
65
66 # Retrieve the IP address of the localhost
67 ip = socket.gethostbyname(socket.gethostname())
68
69 subprocess.check_call([ 'Orthanc', '--config=%s' % args.target ])
70
71 with open(args.target, 'r') as f:
72 config = f.read()
73
74 config = re.sub(r'("DicomAet"\s*:)\s*".*?"', r'\1 "ORTHANC"', config)
75 config = re.sub(r'("RemoteAccessAllowed"\s*:)\s*false', r'\1 true', config)
76 config = re.sub(r'("AuthenticationEnabled"\s*:)\s*false', r'\1 true', config)
77 config = re.sub(r'("RegisteredUsers"\s*:)\s*{', r'\1 { "alice" : "orthanctest"', config)
78 config = re.sub(r'("DicomModalities"\s*:)\s*{', r'\1 { "orthanc" : [ "%s", "%s", %d ]' %
79 ('ORTHANCTEST', ip, 5001), config)
80
81 with open(args.target, 'wt') as f:
82 f.write(config)
83