File: echo.py

package info (click to toggle)
odil 0.13.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,476 kB
  • sloc: cpp: 55,982; python: 3,947; javascript: 460; xml: 182; makefile: 99; sh: 36
file content (41 lines) | stat: -rw-r--r-- 1,445 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import argparse
import logging

import odil

def add_subparser(subparsers):
    parser = subparsers.add_parser(
        "echo", help="Ping a remote DICOM server (C-ECHO)",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument("host", help="Remote host address")
    parser.add_argument("port", type=int, help="Remote host port")
    parser.add_argument(
        "calling_ae_title", help="AE title of the calling application")
    parser.add_argument(
        "called_ae_title", help="AE title of the called application")
    parser.set_defaults(function=echo)
    return parser

def echo(host, port, calling_ae_title, called_ae_title):
    association = odil.Association()
    association.set_peer_host(host)
    association.set_peer_port(port)
    association.update_parameters()\
        .set_calling_ae_title(calling_ae_title)\
        .set_called_ae_title(called_ae_title) \
        .set_presentation_contexts([
            odil.AssociationParameters.PresentationContext(
                3, odil.registry.Verification,
                [ odil.registry.ImplicitVRLittleEndian ], 
                odil.AssociationParameters.PresentationContext.Role.SCU
            )
        ])
    association.associate()
    logging.info("Association established")

    echo = odil.EchoSCU(association)
    echo.echo()
    logging.info("C-ECHO successful")

    association.release()
    logging.info("Association released")