Skip to content

A little Python3 project which allows you to update a python program without needing to rerun it.

Notifications You must be signed in to change notification settings

BKG-Robocon-team/IOT24_PyOTA

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Over-The-Air Update

This is a little Python3 project which allows you to update a python program without needing to rerun it. You can take a look at the example folder of this repository in order to understand how this script works.

Requirements

The only file you need in order to use this update system for python project is the ota-update.py. Keep in mind that in the directory where this script will be executed, files and folders will be created. I recommend executing this script inside an empty directory which will be used only for your python project.

It requires the PrintBetter python package in order to work.

File architecture

The typical directory tree of a python project using the ota-update.py script should look like this:

.
├── deposit
├── logs
│   ├── logfile_DD-MM-YY_HH.MM.SS.log
│   └── ...
├── main
│   ├── main.py
│   └── ...
├── ota-update.py
  • The deposit folder is the place where you can put files from your python project. It can be assets, files or folders. The files inside the main folder will be replaced by the new ones inside the deposit folder once/if the ota-update.py script is running. The file structure inside the deposit folder will be replicated inside the main folder. You should only place new files inside the deposit folder as opposed to placing your whole python project every time: nothing is automatically deleted from the main directory, files that are found inside the deposit folder will be added to the main folder or will replace the old ones.
  • The main folder is where your python project is. The ota-update.py script will automatically execute the main.py file inside it.
  • The logs folder is the place where you will find the logs generated by the PrintBetter python package used by the ota-update.py script.

Be careful

You need to run the ota-update.py script directly from its parent directory!

For example:

cd users/gruvw/python-ota-update/example
python ota-update.py

First execution

If there is no deposit or main folder in the same directory of the ota-update.py, the first execution of the script will create both of them (along with the logs folder). It will then trow a "No main.py inside the main directory." exception which is totally normal because the main directory has just been created so there is no main.py file inside it yet. You can now place your python project files inside the freshly created deposit folder and run the ota-update.py script again. This will move your whole python project from the deposit to the main folder.

How to use

Once you have your working python project inside the main folder (see First execution), you may run the ota-update.py script which will execute the main.py inside the main folder. You can now put new files and/or folders inside the deposit folder while the script is running. The main.py will automatically stop and the new files will be moved from the deposit to the main folder. The main.py script will then start again automatically.

  1. You should not put anything inside the main folder by yourself, but rather put them inside the deposit folder and run the ota-update.py
  2. You can delete files from the main folder if you need to, but you should not do so while the ota-update.py is still running
  3. You need to have a main.py script inside the main folder in order to use the ota-update.py script properly
  4. You can update any file that you want with the script, even the main.py script. Just put it inside the deposit folder
  5. If you put some files inside the deposit folder while the ota-update.py script is not running, the files will be moved to the main folder when you will run the script

Why I created this

I created this file architecture/python script because I used to have to update a python script to a Raspberry Pi via FTP. I always needed to connect to the Raspberry Pi via VNC or SSH in order to:

  1. Stop the currently running python script
  2. Delete the old version of the python file
  3. Run the new script that I just uploaded

Now, with this solution, I only need to run the ota-update.py script once (or even auto-run at startup) and if I need to update my script or anything about my python project, I just transfer the files inside the deposit folder via FTP. My script will start again automatically after the update.

Issues / Pull requests

Fill free to open an issue if anything is not working for you. Pull requests are also welcome if you think about a feature, I would be happy to take a look at your code.

About

A little Python3 project which allows you to update a python program without needing to rerun it.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%