kbr / fritzconnection

Python-Tool to communicate with the AVM Fritz!Box by the TR-064 protocol and the AHA-HTTP-Interface
MIT License
303 stars 59 forks source link

Provide a self-contained CLI archive #151

Open samba2 opened 2 years ago

samba2 commented 2 years ago

Disclaimer: This is more of a feature request/ product vision then a concrete action.

The fritzconnection project does a great job to provide a simple API to Fritzboxes as well as some CLI tools. I think it would be a good way forward to simplify the usage of the project as a CLI since this lowers the usage barriers.

Currently users are required to have Python environment available in which they call pip install .... In contrast, to just execute the CLI functionality, core Python comes with the zipapp package. My suggestion is to provide the user with a a self contained Python archive which just needs a recent Python interpreter to execute. To execute an imaginary fritzconnection CLI a user might just call python fritzconnection.pyz. This self-contained approach is very similar to Java fat jars which execute like java -jar myapp.jar.

The platform independent packaging via zipapp already seems to work. Here is what I did on my Windows 11 machine inside WSL 2:

# building
$ pip install . --target /tmp/myapp
$  python3 -m zipapp  -o /mnt/c/temp/app.pyz -m "fritzconnection.cli.fritzinspection:main" /tmp/myapp

# executing
$ python3 /mnt/c/temp/app.pyz  --help

This worked straight away. Also setting the password via ENV variable and running python3 /mnt/c/temp/app.pyz -i 192.168.178.1 worked. Additionally I ran the same app.pyz in the Windows 11 context and it also worked without any modifications. So the chances are quite high that the produced app archive is truly platform independent and also works e.g. on Macs.

So in my eyes there is only little to do to provide a zipapp which is platform agnostic and can be much simpler used - just download the file and execute (Python3 provided). What is left to do here would be the CI setup to build + release the app archive.

Which brings me to the next improvement. Currently, fritzconnection comes with a bunch of simple CLI tools which can be found inside the cli directory. For a zipapp a single entry point/ CLI command would be needed. To differentiate the functionalities the CLI would work with subcommands like python fritzconnection.pyz phonebook or python fritzconnection.pyz status. For this task a dedicated framework like click is probably a good choice (the functionality of plain argparse is limited)

An inspiration could be the meanwhile archived fritzctl project: https://github.com/bpicode/fritzctl