|
@@ -1,4 +1,5 @@
|
|
#啟動和管理項目
|
|
#啟動和管理項目
|
|
|
|
+from distutils.log import error
|
|
from encodings import utf_8
|
|
from encodings import utf_8
|
|
from multiprocessing import Value
|
|
from multiprocessing import Value
|
|
from app import create_app
|
|
from app import create_app
|
|
@@ -355,8 +356,6 @@ Automatic_Build_System = {
|
|
'build-essential': '0',
|
|
'build-essential': '0',
|
|
'tasksel': '0',
|
|
'tasksel': '0',
|
|
'lamp-server': '0',
|
|
'lamp-server': '0',
|
|
- 'tasksel': '0',
|
|
|
|
- 'lamp-server': '0',
|
|
|
|
'phpMyAdmin-5.1.0-all-languages.tar.gz': '0',
|
|
'phpMyAdmin-5.1.0-all-languages.tar.gz': '0',
|
|
'openssl': '0',
|
|
'openssl': '0',
|
|
'php-common': '0',
|
|
'php-common': '0',
|
|
@@ -376,8 +375,6 @@ Automatic_Build_System = {
|
|
'apache2': '0',
|
|
'apache2': '0',
|
|
'paho-mqtt': '0',
|
|
'paho-mqtt': '0',
|
|
'mosquitto': '0',
|
|
'mosquitto': '0',
|
|
- 'paho-mqtt': '0',
|
|
|
|
- 'mosquitto': '0',
|
|
|
|
'mqtt_server_setting': '0',
|
|
'mqtt_server_setting': '0',
|
|
'rclocal/rc.local': '0',
|
|
'rclocal/rc.local': '0',
|
|
'golang': '0',
|
|
'golang': '0',
|
|
@@ -390,7 +387,6 @@ Automatic_Build_System = {
|
|
'ntpdate': '0',
|
|
'ntpdate': '0',
|
|
'--keyserver': '0',
|
|
'--keyserver': '0',
|
|
'update': '0',
|
|
'update': '0',
|
|
- 'upgrade': '0',
|
|
|
|
'ros-melodic-desktop-full': '0',
|
|
'ros-melodic-desktop-full': '0',
|
|
'ros-melodic-rqt*': '0',
|
|
'ros-melodic-rqt*': '0',
|
|
'python-rosdep': '0',
|
|
'python-rosdep': '0',
|
|
@@ -410,28 +406,34 @@ def add_server_views():
|
|
username = session['uname']
|
|
username = session['uname']
|
|
L = []
|
|
L = []
|
|
if request.method == 'GET':
|
|
if request.method == 'GET':
|
|
- # # # 232 路徑
|
|
|
|
- os.system('git clone -b sh --single-branch http://60.250.156.230:3000/Automatic_build_system/Automatically_install_files.git /home/gs1802/BBend-Test-JWT/newSH')
|
|
|
|
- with open('/home/gs1802/BBend-Test-JWT/newSH/coffeesystem.sh', encoding='utf-8') as f:
|
|
|
|
- D['command'] = f.read().split('\n')
|
|
|
|
- sl(3)
|
|
|
|
- shutil.rmtree('/home/gs1802/BBend-Test-JWT/newSH', onerror=remove_readonly)
|
|
|
|
- with open('/home/gs1802/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'],
|
|
|
|
# ============================================================================================
|
|
# ============================================================================================
|
|
- # # # 本機 路徑
|
|
|
|
- # 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:
|
|
|
|
|
|
+ # # 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')
|
|
# D['command'] = f.read().split('\n')
|
|
- # # print("D['command']: ", D['command'])
|
|
|
|
# sl(3)
|
|
# sl(3)
|
|
- # shutil.rmtree('newSH', onerror=remove_readonly)
|
|
|
|
- # with open('Item.txt') as f:
|
|
|
|
|
|
+ # 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')
|
|
# D['item_name'] = f.read().split('\n')
|
|
# for item in D['item_name']:
|
|
# for item in D['item_name']:
|
|
# L.append('.'.join(item.split('.')[1:])) # 拿掉 '.'.join 的話會變成 [['python3', '8'], ['python3-pip'],
|
|
# L.append('.'.join(item.split('.')[1:])) # 拿掉 '.'.join 的話會變成 [['python3', '8'], ['python3-pip'],
|
|
|
|
+
|
|
|
|
+ # ============================================================================================
|
|
|
|
+ # # # 本機 路徑
|
|
|
|
+ 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('newSH', onerror=remove_readonly)
|
|
|
|
+ with open('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'],
|
|
# # ============================================================================================
|
|
# # ============================================================================================
|
|
|
|
|
|
sl(3)
|
|
sl(3)
|
|
@@ -479,12 +481,13 @@ def add_server_views():
|
|
csvWriter = csv.writer(csvFile)
|
|
csvWriter = csv.writer(csvFile)
|
|
csvWriter.writerow(['Command', 'Install Content', 'Time', 'Status'])
|
|
csvWriter.writerow(['Command', 'Install Content', 'Time', 'Status'])
|
|
|
|
|
|
- # # # # Rita TEST
|
|
|
|
|
|
+ # # # Rita TEST
|
|
# D['command'] = [
|
|
# D['command'] = [
|
|
- # # 'sudo pip3 install cryptography==3.3.2',
|
|
|
|
- # 'sudo apt-key adv --keyserver "hkp://keyserver.ubuntu.com:80" --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654',
|
|
|
|
- # # 'cd /home/gs1802;pwd;sudo git clone http://60.250.156.230:3000/Automatic_build_system/Coffee_MySQL.git /home/gs1802/Coffee_MySQL/',
|
|
|
|
- # # 'rosdep update'
|
|
|
|
|
|
+ # "sudo apt-get install tasksel -y",
|
|
|
|
+ # "sudo DEBIAN_FRONTEND=noninteractive tasksel install lamp-server",
|
|
|
|
+ # "sudo -H pip3 install paho-mqtt",
|
|
|
|
+ # "sudo apt-get install mosquitto -y",
|
|
|
|
+
|
|
# ]
|
|
# ]
|
|
|
|
|
|
for command in D['command']:
|
|
for command in D['command']:
|
|
@@ -498,7 +501,6 @@ def add_server_views():
|
|
if key in command and value == '0':
|
|
if key in command and value == '0':
|
|
print('key: ', key, ' / command: ', command)
|
|
print('key: ', key, ' / command: ', command)
|
|
Automatic_Build_System[key] = "Install"
|
|
Automatic_Build_System[key] = "Install"
|
|
- # sl(1) # Rita 原本為 sl(6) 增加後觀察是否 clone 輸出會改變
|
|
|
|
|
|
|
|
# # 0429 測試用
|
|
# # 0429 測試用
|
|
# import random
|
|
# import random
|
|
@@ -506,12 +508,11 @@ def add_server_views():
|
|
# sl(tt)
|
|
# sl(tt)
|
|
# Automatic_Build_System[key] = tt
|
|
# Automatic_Build_System[key] = tt
|
|
|
|
|
|
- # Rita 0428 測試
|
|
|
|
|
|
+ sl(1)
|
|
command_start_time = time.time()
|
|
command_start_time = time.time()
|
|
- # command = "bash -lc '{}'".format(command)
|
|
|
|
- # print(command)
|
|
|
|
- stdin, stdout, stderr = ssh.exec_command(command) # # Rita 0428 測試
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ # 0504 Rita 測試
|
|
|
|
+ stdin, stdout, stderr = ssh.exec_command(command)
|
|
error = stderr.read().decode()
|
|
error = stderr.read().decode()
|
|
success = stdout.read().decode()
|
|
success = stdout.read().decode()
|
|
# print('error: ', error, '\nlen(error): ', len(error))
|
|
# print('error: ', error, '\nlen(error): ', len(error))
|
|
@@ -519,11 +520,10 @@ def add_server_views():
|
|
print('success: ', success)
|
|
print('success: ', success)
|
|
if len(success) > 200000:
|
|
if len(success) > 200000:
|
|
success = success[0:20000] + '... etc'
|
|
success = success[0:20000] + '... etc'
|
|
|
|
+
|
|
execution_time = round(time.time() - command_start_time, 3)
|
|
execution_time = round(time.time() - command_start_time, 3)
|
|
|
|
|
|
- # if error and 'mysql: [Warning] Using a password on the command line interface can be insecure.' not in error:
|
|
|
|
if error:
|
|
if error:
|
|
-
|
|
|
|
# 排除 錯誤訊息中的 警告訊息
|
|
# 排除 錯誤訊息中的 警告訊息
|
|
Warning_list = [
|
|
Warning_list = [
|
|
"WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager.",
|
|
"WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager.",
|
|
@@ -604,40 +604,9 @@ def add_server_views():
|
|
if key in command:
|
|
if key in command:
|
|
Automatic_Build_System[key] = execution_time
|
|
Automatic_Build_System[key] = execution_time
|
|
|
|
|
|
- # # 修改 git 檔案內 app.ini 檔案, 將使用者取代成 username
|
|
|
|
- # if 'app.ini' in command :
|
|
|
|
- # command = 'cd /home/' + username + '/gogs/custom/conf/;' + \
|
|
|
|
- # 'pwd;' + \
|
|
|
|
- # 'sed -i "s/使用者/' + username + '/g" app.ini'
|
|
|
|
- # print(command)
|
|
|
|
- # stdin, stdout, stderr = ssh.exec_command(command)
|
|
|
|
- # error = stderr.read().decode()
|
|
|
|
- # success = stdout.read().decode()
|
|
|
|
- # if error:
|
|
|
|
- # print('=== error ===')
|
|
|
|
- # with open('ItemFile.csv', 'a', newline='') as csvFile:
|
|
|
|
- # csvWriter = csv.writer(csvFile)
|
|
|
|
- # csvWriter.writerow([command.replace(';', ';\n'),
|
|
|
|
- # 'success: \n' + success + '\n' + 'error: \n' + error,
|
|
|
|
- # # 'success: \n' + success,
|
|
|
|
- # # 'error: \n' + error,
|
|
|
|
- # execution_time,
|
|
|
|
- # 'error'])
|
|
|
|
- # else:
|
|
|
|
- # print('=== success ===')
|
|
|
|
- # with open('ItemFile.csv', 'a', newline='') as csvFile:
|
|
|
|
- # csvWriter = csv.writer(csvFile)
|
|
|
|
- # csvWriter.writerow([command.replace(';', ';\n'),
|
|
|
|
- # 'success: \n' + success + '\nerror: \n' + error,
|
|
|
|
- # execution_time,
|
|
|
|
- # 'success'])
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- sl(3)
|
|
|
|
|
|
+ sl(5) # Rita 原本為 sl(6) 增加後觀察是否 clone 輸出會改變
|
|
print('-----------------------------------------------------------------------------')
|
|
print('-----------------------------------------------------------------------------')
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
# print("Automatic_Build_System: ")
|
|
# print("Automatic_Build_System: ")
|
|
# print(Automatic_Build_System)
|
|
# print(Automatic_Build_System)
|
|
with open('../ItemFile.csv', 'a', newline='') as csvFile:
|
|
with open('../ItemFile.csv', 'a', newline='') as csvFile:
|
|
@@ -647,11 +616,8 @@ def add_server_views():
|
|
'',
|
|
'',
|
|
''])
|
|
''])
|
|
|
|
|
|
- # # 關閉寫入的 CSV 檔案
|
|
|
|
- # csvFile.close()
|
|
|
|
-
|
|
|
|
- # # 關閉連線
|
|
|
|
- # ssh.close()
|
|
|
|
|
|
+ # 關閉連線
|
|
|
|
+ ssh.close()
|
|
if item_install_fail:
|
|
if item_install_fail:
|
|
res = '有套件未安裝完成!'
|
|
res = '有套件未安裝完成!'
|
|
else:
|
|
else:
|