Browse Source

更新 'backup/preset/app/checkout.py'

junhuanchen 1 year ago
parent
commit
070b89c156
1 changed files with 26 additions and 23 deletions
  1. 26 23
      backup/preset/app/checkout.py

+ 26 - 23
backup/preset/app/checkout.py

@@ -1,34 +1,37 @@
-from dulwich import porcelain
-from dulwich import repo
+import git
 import os
+from io import RawIOBase
 
-
-def ro():
-    os.system("/etc/init.d/S01mount_ro start")
+localrep = "/home"
 
 
-def rw():
-    os.system("/etc/init.d/S01mount_ro stop")
+class NewStream(RawIOBase):
+    """Fallback if stdout or stderr are unavailable, does nothing."""
 
+    def read(self, size=-1):
+        return None
 
-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)
+    def readall(self):
+        return None
 
+    def readinto(self, b):
+        return None
 
-localrep = "/home"
+    def write(self, b):
+        print(b)
+        return None
 
 
-rw()
-if porcelain.active_branch(localrep) != b'master':
-    checkout(localrep, 'master')
+git.rw()
+steam = NewStream()
+if os.path.exists(localrep + "/cclb_launch"):
+    os.remove(localrep + "/cclb_launch")
+if git.activeBranch(localrep) != b'master':
+    git.checkout(localrep, 'master', steam)
 else:
-    checkout(localrep, 'en')
-os.remove("/root/CocoPi.py")
-ro()
-os.system('reboot')
+    git.checkout(localrep, 'en', steam)
+if os.path.exists("/root/CocoPi.py"):
+    os.remove("/root/CocoPi.py")
+os.system('chmod -R 777 /home')
+os.system('reboot')
+git.ro()