from dulwich import porcelain from dulwich import repo import os def ro(): os.system("/etc/init.d/S01mount_ro start") def rw(): os.system("/etc/init.d/S01mount_ro stop") def checkout(rep, branch): r = repo.Repo(rep) try: porcelain.checkout_branch(r, 'origin/' + branch) except porcelain.CheckoutError as e: print("CheckoutError:", e) porcelain.reset(r, 'hard') porcelain.checkout_branch(r, 'origin/' + branch) localrep = "/home" rw() if porcelain.active_branch(localrep) != b'master': checkout(localrep, 'master') else: checkout(localrep, 'en') os.remove("/root/CocoPi.py") ro() os.system('reboot')