コード例 #1
0
    def single_store(self, file, raet, raddress, rport=104):
        if not os.path.isfile(file):
            raise net.DicomIOError, 'file must be a real file, not a directory'

        cmd = os.path.join(
            net.DCM4CHE_BIN_DIR,
            'dcmsnd.bat' if sys.platform == 'win32' else 'dcmsnd'
        )
        tokens = {
            'cmd': cmd,
            'aet': self.aet,
            'raet': raet,
            'raddress': raddress,
            'rport': rport,
            'file': file,
        }
        cmd = Template(
            '$cmd -L $aet $raet@$raddress:$rport $file'
        ).safe_substitute(tokens)

        self._retcode, self._output, self._error = get_output(cmd, 4096)

        # check for errors
        if self._retcode == 1 or self._retcode == 2:
            raise self._get_exception()
コード例 #2
0
def http_send(url, spool, buffer=8192):
    nfiles, nsent_files = 0, 0

    try:
        # check that this task is not locked
        _lock_spool(spool)
    except StopTask:
        return
    
    try:
        # if instructed to stop, just do it
        _check_stop(spool, nfiles, nsent_files)
 
        logger.info('starting to send files in: %s to: %s' % (spool, url))

        # create the log folder if there is none
        try:
            log_folder = os.path.join(spool, 'client')
            if not os.path.exists(log_folder):
                os.makedirs(log_folder)
        except OSError as e:
            logger.error(e)
            return

        # if instructed to stop, just do it
        _check_stop(spool, nfiles, nsent_files)

        path = os.path.join(imagis.THIRD_PARTY_DIR, 'http_sender', 'http_sender.py')
        to_continue = '-'.join(os.listdir(log_folder))
        for file_path in files_from(spool, True):

            # if instructed to stop, just do it
            _check_stop(spool, nfiles, nsent_files)

            # do not process the log folder
            if log_folder in file_path:
                continue

            space = ' ' if WINDOWS else '\ '
            cmd = ' '.join((
                'python',
                path ,
                '-U %s' % url,
                '-f %s' % file_path.replace(' ', space),
                '-l %s' % log_folder.replace(' ', space),
                '-u store_user',
                '-p store_passwd',
                '-b %s' % buffer,
            ))

            file_name = os.path.basename(file_path)
            incomplete = ''
            if file_name in to_continue:
                # need to be continued
                cmd = cmd + ' -R'
                incomplete = 'incomplete'

            logger.info('starting to send %s file: %s' % (incomplete, file_name))

            _, output, _ = get_output(cmd)

            # if instructed to stop, just do it
            _check_stop(spool, nfiles, nsent_files)

            error = process_output(file_path, output)

            # count the number of successfully sent files
            if not error:
                nsent_files += 1
            nfiles += 1

        logger.info('%s files of %s in: %s were sent' % (nsent_files, nfiles, spool))

    except StopTask:
        pass
    finally:
        # remove spool from the list of analyzed spools
        _unlock_spool(spool)