|
@@ -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()
|