diff options
Diffstat (limited to 'src/pio_ini.py')
-rwxr-xr-x | src/pio_ini.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/pio_ini.py b/src/pio_ini.py new file mode 100755 index 0000000..2d9c7c6 --- /dev/null +++ b/src/pio_ini.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +import os +import yaml + +from argparse import ArgumentParser, ArgumentError +from home.pio import get_products, platformio_ini +from home.pio.exceptions import ProductConfigNotFoundError + + +def get_config(product: str) -> dict: + config_path = os.path.join( + os.getenv('HOME'), '.config', + 'homekit_pio', f'{product}.yaml' + ) + if not os.path.exists(config_path): + raise ProductConfigNotFoundError(f'{config_path}: product config not found') + + with open(config_path, 'r') as f: + return yaml.safe_load(f) + + +if __name__ == '__main__': + products = get_products() + parser = ArgumentParser() + parser.add_argument('--product', type=str, choices=products, + help='PIO product name') + parser.add_argument('--target', type=str, required=True, + help='PIO build target') + parser.add_argument('--node-id', type=str) + parser.add_argument('--platform', default='espressif8266', type=str) + parser.add_argument('--framework', default='arduino', type=str) + parser.add_argument('--upload-port', default='/dev/ttyUSB0', type=str) + parser.add_argument('--monitor-speed', default=115200) + parser.add_argument('--debug', action='store_true') + parser.add_argument('--debug-network', action='store_true') + arg = parser.parse_args() + + if not arg.product: + product = os.path.basename(os.path.realpath(os.getcwd())) + if product not in products: + raise ArgumentError(None, 'invalid product') + else: + product = arg.product + + product_config = get_config(product) + if arg.target not in product_config['targets']: + raise ArgumentError(None, f'target {arg.target} not found for product {product}') + + ini = platformio_ini(product_config=product_config, + target=arg.target, + node_id=arg.node_id, + platform=arg.platform, + framework=arg.framework, + upload_port=arg.upload_port, + monitor_speed=arg.monitor_speed, + debug=arg.debug, + debug_network=arg.debug_network) + print(ini) |