mirror of
				https://github.com/dekuNukem/USB4VC.git
				synced 2025-10-24 11:20:50 -07:00 
			
		
		
		
	added new source code packing script, added internet update code
This commit is contained in:
		
							
								
								
									
										1
									
								
								push.sh
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								push.sh
									
									
									
									
									
								
							| @@ -9,6 +9,7 @@ find . -type f -name "*.l#*" -exec rm -f {} \; | ||||
| find . -type f -name "*.csv#*" -exec rm -f {} \; | ||||
| find . -type f -name "*.DS_Store*" -exec rm -f {} \; | ||||
| find . -name "__pycache__" -exec rm -rf {} \; | ||||
| rm -rfv ./user_program/rpi_app | ||||
|  | ||||
| git add --all | ||||
| git commit -m "$@" | ||||
|   | ||||
							
								
								
									
										17
									
								
								user_program/make_zip.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								user_program/make_zip.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| import usb4vc_shared | ||||
| import os | ||||
| import sys | ||||
| import time | ||||
|  | ||||
| os.system("rm -rfv ./rpi_app") | ||||
| os.system("sleep 0.1") | ||||
| os.system("rm -fv ./*.zip") | ||||
| os.system("sleep 0.1") | ||||
| os.system("mkdir rpi_app") | ||||
| os.system("sleep 0.1") | ||||
| os.system("cp -v ./*.py rpi_app/") | ||||
| os.system("cp -v ./*.ttf rpi_app/") | ||||
|  | ||||
| filename = f'usb4vc_src_{usb4vc_shared.RPI_APP_VERSION_TUPLE[0]}.{usb4vc_shared.RPI_APP_VERSION_TUPLE[1]}.{usb4vc_shared.RPI_APP_VERSION_TUPLE[2]}.zip' | ||||
| os.system(f"7z a {filename} rpi_app") | ||||
| print(filename) | ||||
| @@ -3,6 +3,8 @@ | ||||
| # sh sync.sh; ssh -t pi@169.254.194.124 "pkill python3;cd ~/usb4vc/rpi_app;python3 usb4vc_main.py" | ||||
|  | ||||
| scp ./* pi@169.254.194.124:~/usb4vc/rpi_app | ||||
| ssh -t pi@169.254.194.124 "pkill python3;cd ~/usb4vc/rpi_app;python3 usb4vc_main.py" | ||||
| # ssh -t pi@169.254.194.124 "pkill python3;cd ~/usb4vc/rpi_app;python3 usb4vc_main.py" | ||||
| # ssh -t pi@169.254.194.124 "pkill python3;cd ~/usb4vc/rpi_app;python3 usb4vc_check_update.py" | ||||
|  | ||||
| # ssh -t pi@169.254.194.124 "pkill python3;cd ~/usb4vc/rpi_app;python3 firmware_flasher.py /home/pi/usb4vc/firmware/PBFW_IBMPC_PBID1_V0_1_5.hex" | ||||
| # ssh -t pi@169.254.194.124 "pkill python3;cd ~/usb4vc/rpi_app;python3 bb_tester.py" | ||||
							
								
								
									
										102
									
								
								user_program/usb4vc_check_update.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								user_program/usb4vc_check_update.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,102 @@ | ||||
| import os | ||||
| import time | ||||
| import json | ||||
| import socket | ||||
| import urllib.request | ||||
| import requests | ||||
| import zipfile | ||||
| import shutil | ||||
|  | ||||
| from usb4vc_shared import RPI_APP_VERSION_TUPLE | ||||
| from usb4vc_shared import this_app_dir_path | ||||
| from usb4vc_shared import config_dir_path | ||||
| from usb4vc_shared import firmware_dir_path | ||||
| from usb4vc_shared import temp_dir_path | ||||
| from usb4vc_shared import ensure_dir | ||||
|  | ||||
| usb4vc_release_url = "https://api.github.com/repos/dekuNukem/usb4vc/releases/latest" | ||||
|  | ||||
| def is_internet_available(): | ||||
|     try: | ||||
|         socket.create_connection(("www.google.com", 80), timeout=1) | ||||
|         return True | ||||
|     except OSError: | ||||
|         pass | ||||
|     return False | ||||
|  | ||||
| def versiontuple(v): | ||||
|     return tuple(map(int, (v.strip('v').split(".")))) | ||||
|  | ||||
| def get_remote_tag_version(): | ||||
|     try: | ||||
|         if is_internet_available() is False: | ||||
|             return 1, 'Internet Unavailable' | ||||
|         result_dict = json.loads(urllib.request.urlopen(usb4vc_release_url).read()) | ||||
|         return 0, versiontuple(result_dict['tag_name']) | ||||
|     except Exception as e: | ||||
|         return 2, f'exception: {e}' | ||||
|     return 3, 'Unknown' | ||||
|  | ||||
| """ | ||||
| 0 success | ||||
| >0 fail | ||||
| """ | ||||
| def download_latest_usb4vc_release(save_path): | ||||
|     try: | ||||
|         if is_internet_available() is False: | ||||
|             return 1, 'Internet Unavailable' | ||||
|         result_dict = json.loads(urllib.request.urlopen(usb4vc_release_url).read()) | ||||
|         header = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',} | ||||
|         for item in result_dict['assets']: | ||||
|             if item['name'].lower().startswith('usb4vc_src') and item['name'].lower().endswith('.zip'): | ||||
|                 zip_path = os.path.join(save_path, item['name']) | ||||
|                 with open(zip_path, 'wb') as out_file: | ||||
|                     content = requests.get(item['browser_download_url'], headers=header, timeout=5).content | ||||
|                     out_file.write(content) | ||||
|                 return 0, zip_path | ||||
|         return 2, 'No Update Found' | ||||
|     except Exception as e: | ||||
|         return 3, f'exception: {e}' | ||||
|     return 4, 'Unknown' | ||||
|  | ||||
| def unzip_file(zip_path, extract_path): | ||||
|     try: | ||||
|         with zipfile.ZipFile(zip_path, 'r') as zip_ref: | ||||
|             zip_ref.extractall(extract_path) | ||||
|     except Exception as e: | ||||
|         return 5, str(e)  | ||||
|     return 0, 'Success!' | ||||
|  | ||||
| def get_usb4vc_update(temp_path): | ||||
|     os.system(f'rm -rfv {os.path.join(temp_path, "*")}') | ||||
|     time.sleep(0.1) | ||||
|     rcode, msg = download_latest_usb4vc_release(temp_path) | ||||
|     if rcode != 0: | ||||
|         return rcode, msg | ||||
|     rcode, msg = unzip_file(msg, temp_path) | ||||
|     return rcode, msg | ||||
|  | ||||
| def update(temp_path): | ||||
|     rcode, item = get_remote_tag_version() | ||||
|     if rcode != 0: | ||||
|         return 1, "Unknown error" | ||||
|     if item < RPI_APP_VERSION_TUPLE: | ||||
|         return 2, 'Local code is newer' | ||||
|     rcode, item = get_usb4vc_update(temp_path) | ||||
|     if rcode != 0: | ||||
|         return 3, 'Download failed' | ||||
|     try: | ||||
|         src_code_path = os.path.join(temp_path, 'rpi_app') | ||||
|         if len(os.listdir(src_code_path)) <= 5: | ||||
|             return 4, 'Too few files' | ||||
|     except Exception as e: | ||||
|         return 5, f'Unknown error: {e}' | ||||
|     os.system(f'rm -rfv {os.path.join(this_app_dir_path, "*")}') | ||||
|     os.system(f'cp -fv {os.path.join(src_code_path, "*")} {this_app_dir_path}') | ||||
|     return 0, 'Success' | ||||
|  | ||||
| # print(update(temp_dir_path)) | ||||
| # print(get_usb4vc_update(temp_dir_path)) | ||||
| # print(get_remote_tag_version() >= RPI_APP_VERSION_TUPLE) | ||||
| # print('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@') | ||||
| # print("ssssssssss", os.path.join(temp_dir_path, '*')) | ||||
| @@ -1,3 +1,15 @@ | ||||
| import os | ||||
|  | ||||
| this_app_dir_path = "/home/pi/usb4vc/rpi_app" | ||||
| config_dir_path = "/home/pi/usb4vc/config" | ||||
| firmware_dir_path = "/home/pi/usb4vc/firmware" | ||||
| temp_dir_path = "/home/pi/usb4vc/temp" | ||||
|  | ||||
| def ensure_dir(dir_path): | ||||
|     print('ensure_dir', dir_path) | ||||
|     if not os.path.exists(dir_path): | ||||
|         os.makedirs(dir_path) | ||||
|  | ||||
| RPI_APP_VERSION_TUPLE = (0, 0, 8) | ||||
|  | ||||
| code_name_to_value_lookup = { | ||||
|   | ||||
| @@ -10,23 +10,23 @@ import RPi.GPIO as GPIO | ||||
| import usb4vc_usb_scan | ||||
| import usb4vc_shared | ||||
| import usb4vc_show_ev | ||||
| import usb4vc_check_update | ||||
| import json | ||||
| import subprocess | ||||
| from subprocess import Popen, PIPE | ||||
|  | ||||
| this_app_dir_path = "/home/pi/usb4vc/rpi_app" | ||||
| config_dir_path = "/home/pi/usb4vc/config" | ||||
| firmware_dir_path = "/home/pi/usb4vc/firmware" | ||||
| config_file_path = os.path.join(config_dir_path, 'config.json') | ||||
| from usb4vc_shared import this_app_dir_path | ||||
| from usb4vc_shared import config_dir_path | ||||
| from usb4vc_shared import firmware_dir_path | ||||
| from usb4vc_shared import temp_dir_path | ||||
| from usb4vc_shared import ensure_dir | ||||
|  | ||||
| def ensure_dir(dir_path): | ||||
|     print('ensure_dir', dir_path) | ||||
|     if not os.path.exists(dir_path): | ||||
|         os.makedirs(dir_path) | ||||
| config_file_path = os.path.join(config_dir_path, 'config.json') | ||||
|  | ||||
| ensure_dir(this_app_dir_path) | ||||
| ensure_dir(config_dir_path) | ||||
| ensure_dir(firmware_dir_path) | ||||
| ensure_dir(temp_dir_path) | ||||
|  | ||||
| PLUS_BUTTON_PIN = 27 | ||||
| MINUS_BUTTON_PIN = 19 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user