Skip to content

Commit

Permalink
rename the script, make it executable, and use click
Browse files Browse the repository at this point in the history
  • Loading branch information
plasorak authored and Kurt Biery committed Aug 13, 2024
1 parent 44747d8 commit abc9266
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions scripts/scale_listrev_app
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3

import json
import shutil
import click
from os.path import exists, join, dirname
from os import remove
from rich.console import Console

console = Console()

CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
@click.command(context_settings=CONTEXT_SETTINGS)
@click.option('--num-apps', '-n', type=int, default=10, help="The number of listrev apps to create")
@click.argument('listrev_cfg_dir', type=click.Path(exists=True))
def cli(num_apps, listrev_cfg_dir):

if not exists(listrev_cfg_dir):
raise RuntimeError(f"Directory {listrev_cfg_dir} does not exist")

console.print(f'Duplicating {listrev_cfg_dir} to have {num_apps} listrev applications')

boot_json = join(listrev_cfg_dir, 'boot.json')
with open(boot_json) as file:
data = json.load(file)

new_apps = {}
new_order = []

for i in range(num_apps):
new_apps[f'listrev-app-s-{i}'] = data['apps']['listrev-app-s']
new_order.append(f'listrev-app-s-{i}')
shutil.copy(join(listrev_cfg_dir, 'data', 'listrev-app-s_conf.json'), join(listrev_cfg_dir, 'data', f'listrev-app-s-{i}_conf.json'))
shutil.copy(join(listrev_cfg_dir, 'data', 'listrev-app-s_init.json'), join(listrev_cfg_dir, 'data', f'listrev-app-s-{i}_init.json'))

remove(join(listrev_cfg_dir, 'data', f'listrev-app-s_conf.json'))
remove(join(listrev_cfg_dir, 'data', f'listrev-app-s_init.json'))

data['apps'] = new_apps
data['order'] = new_order

remove(boot_json)

with open(boot_json, 'w') as file:
json.dump(data, file, indent=4)


if __name__ == '__main__':
try:
cli()
except Exception as e:
console.print_exception()

0 comments on commit abc9266

Please sign in to comment.