Ver Fonte

CurrentPathUpdate

rita há 2 anos atrás
pai
commit
2714cbb2ba
1 ficheiros alterados com 15 adições e 58 exclusões
  1. 15 58
      manage.py

+ 15 - 58
manage.py

@@ -384,56 +384,17 @@ def ABS_update():
 def add_server_views():
     username = session['uname']
     L = []
-    if request.method == 'GET':
-        # # ============================================================================================
-        # # # # 232 路徑
-        # # Users = os.popen("getent passwd 1000 | cut -d: -f1")
-        # # UserFile = Users.read().strip()
-        # # print("UserFile:", UserFile)
-
-        # # os.system('git clone -b sh --single-branch http://60.250.156.230:3000/Automatic_build_system/Automatically_install_files.git /home/' + UserFile + '/BBend-Test-JWT/newSH')
-        # # with open('/home/' + UserFile + '/BBend-Test-JWT/newSH/coffeesystem.sh', encoding='utf-8') as f:
-        # #     D['command'] = f.read().split('\n')
-        # # sl(3)
-        # # shutil.rmtree('/home/' + UserFile + '/BBend-Test-JWT/newSH', onerror=remove_readonly)
-        # # with open('/home/' + UserFile + '/BBend-Test-JWT/Item.txt') as f:
-        # #     D['item_name'] = f.read().split('\n')
-        # #     for item in D['item_name']:
-        # #         L.append('.'.join(item.split('.')[1:]))         # 拿掉 '.'.join 的話會變成 [['python3', '8'], ['python3-pip'],
+    CURRENT_PATH = os.path.dirname(__file__)
+    print("CURRENT_PATH: ", CURRENT_PATH)
     
-        # # ============================================================================================
-        # # # 本機 路徑
-        # os.system('git clone -b sh --single-branch http://60.250.156.230:3000/Automatic_build_system/Automatically_install_files.git C:/Users/USER/Rita/operating/sixthproject/BBend-Test-JWT/newSH')
-        # with open('C:/Users/USER/Rita/operating/sixthproject/BBend-Test-JWT/newSH/coffeesystem.sh', encoding='utf-8') as f:
-        #     D['command'] = f.read().split('\n')
-        # # print("D['command']: ", D['command'])
-        # sl(3)
-        # shutil.rmtree('C:/Users/USER/Rita/operating/sixthproject/BBend-Test-JWT/newSH', onerror=remove_readonly)
-        # with open('C:/Users/USER/Rita/operating/sixthproject/BBend-Test-JWT/Item.txt') as f:
-        #     D['item_name'] = f.read().split('\n')
-        #     for item in D['item_name']:
-        #         # L.append('.'.join(item.split('.')[1:]))         # 拿掉 '.'.join 的話會變成 [['python3', '8'], ['python3-pip'],
-        #         L.append(item)
-        current_path = os.path.dirname(__file__)
-        # print("current_path: ", current_path)
-        with open(current_path + '/Item.txt') as f:
+    if request.method == 'GET':
+        with open(CURRENT_PATH + '/Item.txt') as f:
             D['item_name'] = f.read().split('\n')
             for item in D['item_name']:
                 # L.append('.'.join(item.split('.')[1:]))         # 拿掉 '.'.join 的話會變成 [['python3', '8'], ['python3-pip'],
                 L.append(item)
-        # # # ============================================================================================
-
-        # sl(3)
-        # L2= []
-        # for i in range(0, len(D['command'])):
-        #     if D['command'][i] == "'" or D['command'][i] == '' or "#" in D['command'][i] or D['command'][i] == ' ':
-        #         continue
-        #     L2.append(D['command'][i])
-        # D['command'] = L2
-
-        # # # ===========================================================================================================
 
-        STATUS = session['status']
+        # STATUS = session['status']
         return render_template('add_server.html', params=locals())
     else:
         item_install_fail = 0
@@ -468,7 +429,7 @@ def add_server_views():
             # 假如帳號密碼正確沒有被捕捉到異常,傳送訊息給前端
             # socketio.emit('user-confirm', 'pass', namespace='/test_conn')
 
-            with open('../ItemFile.csv', 'w', newline='') as csvFile:
+            with open(CURRENT_PATH + '/ItemFile.csv', 'w', newline='') as csvFile:
                 csvWriter = csv.writer(csvFile)
                 csvWriter.writerow(['Command', 'Install Content', 'Time', 'Status'])
             
