view 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
line wrap: on
line source

#!/usr/bin/python

# Orthanc - A Lightweight, RESTful DICOM Store
# Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
# Department, University Hospital of Liege, Belgium
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


import argparse
import os
import re
import socket
import subprocess
import sys
import json

##
## Parse the command-line arguments
##

parser = argparse.ArgumentParser(description = 'Generate the configuration file for the ' +
                                 'instance of Orthanc to be checked against the integration tests.')

parser.add_argument('--target', 
                    default = 'IntegrationTestsConfiguration.json',
                    help = 'Configuration file to generate')

parser.add_argument('--force', 
                    help = 'Overwrite the file even if it already exists',
                    action = 'store_true')

parser.add_argument('--plugins', 
                    help = 'Add a path to a folder containing plugins')

parser.add_argument('--dicom',
                    type = int,
                    default = 4242,
                    help = 'DICOM port of the Orthanc server')

args = parser.parse_args()


##
## Check whether the file can be overwritten
##

if os.path.exists(args.target) and not args.force:
    print("""
WARNING: The file %s will be overwritten!

Are you sure ["yes" to go on]?""" % args.target)

    if sys.stdin.readline().strip() != 'yes':
        print('Aborting...')
        exit(0)


## 
## Generate the configuration file
##


# Retrieve the IP address of the localhost
ip = socket.gethostbyname(socket.gethostname())

subprocess.check_call([ 'Orthanc', '--config=%s' % args.target ])

with open(args.target, 'r') as f:
    # Remove the C++-style comments
    nocomment = re.sub('//.*$', '', f.read(), 0, re.MULTILINE)

    # Remove the C-style comments
    nocomment = re.sub('/\*.*?\*/', '', nocomment, 0, re.DOTALL | re.MULTILINE)

    config = json.loads(nocomment)

config['AllowFindSopClassesInStudy'] = True
config['AuthenticationEnabled'] = True
config['DefaultEncoding'] = 'Windows1251'  # For test_issue_32
config['DicomAet'] = 'ORTHANC'
config['DicomAssociationCloseDelay'] = 0
config['DicomModalities'] = { 'orthanctest' : [ 'ORTHANCTEST', ip, 5001 ] }
config['DicomPort'] = args.dicom
config['HttpCompressionEnabled'] = False
config['OrthancPeers'] = { 'peer' : [ 'http://%s:%d/' % (ip, 5000), 'alice', 'orthanctest' ] }
config['RegisteredUsers'] = { 'alice' : 'orthanctest' }
config['RemoteAccessAllowed'] = True

config['Dictionary'] = {
    "00e1,10c2" : [ "UI", "PET-CT Multi Modality Name", 1, 1, "ELSCINT1" ],
    "7053,1003" : [ "ST", "Original Image Filename", 1, 1, "Philips PET Private Group" ]
}

config['DicomWeb'] = {
    "Servers" : {
        "sample" : [ 
            "http://localhost:8042/dicom-web/",
            "alice", 
            "orthanctest" 
        ]
    }
}


# Enable case-insensitive PN (the default on versions <= 0.8.6)
config['CaseSensitivePN'] = False

if args.plugins != None:
    config['Plugins'] = [ args.plugins ]

with open(args.target, 'wt') as f:
    f.write(json.dumps(config, indent = True, sort_keys = True))
    f.write('\n')