# coding: utf-8 import os import shutil import requests from tkinter import * HOST_URL = 'http://localhost/pi/' if os.path.exists('/home/pi/Desktop/dev.update') else 'http://www-ict.dent.agu.ac.jp/pi/' MANAGER = 'manager.py' TARGET_DIR = "/home/pi/agud-pi" def update(newest_version): os.system('rm -f ' + TARGET_DIR + '/' + MANAGER) res = requests.get(HOST_URL + MANAGER, timeout=1, stream=True) if res.status_code == 200: with open(TARGET_DIR + '/' + MANAGER, 'wb') as file: res.raw.decode_content = True shutil.copyfileobj(res.raw, file) cmd = 'python3 ' + TARGET_DIR + '/' + MANAGER + ' ' + HOST_URL + ' ' + newest_version os.system('lxterminal -e ' + cmd) else: pass if not os.path.isdir(TARGET_DIR): os.makedirs(TARGET_DIR) try: res = requests.get(HOST_URL + 'newest_version.txt', timeout=0.5) if res.status_code == 200: newest_version = res.text update(newest_version) else: pass except: root = Tk() root.title('エラー') text = Text(root, width=60, height=6) text.insert(END, 'エラーが発生しました。\n接続先:' + HOST_URL + '\n') text.pack() root.mainloop()