@@ -477,12 +438,12 @@ def add_server_views():
                 if eval("item" + str(item_num)) == 'true':
                     print('========== item ' + str(item_num) + ' install ====================================')
                     # 下載資料夾
-                    os.system('git clone -b item' + str(item_num) + ' --single-branch http://60.250.156.230:3000/Automatic_build_system/Automatically_install_files.git C:/Users/USER/Rita/operating/sixthproject/BBend-Test-JWT/item' + str(item_num) + '')
-                    with open('C:/Users/USER/Rita/operating/sixthproject/BBend-Test-JWT/item' + str(item_num) + '/item' + str(item_num) + '.sh', encoding='utf-8') as f:
+                    os.system('git clone -b item' + str(item_num) + ' --single-branch http://60.250.156.230:3000/Automatic_build_system/Automatically_install_files.git ' + CURRENT_PATH + '/item' + str(item_num) + '')
+                    with open( CURRENT_PATH + '/item' + str(item_num) + '/item' + str(item_num) + '.sh', encoding='utf-8') as f:
                         D['command'] = f.read().split('\n')
                     sl(1)
                     # 刪除下載資料夾
-                    shutil.rmtree('C:/Users/USER/Rita/operating/sixthproject/BBend-Test-JWT/item' + str(item_num) + '', onerror=remove_readonly)
+                    shutil.rmtree( CURRENT_PATH + '/item' + str(item_num) + '', onerror=remove_readonly)
                     
                     # 移除不需要執行之指令
                     sl(1)
@@ -544,7 +505,7 @@ def add_server_views():
                                         pass
                             if for_error_command_list == [''] or for_error_command_list == []:
                                 print('=== Warning ===')
-                                with open('../ItemFile.csv', 'a', newline='') as csvFile:
+                                with open(CURRENT_PATH + '/ItemFile.csv', 'a', newline='') as csvFile:
                                     csvWriter = csv.writer(csvFile)
                                     csvWriter.writerow([command.replace(';', ';\n'), 
                                                         'success: \n' + success + '\n' + 'error: \n' + error, 
@@ -560,7 +521,7 @@ def add_server_views():
 
                                 if item_install_fail == 0:
                                     item_install_fail = 1
-                                with open('../ItemFile.csv', 'a', newline='') as csvFile:
+                                with open(CURRENT_PATH + '/ItemFile.csv', 'a', newline='') as csvFile:
                                     csvWriter = csv.writer(csvFile)
                                     csvWriter.writerow([command.replace(';', ';\n'), 
                                                         'success: \n' + success + '\n' + 'error: \n' + error, 
@@ -573,7 +534,7 @@ def add_server_views():
                         else:
                             print('=== success ===')
 
-                            with open('../ItemFile.csv', 'a', newline='') as csvFile:
+                            with open(CURRENT_PATH + '/ItemFile.csv', 'a', newline='') as csvFile:
                                 csvWriter = csv.writer(csvFile)
                                 csvWriter.writerow([command.replace(';', ';\n'), 
                                                     'success: \n' + success + '\nerror: \n' + error, 
@@ -586,16 +547,12 @@ def add_server_views():
                         
                         sl(5)     # Rita 原本為 sl(6) 增加後觀察是否 clone 輸出會改變
                         print('-----------------------------------------------------------------------------')
-            # os.system('sudo reboot')
-            # os.system('sudo systemctl restart rc.local.service')
             
-            stdin, stdout, stderr = ssh.exec_command("sudo systemctl restart rc-local.service")
+            # stdin, stdout, stderr = ssh.exec_command("sudo systemctl restart rc-local.service")
             sl(5)
-            stdin, stdout, stderr = ssh.exec_command("sudo reboot")
+            # stdin, stdout, stderr = ssh.exec_command("sudo reboot")
 
-            # print("Automatic_Build_System: ")
-            # print(Automatic_Build_System)
-            with open('../ItemFile.csv', 'a', newline='') as csvFile:
+            with open( CURRENT_PATH + '/ItemFile.csv', 'a', newline='') as csvFile:
                 csvWriter = csv.writer(csvFile)
                 csvWriter.writerow(['',
                                     'Automatic_Build_System: \n' + str(Automatic_Build_System),