eclipse-kuksa / kuksa.val.feeders

kuksa.val.feeders
Apache License 2.0
8 stars 22 forks source link

Fix server_type handling #144

Closed erikbosch closed 1 year ago

erikbosch commented 1 year ago

Previously you would get an error whatever you specified. This change behavior to expect lower case name:

I.e. you should call:

erik@debian3:~/kuksa.val.feeders/dbc2val$ ./dbcfeeder.py --server-type kuksa_databroker
2023-09-19 12:58:13,256 INFO dbcfeeder: Reading configuration from file: config/dbc_feeder.ini
2023-09-19 12:58:13,257 INFO dbcfeeder: DBC2VAL mode is: True
2023-09-19 12:58:13,257 INFO dbcfeeder: VAL2DBC mode is: False
...

If you try uppercase you get an error:

erik@debian3:~/kuksa.val.feeders/dbc2val$ ./dbcfeeder.py --server-type KUKSA_DATABROKER
usage: dbcfeeder.py [-h] [--config FILE] [--dbcfile FILE] [--dumpfile FILE] [--canport DEVICE] [--use-j1939] [--use-socketcan] [--mapping FILE] [--dbc-default FILE] [--server-type {kuksa_val_server,kuksa_databroker}] [--lax-dbc-parsing]
                    [--dbc2val] [--no-dbc2val] [--val2dbc] [--no-val2dbc]
dbcfeeder.py: error: argument --server-type: invalid choice: 'KUKSA_DATABROKER' (choose from 'kuksa_val_server', 'kuksa_databroker')

How it worked before this PR

You were doomed if you used kuksa_databroker

erik@debian3:~/kuksa.val.feeders/dbc2val$ ./dbcfeeder.py --server-type kuksa_databroker
usage: dbcfeeder.py [-h] [--config FILE] [--dbcfile FILE] [--dumpfile FILE] [--canport DEVICE] [--use-j1939] [--use-socketcan] [--mapping FILE] [--dbc-default FILE] [--server-type {KUKSA_VAL_SERVER,KUKSA_DATABROKER}] [--lax-dbc-parsing]
                    [--dbc2val] [--no-dbc2val] [--val2dbc] [--no-val2dbc]
dbcfeeder.py: error: argument --server-type: invalid choice: 'kuksa_databroker' (choose from 'KUKSA_VAL_SERVER', 'KUKSA_DATABROKER')

You were also doomed if you used KUKSA_DATABROKER

erik@debian3:~/kuksa.val.feeders/dbc2val$ ./dbcfeeder.py --server-type KUKSA_DATABROKER
2023-09-19 12:56:22,045 INFO dbcfeeder: Reading configuration from file: config/dbc_feeder.ini
2023-09-19 12:56:22,046 INFO dbcfeeder: DBC2VAL mode is: True
2023-09-19 12:56:22,046 INFO dbcfeeder: VAL2DBC mode is: False
Traceback (most recent call last):
  File "/home/erik/kuksa.val.feeders/dbc2val/./dbcfeeder.py", line 703, in <module>
    sys.exit(main(sys.argv))
  File "/home/erik/kuksa.val.feeders/dbc2val/./dbcfeeder.py", line 608, in main
    kuksa_val_client = _get_kuksa_val_client(args, config)
  File "/home/erik/kuksa.val.feeders/dbc2val/./dbcfeeder.py", line 407, in _get_kuksa_val_client
    server_type = ServerType(server_type_name)
  File "/usr/local/lib/python3.10/enum.py", line 385, in __call__
    return cls.__new__(cls, value)
  File "/usr/local/lib/python3.10/enum.py", line 710, in __new__
    raise ve_exc
ValueError: 'KUKSA_DATABROKER' is not a valid ServerType
erikbosch commented 1 year ago

FYI: @sophokles73 @SebastianSchildt

I believe it looks better to request lower case name as argument. I also added some basic tests. Lower case names is also what is used in the README.md file

erikbosch commented 1 year ago

Candidate for v0.4.1 - can you review @SebastianSchildt @lukasmittag