增加Apache配置,当有Apache配置时显示Apache服务按钮

This commit is contained in:
shileiye 2022-01-07 01:37:56 +08:00
parent b26411eec7
commit f638a47436
2 changed files with 45 additions and 19 deletions

BIN
dist/main.exe vendored

Binary file not shown.

46
main.py
View File

@ -45,13 +45,16 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.newGameInput.setText(config['GAME']['game_name']) self.newGameInput.setText(config['GAME']['game_name'])
# 设置按钮状态 # 设置按钮状态
if not config.has_section('NGINX'): if not config.has_section('NGINX') and not config.has_section('APACHE'):
self.nginxButton.setDisabled(True) self.nginxButton.setDisabled(True)
else: elif config.has_section('APACHE'):
if isinstance(checkprocess("nginx.exe"), int): self.nginxButton.setText("启动Apache")
self.nginxButton.setText("关闭Nginx") if isinstance(checkprocess("httpd.exe"), int):
self.nginxButton.setText("关闭Apache")
else: else:
self.nginxButton.setText("启动Nginx") self.nginxButton.setText("启动Nginx")
if isinstance(checkprocess("nginx.exe"), int):
self.nginxButton.setText("关闭Nginx")
if not config.has_section('MYSQL'): if not config.has_section('MYSQL'):
self.mysqlButton.setDisabled(True) self.mysqlButton.setDisabled(True)
@ -186,21 +189,40 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# encoding='utf-8' # encoding='utf-8'
) )
self.nginxButton.setText("关闭Nginx") self.nginxButton.setText("关闭Nginx")
else: elif self.nginxButton.text() == '关闭Nginx':
nginx_process = Popen('.\\nginx.exe -s stop', Popen('.\\nginx.exe -s stop',
shell=True, shell=True,
cwd=config['NGINX']['nginx_path'], cwd=config['NGINX']['nginx_path'],
# encoding='utf-8' # encoding='utf-8'
) )
spawner_process = Popen('taskkill /f /t /im php-cgi-spawner.exe', Popen('taskkill /f /t /im php-cgi-spawner.exe',
shell=True, shell=True,
# encoding='utf-8' # encoding='utf-8'
) )
PHP_process = Popen('taskkill /f /t /im php-cgi.exe', Popen('taskkill /f /t /im php-cgi.exe',
shell=True, shell=True,
# encoding='utf-8' # encoding='utf-8'
) )
self.nginxButton.setText("启动Nginx") self.nginxButton.setText("启动Nginx")
elif self.nginxButton.text() == '启动Apache':
Popen('.\\httpd.exe',
shell=True,
cwd=config['APACHE']['apache_path'] + 'bin\\',
# encoding='utf-8'
)
self.nginxButton.setText("关闭Apache")
elif self.nginxButton.text() == '关闭Apache':
Popen('.\\httpd.exe k stop',
shell=True,
cwd=config['APACHE']['apache_path'] + 'bin\\',
# encoding='utf-8'
)
Popen('taskkill /f /t /im httpd.exe',
shell=True,
# encoding='utf-8'
)
self.nginxButton.setText("启动Apache")
# print(process) # print(process)
# os.chdir("D:\\LYserver\\phpstudy_pro\\Extensions\\Nginx1.15.11") # os.chdir("D:\\LYserver\\phpstudy_pro\\Extensions\\Nginx1.15.11")
# nginxtype = os.system('start .\\nginx.exe') # 不弹出界面 # nginxtype = os.system('start .\\nginx.exe') # 不弹出界面
@ -210,7 +232,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def mysql(self, event): def mysql(self, event):
if self.mysqlButton.text() == '启动MySql': if self.mysqlButton.text() == '启动MySql':
Popen('.\\mysqld.exe', Popen('.\\mysqld.exe --console',
shell=True, shell=True,
cwd=config['MYSQL']['mysql_path'] + 'bin', cwd=config['MYSQL']['mysql_path'] + 'bin',
# encoding='utf-8' # encoding='utf-8'
@ -235,10 +257,14 @@ class MainWindow(QMainWindow, Ui_MainWindow):
else: else:
sleeptime = float(value.split(",")[1]) sleeptime = float(value.split(",")[1])
game_file = value.split(",")[0] game_file = value.split(",")[0]
# 处理启动路径
game_path = '\\'.join(value.split("\\")[0:-1])
# print(game_path)
try: try:
Popen('start ' + game_file, Popen('start ' + game_file,
shell=True, shell=True,
# cwd=values, cwd=game_path,
# encoding='utf-8' # encoding='utf-8'
) )
time.sleep(float(sleeptime)) # 延迟启动时间 time.sleep(float(sleeptime)) # 延迟启动时间