We implemented a new feature for our PASSDORA Box. Passdora is a Raspberry Pi based system which hosts the Sequry password-manager.
New Features
What feature(s) did you add?
The Passdora-system requires multiple (Python-)scripts to run in the background. Those scripts listen to button presses on the Raspberry Pi's GPIO pins and show content on the display.
So far all scripts are run on system startup which requires a lot of entries in system files which are hard to manage and require a lot of effort to modify once something (e.g. a path) changes.
It also happens, since all the scripts run separately without a controlling instance, that they overwrite each other's content on the display.
To prevent that from happening and to have a script managing which scripts are run at which time, a central controlling instance is required. This instance should invoke the required scripts (on startup), allow the sharing of data/objects between them and control their display access.
Reasons
- central instance invoking required scripts required -> reduce amount of system startup entries
- control display access between all scripts
- allow data/object sharing and communication between scripts
- central management of everything happening in the background
How did you implement it/them?
The following architecture should allow a centralized management of the scripts:
Create an abstract class which inherits the threading. Thread class (so it can be run in the background) which is the base for all background scripts/classes:
Build_Image/files/passdora_scripts/lib/autostart/AbstractAutostart.pyMove all (background) scripts in their own classes: Build_Image/files/passdora_scripts/lib/autostart/BackupButtonListener.py, Build_Image/files/passdora_scripts/lib/autostart/ShowIP.py
Have all background scripts inherit that class [see 2.]
Implement the scripts background tasks in the overwritten run()-method [see 2.]
Create a central class that invokes all required classes and calls their run()-method to make them execute their required code in the background:
Build_Image/files/passdora_scripts/script_loader.py
The changes are included in the [ac4cf4a9] commit. For the sake of clarity, I have linked the individual file changes once again above.
Thanks for reading
Jan, for PCSG Developers
Posted on Utopian.io - Rewarding Open Source Contributors