Passed
Pull Request — master (#3)
by Yang
04:58
created

Python.LORIS.candidates   A

Complexity

Total Complexity 42

Size/Duplication

Total Lines 280
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 170
dl 0
loc 280
rs 9.0399
c 0
b 0
f 0
wmc 42

10 Methods

Rating   Name   Duplication   Size   Complexity  
A LORIS_candidates.parse_PSCID() 0 27 5
A LORIS_candidates.deleteCandidateCNBP() 0 26 3
A LORIS_candidates.check_instutitionID_compliance() 0 10 2
A LORIS_candidates.check_PSCID_compliance() 0 32 5
A LORIS_candidates.check_DCCID() 0 17 5
A LORIS_candidates.createCandidateCNBP() 0 36 4
A LORIS_candidates.check_subjectID_compliance() 0 9 4
B LORIS_candidates.checkDCCIDExist() 0 35 5
A LORIS_candidates.check_projectID_compliance() 0 15 2
B LORIS_candidates.checkPSCIDExist() 0 45 7

How to fix   Complexity   

Complexity

Complex classes like Python.LORIS.candidates often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
from subprocess import check_call
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 sys
3
import os
4
import re
5
import json
6
import logging
7
from dotenv import load_dotenv
8
from LORIS.query import LORIS_query
0 ignored issues
show
introduced by
Unable to import 'LORIS.query'
Loading history...
9
from LORIS.helper import LORIS_helper
0 ignored issues
show
introduced by
Unable to import 'LORIS.helper'
Loading history...
10
from LocalDB.schema import CNBP_blueprint
0 ignored issues
show
Bug introduced by
The name schema does not seem to exist in module LocalDB.
Loading history...
introduced by
Unable to import 'LocalDB.schema'
Loading history...
11
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
12
#logger = logging.getLogger('LORISQuery')
13
14
class LORIS_candidates:
0 ignored issues
show
Coding Style Naming introduced by
The name LORIS_candidates does not conform to the class naming conventions ([A-Z_][a-zA-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 class 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...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
15
16
    @staticmethod
17
    def parse_PSCID(PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name parse_PSCID does not conform to the method 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 Naming introduced by
The name PSCID does not conform to the argument 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...
18
        """
19
        Return three parts of the PSCID: institution, project, subject
20
        :param PSCID:
21
        :return:
22
        """
23
        success = load_dotenv()
24
        if not success:
25
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

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

Loading history...
26
27
        # Loading regular expression
28
        re_institution = CNBP_blueprint.PSCID_schema_institution
29
        re_project = CNBP_blueprint.PSCID_schema_project
30
        re_subject = CNBP_blueprint.PSCID_schema_subject
31
32
        # Use expression to extract from the inputted PSCID
33
        input_institution = re.search(re_institution, PSCID).group(0)
34
        input_project = re.search(re_project, PSCID).group(0)
35
        input_subject = re.search(re_subject, PSCID).group(0)
36
37
        if input_subject is None or input_project is None or input_institution is None:
38
            success = False
39
        else:
40
            success = True
41
42
        return success, input_institution, input_project, input_subject
43
44
    @staticmethod
45
    def check_instutitionID_compliance(input_institutionID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_instutitionID_compliance does not conform to the method 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 Naming introduced by
The name input_institutionID does not conform to the argument 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 method 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...
46
        # Parse from the .env standardization
47
        InsitituionID = os.getenv("institutionID")
0 ignored issues
show
Coding Style Naming introduced by
The name InsitituionID 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
49
        # Check if institution ID matches
50
        if not (input_institutionID == InsitituionID):
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after not.
Loading history...
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
51
            return False
52
        else:
53
            return True
54
55
    @staticmethod
56
    def check_projectID_compliance(input_projectID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_projectID_compliance does not conform to the method 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 Naming introduced by
The name input_projectID does not conform to the argument 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 method 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...
57
58
        # Load ProjectIDs from the environment.
59
        success = load_dotenv()
60
        if not success:
61
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

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

Loading history...
62
63
        projectID_dictionary_json: str = os.getenv("projectID_dictionary")
0 ignored issues
show
Coding Style Naming introduced by
The name projectID_dictionary_json 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...
64
        projectID_list = json.loads(projectID_dictionary_json)
0 ignored issues
show
Coding Style Naming introduced by
The name projectID_list 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...
65
66
        # check if project ID is in the projectID list.
67
        isRecognized = input_projectID in projectID_list
0 ignored issues
show
Coding Style Naming introduced by
The name isRecognized 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...
68
69
        return isRecognized
70
71
    @staticmethod
72
    def check_subjectID_compliance(input_subjectID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_subjectID_compliance does not conform to the method 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 Naming introduced by
The name input_subjectID does not conform to the argument 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 method 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...
73
        if not input_subjectID.isdigit():
74
            return False
75
76
        if int(input_subjectID) < 9999 or int(input_subjectID) > 0:
0 ignored issues
show
Unused Code introduced by
The if statement can be replaced with 'return bool(test)'
Loading history...
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
77
            return True
78
        else:
79
            return False
80
81
    @staticmethod
82
    def check_PSCID_compliance(PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_PSCID_compliance does not conform to the method 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 Naming introduced by
The name PSCID does not conform to the argument 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...
83
        """
84
        Checks PSCID inputed for 1) InstitionID format, 2) ProjectID format, 3) SubjectID format.
85
        :param PSCID:
86
        :return:
87
        """
88
        logger = logging.getLogger(__name__)
89
90
        # Parse from input PSCID
91
        success, input_institution, input_project, input_subject = LORIS_candidates.parse_PSCID(PSCID)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (102/100).

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

Loading history...
92
93
        # Ensure parsing success
94
        if not success:
95
            return False
96
97
        # Check institution ID to ensure that
98
        if not LORIS_candidates.check_instutitionID_compliance(input_institution):
99
            logger.info("Institution not compliant")
100
            return False
101
102
        # Check if projectID already exist
103
        if not LORIS_candidates.check_projectID_compliance(input_project):
104
            logger.info("ProjectID not recognized")
105
            return False
106
107
        # Check last four digits: make sure the last four characters are digits.
108
        if not LORIS_candidates.check_subjectID_compliance(str(input_subject)):
109
            logger.info("SubjectID not standardized")
110
            return False
111
112
        return True
113
114
    @staticmethod
115
    def check_DCCID(DCCID):
0 ignored issues
show
Coding Style Naming introduced by
The name check_DCCID does not conform to the method 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 Naming introduced by
The name DCCID does not conform to the argument 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...
116
        """
117
        Check if DCCID id conform.
118
        :param DCCID:
119
        :return:
120
        """
121
        if not len(str(DCCID)) == 6:
0 ignored issues
show
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
Unused Code introduced by
Consider changing "not len(str(DCCID)) == 6" to "len(str(DCCID)) != 6"
Loading history...
122
            return False
123
        elif not str(DCCID).isnumeric():
124
            return False
125
        elif DCCID > 999999:
126
            return False
127
        elif DCCID < 0:
128
            return False
129
        else:
130
            return True
131
132
    @staticmethod
133
    def deleteCandidateCNBP(token, DCCID, PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name deleteCandidateCNBP does not conform to the method 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 Naming introduced by
The name DCCID does not conform to the argument 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 Naming introduced by
The name PSCID does not conform to the argument 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 method 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...
Unused Code introduced by
The argument token seems to be unused.
Loading history...
134
        logger = logging.getLogger('UT_LORIS_delete_subject')
135
136
        # Load the hard coded variables.
137
        success = load_dotenv()
138
        if not success:
139
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

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

Loading history...
140
        ProxyIP = os.getenv("ProxyIP")
0 ignored issues
show
Coding Style Naming introduced by
The name ProxyIP 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...
141
        ProxyUsername = os.getenv("ProxyUsername")
0 ignored issues
show
Coding Style Naming introduced by
The name ProxyUsername 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...
142
        ProxyPassword = os.getenv("ProxyPassword")
0 ignored issues
show
Coding Style Naming introduced by
The name ProxyPassword 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...
143
        LORISHostPassword = os.getenv("LORISHostPassword")
0 ignored issues
show
Coding Style Naming introduced by
The name LORISHostPassword 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...
144
        LORISHostUsername = os.getenv("LORISHostUsername")
0 ignored issues
show
Coding Style Naming introduced by
The name LORISHostUsername 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...
145
        LORISHostIP = os.getenv("LORISHostIP")
0 ignored issues
show
Coding Style Naming introduced by
The name LORISHostIP 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...
146
        DeletionScript = os.getenv("DeletionScript")
0 ignored issues
show
Coding Style Naming introduced by
The name DeletionScript 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...
147
148
        # Export some variables for subsequent deletion clean script against production database (yes... because we could not automate LORIS development...):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (157/100).

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

Loading history...
149
        command_string = ["sshpass", "-p", ProxyPassword, "ssh", ProxyUsername + "@" + ProxyIP, "-t", "sshpass", "-p",
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (118/100).

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

Loading history...
150
                          LORISHostPassword, "ssh", "-L", "3001:localhost:22",
151
                          LORISHostUsername + "@" + LORISHostIP, "php", DeletionScript, "delete_candidate", str(DCCID),
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (119/100).

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

Loading history...
152
                          PSCID, "confirm"]
153
154
        logger.info(command_string)
155
        if 'TRAVIS' in os.environ:
156
            logger.info("Running LORIS delete candidate that was created for: " + PSCID)
157
            check_call(command_string)
158
159
    @staticmethod
160
    def createCandidateCNBP(token, proposed_PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name createCandidateCNBP does not conform to the method 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 Naming introduced by
The name proposed_PSCID does not conform to the argument 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...
161
        """
162
        Create a candidate using the given PSCID
163
        :param token
164
        :param proposed_PSCID:
165
        :return: DCCID
166
        """
167
        logger = logging.getLogger('LORIS_CreateCNBPCandidates')
168
        logger.info("Creating CNBP Candidates: " + proposed_PSCID)
169
170
        PSCID_exist = LORIS_candidates.checkPSCIDExist(token, proposed_PSCID)
0 ignored issues
show
Coding Style Naming introduced by
The name PSCID_exist 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...
171
        if PSCID_exist:
172
            logger.info("PSCID already exist. Quitting.")
173
            return False
174
175
        Candidate = {}
0 ignored issues
show
Coding Style Naming introduced by
The name Candidate 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...
176
        Candidate['Project'] = 'loris'
177
        Candidate['PSCID'] = proposed_PSCID
178
        Candidate['DoB'] = '2018-05-04'
179
        Candidate['Gender'] = 'Female'
180
181
        data = {"Candidate":Candidate}
182
183
        data_json = json.dumps(data)
184
185
        response_code, response = LORIS_query.postCNBP(token, "candidates/", data_json)
186
        if not LORIS_helper.is_response_success(response_code, 201):
0 ignored issues
show
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
187
            return False, None
188
        elif response is not None:  # only try to decode if response is not empty!
189
            response_json = response.json()
190
            meta = response_json.get('Meta')
191
            CandID = meta.get('CandID')
0 ignored issues
show
Coding Style Naming introduced by
The name CandID 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...
192
            return True, CandID
193
        else:
194
            return False, None
195
196
    @staticmethod
197
    def checkPSCIDExist(token, proposed_PSCID):
0 ignored issues
show
Coding Style Naming introduced by
The name checkPSCIDExist does not conform to the method 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 Naming introduced by
The name proposed_PSCID does not conform to the argument 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...
198
        """
199
        Check if Site/Study already contain the PSCID
200
        :param token:
201
        :param proposed_PSCID:
202
        :return: bool for connection, bool on if such PSCID (INSTITUTIONID + PROJECTID + SUBJECTID) exist already.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (114/100).

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

Loading history...
203
        """
204
        logger = logging.getLogger('LORIS_checkPSCIDExist')
205
        logger.info("Checking if PSCID exist: "+proposed_PSCID)
206
        success = load_dotenv()
207
        if not success:
208
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

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

Loading history...
209
        institution_check = os.getenv("institutionID")
210
211
212
        #Get list of projects
213
        response_success, loris_project = LORIS_query.getCNBP(token, r"projects/loris")
214
        if not response_success:
215
            return response_success, None
216
217
        #Get list of candidates (Candidates in v0.0.1)
218
        candidates = loris_project.get("Candidates")
219
        logger.info(candidates)
220
221
        for DCCID in candidates: #these candidates should really be only from the same ID regions.
0 ignored issues
show
Coding Style Naming introduced by
The name DCCID 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...
222
            response_success, candidate_json = LORIS_query.getCNBP(token, r"candidates/"+DCCID)
223
            if not response_success:
224
                return response_success, False
225
            # Each site following the naming convention should have SITE prefix and PI prefix and PROJECT prefix to avoid collision
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (131/100).

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

Loading history...
226
227
            # A site check here.
228
            candidate_meta = candidate_json.get("Meta")
229
            candidate_pscID = candidate_meta.get("PSCID")
0 ignored issues
show
Coding Style Naming introduced by
The name candidate_pscID 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...
230
231
            # Not gonna check is institution ID doesn't even match.
232
            if candidate_pscID[0:3] != institution_check:
233
                continue
234
235
            elif candidate_pscID == proposed_PSCID:
236
                return response_success, True
237
238
                #latest_timepoint = findLatestTimePoint(DCCID)
239
240
        return True, False
241
242
    @staticmethod
243
    def checkDCCIDExist(token, proposed_DCCID):
0 ignored issues
show
Coding Style Naming introduced by
The name checkDCCIDExist does not conform to the method 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 Naming introduced by
The name proposed_DCCID does not conform to the argument 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...
244
        """
245
        Check if Site/Study already contain the PSCID
246
        :param token:
247
        :param proposed_DCCID:
248
        :return:
249
        """
250
        logger = logging.getLogger('LORIS_checkDCCIDExist')
251
        logger.info("Checking if DCCID exist: "+str(proposed_DCCID))
252
        success = load_dotenv()
253
        if not success:
254
            raise ImportError("Credential .env NOT FOUND! Please ensure .env is set with all the necessary credentials!")
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (121/100).

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

Loading history...
255
        institution_check = os.getenv("institutionID")
0 ignored issues
show
Unused Code introduced by
The variable institution_check seems to be unused.
Loading history...
256
257
        assert (LORIS_candidates.check_DCCID(proposed_DCCID))
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
258
259
        #Get list of projects
260
        response, loris_project = LORIS_query.getCNBP(token, r"projects/loris")
261
        response_success = LORIS_helper.is_response_success(response, 200)
262
263
        if not response_success:
264
            logger.info("FAILED log response: " + str(response))
265
            return response_success, None
266
267
        #Get list of candidates (Candidates in v0.0.1)
268
        candidates = loris_project.get("Candidates")
269
        logger.info(candidates)
270
271
        for DCCID in candidates:
0 ignored issues
show
Coding Style Naming introduced by
The name DCCID 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...
272
            if str(proposed_DCCID) == DCCID:
273
                return response_success, True
274
            else:
275
                continue
276
        return response_success, False
277
278
if __name__ == "__main__":
279
    print(LORIS_candidates.check_projectID_compliance("GL01"))
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...