view GenerateConfigurationForTests.py @ 228:84244277413b

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 27 Feb 2019 15:41:35 +0100
parents f5414254ccaa
children f2af7bdc9bf8
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
# Copyright (C) 2017-2019 Osimis S.A., 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
import urllib


##
## 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())


# Download the content of the default configuration file
with open(args.target, 'w') as f:
    url = 'https://bitbucket.org/sjodogne/orthanc/raw/default/Resources/Configuration.json'
    http = urllib.urlopen(url)
    if http.getcode() != 200:
        raise Exception('Cannot download: %s' % url)
    
    f.write(http.read())
    

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['DefaultEncoding'] = 'Utf8'
config['AllowFindSopClassesInStudy'] = False
config['AuthenticationEnabled'] = True
config['DicomAet'] = 'ORTHANC'
config['DicomAssociationCloseDelay'] = 0
config['DicomModalities'] = {
     'orthanctest' : [ 'ORTHANCTEST', ip, 5001 ],
     'self' : [ 'ORTHANC', '127.0.0.1', 4242 ]
}
config['DicomPort'] = args.dicom
config['HttpCompressionEnabled'] = False
config['LogExportedResources'] = True
config['OrthancPeers'] = { 'peer' : [ 'http://%s:%d/' % (ip, 5000), 'alice', 'orthanctest' ] }
config['RegisteredUsers'] = { 'alice' : 'orthanctest' }
config['RemoteAccessAllowed'] = True
config['OverwriteInstances'] = True
config['JobsHistorySize'] = 1000
config['SynchronousCMove'] = False
config['MediaArchiveSize'] = 1
config['SaveJobs'] = False
del config['KeepAlive']

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' 
        ]
    }
}

config['Worklists'] = {
    'Enable': True,
    'Database': os.path.abspath(os.path.join(os.path.dirname(__file__), './Database/Worklists/Working')),
}

config['PostgreSQL'] = {
    'EnableIndex' : True,
    'EnableStorage' : True,
    'Host' : 'localhost',
    'Port' : 5432,
    'Database' : 'orthanctest',
    'Username' : 'postgres',
    'Password' : 'postgres'
}

config['MySQL'] = {
    'EnableIndex' : True,
    'EnableStorage' : True,
    'Host' : 'localhost',
    'Port' : 3306,
    'Database' : 'orthanctest',
    'Username' : 'root',
    'Password' : 'root',
    'UnixSocket' : '',
}



# 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')