Skip to content

Commit 3b9192c

Browse files
committed
func out
1 parent cff16b4 commit 3b9192c

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/iterative_telemetry/__init__.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -196,37 +196,18 @@ def _find_or_create_user_id():
196196
IDs are generated randomly with UUID.
197197
"""
198198

199-
legacy_dvc_config_dir = user_config_dir("dvc", "iterative")
200199
config_dir = user_config_dir(
201200
os.path.join("iterative", "telemetry"), "iterative"
202201
)
203-
legacy_user_id_file = os.path.join(legacy_dvc_config_dir, "user_id")
204202
user_id_file = os.path.join(config_dir, "user_id")
205203
lockfile = os.path.join(config_dir, "user_id.lock")
206204

207205
try:
208206
with FileLock( # pylint: disable=abstract-class-instantiated
209207
lockfile, timeout=5
210208
):
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)
230211

231212
try:
232213

@@ -249,3 +230,22 @@ def _find_or_create_user_id():
249230
except Timeout:
250231
logger.debug("Failed to acquire %s", lockfile)
251232
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

Comments
 (0)