44
55from __future__ import annotations
66
7- import json
8- import os . path
7+ import os
8+ import shutil
99import ssl
1010
1111import click
1717 legacy_config_directory ,
1818 migrate_legacy_config ,
1919)
20- from tidy3d .web .cli .constants import CREDENTIAL_FILE , TIDY3D_DIR
21- from tidy3d .web .cli .migrate import migrate as migrate_authentication
20+ from tidy3d .web .cli .constants import TIDY3D_DIR
2221from tidy3d .web .core .constants import HEADER_APIKEY
2322from tidy3d .web .core .environment import Env
2423
@@ -90,15 +89,6 @@ def auth(req):
9089 req .headers [HEADER_APIKEY ] = apikey
9190 return req
9291
93- if os .path .exists (CREDENTIAL_FILE ):
94- with open (CREDENTIAL_FILE , encoding = "utf-8" ) as fp :
95- auth_json = json .load (fp )
96- email = auth_json ["email" ]
97- password = auth_json ["password" ]
98- if email and password :
99- if migrate_authentication ():
100- return
101-
10292 if not apikey :
10393 current_apikey = get_description ()
10494 message = f"Current API key: [{ current_apikey } ]\n " if current_apikey else ""
@@ -119,12 +109,6 @@ def auth(req):
119109 click .echo ("API key is invalid." )
120110
121111
122- @click .command (name = "auth-migrate" )
123- def migrate_command ():
124- """Click command to migrate the credential to api key."""
125- migrate_authentication ()
126-
127-
128112@click .command ()
129113@click .argument ("lsf_file" )
130114@click .argument ("new_file" )
@@ -158,20 +142,7 @@ def config_reset(yes: bool, preserve_profiles: bool) -> None:
158142 click .echo ("Configuration reset to defaults." )
159143
160144
161- @click .command (name = "config-migrate" )
162- @click .option (
163- "--overwrite" ,
164- is_flag = True ,
165- help = "Replace existing files in the destination configuration directory if they already exist." ,
166- )
167- @click .option (
168- "--delete-legacy" ,
169- is_flag = True ,
170- help = "Remove the legacy '~/.tidy3d' directory after a successful migration." ,
171- )
172- def config_migrate (overwrite : bool , delete_legacy : bool ) -> None :
173- """Copy configuration files from '~/.tidy3d' to the canonical location."""
174-
145+ def _run_config_migration (overwrite : bool , delete_legacy : bool ) -> None :
175146 legacy_dir = legacy_config_directory ()
176147 if not legacy_dir .exists ():
177148 click .echo ("No legacy configuration directory found at '~/.tidy3d'; nothing to migrate." )
@@ -181,6 +152,20 @@ def config_migrate(overwrite: bool, delete_legacy: bool) -> None:
181152 try :
182153 destination = migrate_legacy_config (overwrite = overwrite , remove_legacy = delete_legacy )
183154 except FileExistsError :
155+ if delete_legacy :
156+ try :
157+ shutil .rmtree (legacy_dir )
158+ except OSError as exc :
159+ click .echo (
160+ f"Destination '{ canonical_dir } ' already exists and the legacy directory "
161+ f"could not be removed. Error: { exc } "
162+ )
163+ return
164+ click .echo (
165+ f"Destination '{ canonical_dir } ' already exists. "
166+ "Skipped copying legacy files and removed the legacy '~/.tidy3d' directory."
167+ )
168+ return
184169 click .echo (
185170 f"Destination '{ canonical_dir } ' already exists. "
186171 "Use '--overwrite' to replace the existing files."
@@ -203,6 +188,23 @@ def config_migrate(overwrite: bool, delete_legacy: bool) -> None:
203188 )
204189
205190
191+ @click .command (name = "config-migrate" )
192+ @click .option (
193+ "--overwrite" ,
194+ is_flag = True ,
195+ help = "Replace existing files in the destination configuration directory if they already exist." ,
196+ )
197+ @click .option (
198+ "--delete-legacy" ,
199+ is_flag = True ,
200+ help = "Remove the legacy '~/.tidy3d' directory after a successful migration." ,
201+ )
202+ def config_migrate (overwrite : bool , delete_legacy : bool ) -> None :
203+ """Copy configuration files from '~/.tidy3d' to the canonical location."""
204+
205+ _run_config_migration (overwrite , delete_legacy )
206+
207+
206208@click .group ()
207209def config_group ():
208210 """Configuration utilities."""
@@ -212,7 +214,6 @@ def config_group():
212214config_group .add_command (config_reset , name = "reset" )
213215
214216tidy3d_cli .add_command (configure )
215- tidy3d_cli .add_command (migrate_command , name = "migrate" )
216217tidy3d_cli .add_command (convert )
217218tidy3d_cli .add_command (develop )
218219tidy3d_cli .add_command (config_group , name = "config" )
0 commit comments