@@ -97,11 +97,13 @@ def consent_file_base_dir():
97
97
dir_to_check = Path .home ()
98
98
99
99
if dir_to_check is None :
100
- raise Exception ('Failed to find location of the openvino_telemetry file.' )
100
+ log .warning ('Failed to find location of the openvino_telemetry file.' )
101
+ return None
101
102
102
103
consent_base_dir = os .path .expandvars (dir_to_check )
103
104
if not os .path .isdir (consent_base_dir ):
104
- raise Exception ('Failed to find location of the openvino_telemetry file.' )
105
+ log .warning ('Failed to find location of the openvino_telemetry file.' )
106
+ return None
105
107
106
108
return consent_base_dir
107
109
@@ -116,7 +118,8 @@ def consent_file_subdirectory():
116
118
return 'Intel Corporation'
117
119
elif platform in ['Linux' , 'Darwin' ]:
118
120
return 'intel'
119
- raise Exception ('Failed to find location of the openvino_telemetry file.' )
121
+ log .warning ('Failed to find location of the openvino_telemetry file.' )
122
+ return None
120
123
121
124
def consent_file (self ):
122
125
"""
@@ -144,6 +147,9 @@ def create_or_check_consent_dir(self):
144
147
:return: True if the directory is created and writable, otherwise False
145
148
"""
146
149
base_dir = self .consent_file_base_dir ()
150
+ consent_file_subdirectory = self .consent_file_subdirectory ()
151
+ if self .consent_file_base_dir () is None or consent_file_subdirectory is None :
152
+ return False
147
153
base_is_dir = os .path .isdir (base_dir )
148
154
base_dir_exists = os .path .exists (base_dir )
149
155
base_w_access = os .access (base_dir , os .W_OK )
@@ -155,33 +161,33 @@ def create_or_check_consent_dir(self):
155
161
"Please allow write access to the following directory: {}" .format (base_dir ))
156
162
return False
157
163
158
- consect_file_dir = os .path .join (self .consent_file_base_dir (), self . consent_file_subdirectory () )
159
- consent_file_is_dir = os .path .isdir (consect_file_dir )
160
- consent_file_dir_exists = os .path .exists (consect_file_dir )
164
+ consent_file_dir = os .path .join (self .consent_file_base_dir (), consent_file_subdirectory )
165
+ consent_file_is_dir = os .path .isdir (consent_file_dir )
166
+ consent_file_dir_exists = os .path .exists (consent_file_dir )
161
167
162
168
# If consent path exists and it is not directory, we try to remove it
163
169
if consent_file_dir_exists and not consent_file_is_dir :
164
170
try :
165
- os .remove (consect_file_dir )
171
+ os .remove (consent_file_dir )
166
172
except :
167
- log .warning ("Unable to create directory for openvino_telemetry file, as {} is invalid directory." .format (consect_file_dir ))
173
+ log .warning ("Unable to create directory for openvino_telemetry file, as {} is invalid directory." .format (consent_file_dir ))
168
174
return False
169
175
170
- if not os .path .exists (consect_file_dir ):
176
+ if not os .path .exists (consent_file_dir ):
171
177
try :
172
- os .mkdir (consect_file_dir )
178
+ os .mkdir (consent_file_dir )
173
179
174
180
# check that directory is created
175
- if not os .path .exists (consect_file_dir ):
181
+ if not os .path .exists (consent_file_dir ):
176
182
return False
177
183
except Exception as e :
178
184
log .warning ("Failed to create directory for openvino_telemetry file: {}" .format (str (e )))
179
185
return False
180
186
181
- consent_file_w_access = os .access (consect_file_dir , os .W_OK )
187
+ consent_file_w_access = os .access (consent_file_dir , os .W_OK )
182
188
if not consent_file_w_access :
183
189
log .warning ("Failed to create openvino_telemetry file. "
184
- "Please allow write access to the following directory: {}" .format (consect_file_dir ))
190
+ "Please allow write access to the following directory: {}" .format (consent_file_dir ))
185
191
return False
186
192
return True
187
193
@@ -191,6 +197,8 @@ def update_result(self, result: ConsentCheckResult):
191
197
:param result: opt-in dialog result.
192
198
:return: False if the consent file is not writable, otherwise True
193
199
"""
200
+ if self .consent_file_base_dir () is None or self .consent_file_subdirectory () is None :
201
+ return False
194
202
if not os .path .exists (self .consent_file ()):
195
203
if not self .create_new_consent_file ():
196
204
return False
@@ -297,6 +305,9 @@ def check(self, enable_opt_in_dialog, disable_in_ci=False):
297
305
Checks if user has accepted the collection of the information by checking the consent file.
298
306
:return: consent check result
299
307
"""
308
+ if self .consent_file_base_dir () is None or self .consent_file_subdirectory () is None :
309
+ return ConsentCheckResult .DECLINED
310
+
300
311
if disable_in_ci and self ._run_in_ci ():
301
312
return ConsentCheckResult .DECLINED
302
313
0 commit comments