Skip to content

Commit d4c990d

Browse files
committed
Change --init to make shorter translate-msgs.config.json
1 parent 78518ac commit d4c990d

3 files changed

Lines changed: 12 additions & 16 deletions

File tree

translate-messages/src/translate_messages/lib/init.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ def cli(caller_file):
1111
cli.project_root = os.path.join(os.path.dirname(caller_file),
1212
f"{ '' if 'src' in os.path.dirname(caller_file) else '../../' }../../")
1313
for filename in [f'{cli.name}.config.json', f'{cli.name.replace("messages", "msgs")}.config.json']:
14-
config_path = os.path.join(cli.project_root, filename)
15-
if os.path.exists(config_path):
16-
cli.config = data.sns.from_dict(data.json.read(config_path)) ; break
14+
cli.config_path = os.path.join(cli.project_root, filename)
15+
if os.path.exists(cli.config_path):
16+
cli.config = data.sns.from_dict(data.json.read(cli.config_path))
17+
cli.config_filename = filename
18+
break
1719

1820
# Parse CLI args
1921
argp = argparse.ArgumentParser(
@@ -45,18 +47,18 @@ def cli(caller_file):
4547
return cli
4648

4749
def config_file(cli):
48-
if os.path.exists(cli.config.path):
49-
return print(f'Config already exists at {cli.config.path}')
50+
if os.path.exists(cli.config_path) : return print(f'Config already exists at {cli.config_path}')
51+
cli.config_filename = 'translate-msgs.config.json'
52+
cli.config_path = os.path.join(cli.project_root, cli.config_filename)
5053
try:
51-
jsd_url = f'{cli.urls.jsdelivr}/{cli.name}/{cli.config.filename}'
54+
jsd_url = f'{cli.urls.jsdelivr}/{cli.name}/{cli.config_filename}'
5255
resp = requests.get(jsd_url, timeout=5)
5356
resp.raise_for_status()
5457
cli.file_config = resp.json()
5558
except (requests.RequestException, ValueError):
5659
cli.file_config = {}
57-
58-
data.json.write(cli.file_config, cli.config.path)
59-
print(f'Default config created at {cli.config.path}')
60+
data.json.write(cli.file_config, cli.config_path)
61+
print(f'Default config created at {cli.config_path}')
6062

6163
def locales_dir(target_dir):
6264
lib_dir = os.path.abspath(os.path.dirname(__file__))

translate-messages/translate-messages.config.json

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)