Skip to content

Conversation

@gb0101010101
Copy link
Contributor

This is an initial effort to clean up the Actions/action.py file.

Goals

  • Remove massive if -> elif -> else code block from the top of the file that is difficult to understand.
  • Ensure that each JavaScript action('command') has a corresponding Action class method in python.
  • Centralize Action logic into each Action class method. There basically should only be need fo socketio to request execution from JavaScript, trigger the server side python Action, and maybe return a response back to JavaScript.
  • Standardize Actions to return True/False and handle errors and exceptions in a consistent manner.

Major Changes

The main change is the introduction on Actions.processAction(). This method takes the Dictionary message from JavaScript, extracts the first argument as the command[method] and passes all other arguments to the python method. It checks if the method exists, raising exception if not, and checks if the command is safe to execute during gcode file upload using _safe_commands Python List.

Subsequent Commits

The rest of the major changes consist of defining new Actions class methods, that previously did not exist, and mapped execution to other Classes. e.g.

optical_Calibrate(self, arg) executes opticalCalibration.on_Calibrate(arg)
These new methods follow existing JavaScipt action('method') naming and map to existing python class methods to minimize code change. They can certainly be renamed for greater legibility and to follow code standards.

Most of the subsequent commits were added during testing to optimize existing code.

  • A few bug fixes from new code.
  • Better Alert messages to inform user what went wrong.
  • Remove unused JavaScript functions replaced by Actions().
  • Make things work better: Like file naming of exports and backups to include dates.
  • Improve file selection in Imports to limit file types (mimetype)
  • Restore accidental deletion of pauseRun()! Doh - can't believe I never clicked the Pause button in testing until today!

Testing

  • All of the testing has been performed using FakeServo.
  • I cannot test on physical equipment as it is in shared remote space with susceptible Covid-19 user and will probably not be able to test in the coming months.
  • I have tested all Actions except calibration methods other that Triangular
  • All calibration methods were tested in limited manner to ensure that they executed existing code in other classes and returned valid responses.
  • Everything appears to be working: as well as it did before this code change.
  • It would be useful to get input from users that use Holey and Optical calibration methods to make sure they work.

Urgency

Because of the scope of this code change it can conflict with many other existing branches. I hopefully have worked out possibly branch changes with current Master. I have reviewed code changes from other users, on Master, and tried to merge code changes, to make this addition painless. Please let me know of conflicts that cannot be easily resolved so this change can be applied.

I hope this effort can be incorporated before it falls too far out of sync with Master.

…p code. Standardize exception handling. Format code.
…ve debugging print(), remove legacy commented code, send file as attachment to retain filename with datestamp.
…mplate to restrict selection of files. Make mimetype variable optional for backwards compatibility when not provided.
…n and does not delete existing log files. Add TODO comments to fix this later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants