Fetch the repository succeeded.
This action will force synchronization from 科艺创想/自美人工智能系统, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
# @Date: 2020-01-03 09:09:04
# @LastEditTime: 2020-03-26 10:05:48
# @Description: 启动和停止 ./run.py debug ./run.py stop
import os
import subprocess
import sys
import time
from python.package.Mylib import Mylib
def stop(pname):
if processExist(pname):
print('[\033[31m停止任务 {} 成功!\033[0m]'.format(pname))
cmd = "sudo pkill -fe {}".format(pname)
os.system(cmd)
return 1
else:
return 0
def processExist(pname):
''' 查询pname进程是否存在 是则返回true '''
query = 'sudo ps ax | grep {} | grep -v grep '.format(pname)
out = os.popen(query).read()
return out != ''
def init():
os.chdir(os.path.dirname(os.path.abspath(__file__)))
# os.system("sudo alsactl --file data/conf/asound.state restore") # 加载音量设置
os.system("sudo amixer set Capture 70%") # 设置话筒
# os.system("alsactl --file data/conf/asound.state restore") # 加载音量设置
os.system("amixer set Capture 70%") # 设置话筒
# 设定目录权限 特别是pi
os.system("sudo chmod -R 0777 data")
os.system("sudo chmod -R 0777 runtime")
os.system("sudo chmod -R 0777 /music/")
bak = "data/conf/configBAK.yaml"
cfg = "config.yaml"
if not os.path.exists(cfg) or os.path.getsize(cfg) < 10:
os.system('sudo cp -f %s %s ' % (bak, cfg))
os.system('sudo chown pi.pi %s' % cfg)
os.system('sudo chmod 0666 %s' % cfg)
print("修复配置文件 %s ,以前配置丢失。 " % cfg)
# 如果屏幕配置为不启动 则也不启动前端app
mojing = Mylib.getConfig()["LoadModular"]["Screen"]
if mojing is False:
global tasks
del(tasks[2])
tasks = [
{"pname": "ControlCenter.py", "cmd": "python3 ControlCenter.py", "sleep": 1},
{"pname": "WebServer.py", "cmd": "python3 WebServer.py", "sleep": 1}, # 前端必须在第一位
{"pname": "moJing", "cmd": "export DISPLAY=:0.0 & app/moJing", "sleep": 1},
{"pname": os.path.basename(__file__), "cmd": __file__, "sleep": 1}] # 自已必须在最后一位
if __name__ == '__main__':
args = str(sys.argv[1:]).lower()
if 'stop' in args:
stop_i = 0
stop_i += stop('awake') # 语音唤醒
stop_i += stop('mplayer')
stop_i += stop('mosquitto')
for task in tasks:
stop_i += stop(task['pname'])
print('=='*40)
print( stop_i )
print('=='*40)
if 'debug' in args:
tasks[1]['cmd'] += " debug"
tasks[2]['cmd'] += " debug"
if not os.popen('export | grep DISPLAY').read():
del(tasks[2])
# 检测自己是否已运行
isroot = 0
if int(os.popen("id -u").read()) == 0:
isroot = 1
thisfile = os.path.basename(__file__)
cmd = "sudo ps ax | grep {} | grep -v grep | wc -l".format(thisfile)
n = int(os.popen(cmd).read()) - isroot
if n >= 2:
print("\033[31m{}已经运行! \033[0m结束任务用: ./{} stop".format(thisfile, thisfile))
exit()
init() # 运行前初始化工作
os.system("mosquitto -d") # 启动本地MQTT服务器
while True:
for task in tasks:
if not processExist(task['pname']):
print("\033[32mRun Task: %s\033[0m" % task['pname'])
subprocess.Popen(args=task['cmd'], shell=True)
time.sleep(task['sleep'])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。