@@ -196,37 +196,18 @@ def _find_or_create_user_id():
196
196
IDs are generated randomly with UUID.
197
197
"""
198
198
199
- legacy_dvc_config_dir = user_config_dir ("dvc" , "iterative" )
200
199
config_dir = user_config_dir (
201
200
os .path .join ("iterative" , "telemetry" ), "iterative"
202
201
)
203
- legacy_user_id_file = os .path .join (legacy_dvc_config_dir , "user_id" )
204
202
user_id_file = os .path .join (config_dir , "user_id" )
205
203
lockfile = os .path .join (config_dir , "user_id.lock" )
206
204
207
205
try :
208
206
with FileLock ( # pylint: disable=abstract-class-instantiated
209
207
lockfile , timeout = 5
210
208
):
211
- try :
212
-
213
- # Backwards compatibility with DVC legacy telemetry location.
214
- # Will only try to copy over if config_dir doesn't
215
- # exist (first run per machine)
216
- if legacy_dvc_config_dir .exists () and not config_dir .exists ():
217
- with open (
218
- legacy_user_id_file , encoding = "utf8"
219
- ) as fobj_legacy :
220
- with open (
221
- user_id_file , "w" , encoding = "utf8"
222
- ) as fobj_new :
223
- user_id = json .load (fobj_legacy )["user_id" ]
224
- json .dump ({"user_id" : user_id }, fobj_new )
225
-
226
- except (FileNotFoundError , ValueError , KeyError ):
227
-
228
- # Fail silently
229
- pass
209
+ # Backwards compatibility with DVC legacy telemetry location.
210
+ _try_load_legacy_user_id (config_dir , user_id_file )
230
211
231
212
try :
232
213
@@ -249,3 +230,22 @@ def _find_or_create_user_id():
249
230
except Timeout :
250
231
logger .debug ("Failed to acquire %s" , lockfile )
251
232
return None
233
+
234
+
235
+ def _try_load_legacy_user_id (config_dir , user_id_file ):
236
+ legacy_config_dir = user_config_dir ("dvc" , "iterative" )
237
+ legacy_user_id_file = os .path .join (legacy_config_dir , "user_id" )
238
+
239
+ try :
240
+ # Will only to copy over if config_dir doesn't
241
+ # exist (first run per machine)
242
+ if legacy_config_dir .exists () and not config_dir .exists ():
243
+ with open (legacy_user_id_file , encoding = "utf8" ) as fobj_legacy :
244
+ with open (user_id_file , "w" , encoding = "utf8" ) as fobj_new :
245
+ user_id = json .load (fobj_legacy )["user_id" ]
246
+ json .dump ({"user_id" : user_id }, fobj_new )
247
+
248
+ except (FileNotFoundError , ValueError , KeyError ):
249
+
250
+ # Fail silently
251
+ pass
0 commit comments