Ankermgmt / ankermake-m5-protocol

Ankermake M5 protocol specifications and libraries *NOT AFFILIATED WITH ANKER*
GNU General Public License v3.0
164 stars 36 forks source link

Improve handling when missing config file #24

Closed spuder closed 1 year ago

spuder commented 1 year ago

Attempting to test the new pppp functionality to upload a gcode produces the following error

I'm 90% positive this error is because I didn't run ankerctl config show first (I don't see a default.json file present in ~/.config/**)

./ankerctl.py config show
[E] No printers configured. Run 'config import' to populate.

Solution

Catch missing config files and give a human readable instruction to run the config import first

 ./ankerctl.py pppp print-file --no-act /Users/spuder/3dprints/ender2pro/predynasticvase_1d1h24m_0.08mm_245C_PETG_ENDER2PRO.gcode
Traceback (most recent call last):
  File "/Users/spuder/Code/github/Ankermgmt/ankermake-m5-protocol/./ankerctl.py", line 369, in <module>
    main()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/spuder/Code/github/Ankermgmt/ankermake-m5-protocol/./ankerctl.py", line 212, in pppp_print_file
    api = cli.pppp.pppp_open(env)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/spuder/Code/github/Ankermgmt/ankermake-m5-protocol/cli/pppp.py", line 11, in pppp_open
    printer = cfg.printers[0]
              ^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'printers'
chrivers commented 1 year ago

Hm, "config show" was just a suggestion for testing config.

In fact, all commands go through a new check upgrade_config_if_needed(), which checks for outdated configs.

The problem with trying to bail on missing config, is that at least one command ("config import") needs to be able to run without config :)

I'll ponder it a bit, and find a solution