RMaixtr 1 ano atrás
pai
commit
739c5f9471
3 arquivos alterados com 105 adições e 0 exclusões
  1. 5 0
      backup/main.py
  2. 57 0
      backup/preset/app/checkout.py
  3. 43 0
      backup/preset/app/pull.py

+ 5 - 0
backup/main.py

@@ -278,6 +278,8 @@ demoListText=(
     "环境监测",
     "模型训练:数据集采集",
     "模型训练:模型部署",
+    "checkout",
+    "pull",
 
 )
 demoNameList=(
@@ -312,6 +314,9 @@ demoNameList=(
     "29_environmentDetection",
     "30_train_data_collect",
     "31_train_deploy_model",
+    "checkout",
+    "pull",
+
 )
 demoNum=len(demoListText)
 pageSig=1

+ 57 - 0
backup/preset/app/checkout.py

@@ -0,0 +1,57 @@
+from dulwich import porcelain
+from dulwich import repo
+import os
+
+
+def is_file_locked(file_path):
+    try:
+        with open(file_path, 'r'):
+            return False
+    except IOError:
+        return True
+
+
+def close_file(file_object):
+    file_object.close()
+
+
+def release_file_resource(file_path):
+    file_descriptor = os.open(file_path, os.O_RDONLY)
+    os.close(file_descriptor)
+
+
+def unlock_file(file_path):
+    if is_file_locked(file_path):
+        with open(file_path, 'r') as file:
+            close_file(file)
+        release_file_resource(file_path)
+
+
+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:
+        print("Error")
+        porcelain.reset(r, 'hard')
+        porcelain.checkout_branch(r, 'origin/' + branch)
+
+
+localrep = "/home/"
+unlockfile = localrep + "cclb_launch"
+
+rw()
+unlock_file(unlockfile)
+if porcelain.active_branch(localrep) != b'master':
+    checkout(localrep, 'master')
+else:
+    checkout(localrep, 'en')
+ro()

+ 43 - 0
backup/preset/app/pull.py

@@ -0,0 +1,43 @@
+from dulwich import porcelain
+import os
+
+
+def is_file_locked(file_path):
+    try:
+        with open(file_path, 'r'):
+            return False
+    except IOError:
+        return True
+
+
+def close_file(file_object):
+    file_object.close()
+
+
+def release_file_resource(file_path):
+    file_descriptor = os.open(file_path, os.O_RDONLY)
+    os.close(file_descriptor)
+
+
+def unlock_file(file_path):
+    if is_file_locked(file_path):
+        with open(file_path, 'r') as file:
+            close_file(file)
+        release_file_resource(file_path)
+
+
+def ro():
+    os.system("/etc/init.d/S01mount_ro start")
+
+
+def rw():
+    os.system("/etc/init.d/S01mount_ro stop")
+
+
+localrep = "/home/"
+unlockfile = localrep + "cclb_launch"
+
+rw()
+unlock_file(unlockfile)
+porcelain.pull('.')
+ro()