下面的 不太对
@admin_cfg.route('/download_log', methods=['GET'])
def download_serial_com_log():
if 'login' not in session:
return redirect("/")
lst_file = os.listdir('/root/')
print(type(lst_file))
print(lst_file)
if os.path.exists('/root/down_data.tar'):
os.remove('/root/down_data.tar')
str_file_lst = ''
for item in lst_file:
print(item)
# modbus_client_com5.log
if item.find('modbus_client_com') >= 0:
str_file_lst = str_file_lst + '/root/' + item + ' '
if len(str_file_lst) > 0:
str_cmd = 'tar cvf /root/down_data.tar ' + str_file_lst
print(str_cmd)
p = os.popen(str_cmd)
data = p.read().strip()
p.close()
else:
return send_from_directory("/root/", filename="4g.txt", as_attachment=True)
return send_from_directory("/root/", filename="down_data.tar", as_attachment=True)