Passed
Pull Request — master (#2)
by Yang
01:44
created

DICOM_RequireDecompression()   B

Complexity

Conditions 8

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 15
rs 7.3333
c 0
b 0
f 0
cc 8
nop 1
1
import logging
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
import os
3
import pydicom, subprocess
0 ignored issues
show
introduced by
Multiple imports on one line (pydicom, subprocess)
Loading history...
introduced by
standard import "import pydicom, subprocess" should be placed before "import pydicom, subprocess"
Loading history...
4
import platform
0 ignored issues
show
Unused Code introduced by
The import platform seems to be unused.
Loading history...
introduced by
standard import "import platform" should be placed before "import pydicom, subprocess"
Loading history...
5
from DICOM.validate import DICOM_validator
0 ignored issues
show
introduced by
Unable to import 'DICOM.validate'
Loading history...
6
from pydicom.filereader import read_file_meta_info
0 ignored issues
show
introduced by
Imports from package pydicom are not grouped
Loading history...
7
8
9
def DICOM_decompress(input_file, out_put):
0 ignored issues
show
Coding Style Naming introduced by
The name DICOM_decompress does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
10
    """
11
    A wrapper for DCMDJPEG for decompression
12
    :param input_file:
13
    :param out_put:
14
    :return:
15
    """
16
    logger = logging.getLogger(__name__)
17
18
    if os.path.exists(out_put):
19
        return False, "Output_exist already."
20
21
    try:
22
        subprocess.check_output(['dcmdjpeg', input_file, out_put])
23
24
    # When dcmdjpeg has errors
25
    except subprocess.CalledProcessError as e:
0 ignored issues
show
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
26
        logger.info(e.output)
27
        ErrorMessage = "File type not compatible for " + input_file
0 ignored issues
show
Coding Style Naming introduced by
The name ErrorMessage does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
28
        logger.info(ErrorMessage)
29
        return False, ErrorMessage
30
31
    # all other unanticipated errors:
32
    except:
0 ignored issues
show
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
33
        ErrorMessage = "Exception encountered while calling DCMDJPEG. Contact author to investigate, attach " + input_file
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (122/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style Naming introduced by
The name ErrorMessage does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
34
        logger.info(ErrorMessage)
35
        return False, ErrorMessage
36
37
    # Ensure that data is actually written out.
38
    if not os.path.exists(out_put):
39
        ErrorMessage = "Cannot write out final file for some reason " + input_file
0 ignored issues
show
Coding Style Naming introduced by
The name ErrorMessage does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
40
        logger.info(ErrorMessage)
41
        return False, ErrorMessage
42
43
    # Test read the data after writing.
44
    try:
45
        data = pydicom.read_file(out_put)
0 ignored issues
show
Unused Code introduced by
The variable data seems to be unused.
Loading history...
46
    except:
0 ignored issues
show
Coding Style Best Practice introduced by
General except handlers without types should be used sparingly.

Typically, you would use general except handlers when you intend to specifically handle all types of errors, f.e. when logging. Otherwise, such general error handlers can mask errors in your application that you want to know of.

Loading history...
47
        ErrorMessage = "Exception encountered while verifying the proper writing out of the DICOM data. Contact author to investigate, attach " + input_file
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (156/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Coding Style Naming introduced by
The name ErrorMessage does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
48
        logger.info(ErrorMessage)
49
        return False, ErrorMessage
50
51
    logger.info("Success writen " + input_file + " to " + out_put)
52
    return True, "All good"
53
54
def DICOM_RequireDecompression(transfer_syntax):
0 ignored issues
show
Coding Style Naming introduced by
The name DICOM_RequireDecompression does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
55
    """
56
    Determine if the transfer syntax symbolize LEE or JPEG compressed!
57
    :param transfer_syntax:
58
    :return: whether the DICOM files are compressed.
59
    """
60
61
    if not ("1.2.840.10008.1.2" in transfer_syntax):
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after not.
Loading history...
62
        raise ValueError
63
    elif transfer_syntax == "1.2.840.10008.1.2" or transfer_syntax[18] == '1' or transfer_syntax[18] == '2':
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
64
        return False
65
    elif transfer_syntax[18] == '4' or transfer_syntax[18] == '5' or transfer_syntax[18] == '6':
66
        return True
67
    else:
68
        raise ValueError
69
70
71
def DICOM_TransferSyntax(file_path):
0 ignored issues
show
Coding Style Naming introduced by
The name DICOM_TransferSyntax does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
72
    """
73
    Used to find if a file is compressed
74
    :param file_path:
75
    :return:
76
    """
77
78
    # Validity check:
79
    success, DICOM = DICOM_validator(file_path)
0 ignored issues
show
Coding Style Naming introduced by
The name DICOM does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Unused Code introduced by
The variable DICOM seems to be unused.
Loading history...
80
    if not success:
81
        raise IOError
82
83
    # Now read the meta information.
84
    dicom_file = read_file_meta_info(file_path)
85
    transfer_syntax = dicom_file.TransferSyntaxUID
86
87
    return transfer_syntax
88
89
def DICOM_QuickTransferSyntaxCheck(file_path):
0 ignored issues
show
Coding Style Naming introduced by
The name DICOM_QuickTransferSyntaxCheck does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
90
    # Validity check:
91
    success, DICOM = DICOM_validator(file_path)
0 ignored issues
show
Coding Style Naming introduced by
The name DICOM does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
92
    if not success:
93
        raise IOError
94
    import dicom
95
96
    # Now read the meta information.
97
    if DICOM.file_meta.TransferSyntaxUID in dicom.dataset.NotCompressedPixelTransferSyntaxes:
0 ignored issues
show
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
Bug introduced by
The Module dicom does not seem to have a member named dataset.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
98
        return False
99
    else:
100
        return True
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...