Compare commits

..

2 Commits

Author SHA1 Message Date
12a3457fe9 完成远程命令的标签 2025-08-31 11:07:11 +08:00
b7cdaa02c8 完成git的功能 2025-08-31 11:02:17 +08:00
7 changed files with 257 additions and 11 deletions

70
app.log
View File

@@ -64,3 +64,73 @@
2025-08-31 11:00:00.984 | INFO | remote_commands_tab:clone_repository:216 - 克隆仓库 2025-08-31 11:00:00.984 | INFO | remote_commands_tab:clone_repository:216 - 克隆仓库
2025-08-31 11:00:00.986 | INFO | remote_commands_tab:run:53 - 执行远程命令: git clone http://192.168.3.241:3000/xiaji/webstatus.git 2025-08-31 11:00:00.986 | INFO | remote_commands_tab:run:53 - 执行远程命令: git clone http://192.168.3.241:3000/xiaji/webstatus.git
2025-08-31 11:00:01.039 | INFO | remote_commands_tab:run:101 - 命令执行成功: git clone http://192.168.3.241:3000/xiaji/webstatus.git 2025-08-31 11:00:01.039 | INFO | remote_commands_tab:run:101 - 命令执行成功: git clone http://192.168.3.241:3000/xiaji/webstatus.git
2025-08-31 11:01:37.176 | INFO | __main__:<module>:52 - 启动应用程序
2025-08-31 11:01:37.199 | INFO | __main__:__init__:13 - 初始化主窗口
2025-08-31 11:01:37.200 | INFO | server_connection_tab:__init__:14 - 初始化服务器连接标签页
2025-08-31 11:01:37.207 | INFO | server_connection_tab:init_ui:93 - 服务器连接标签页UI初始化完成
2025-08-31 11:01:37.207 | INFO | server_connection_tab:load_config:96 - 加载配置文件
2025-08-31 11:01:37.208 | INFO | server_connection_tab:load_config:103 - 成功加载配置文件: c:\Users\xiaji\Documents\个人文件夹\夏骥\桌面部署\config.json
2025-08-31 11:01:37.208 | INFO | server_connection_tab:on_alias_changed:122 - 选择别名: 测试机
2025-08-31 11:01:37.210 | INFO | remote_commands_tab:__init__:116 - 初始化远程命令标签页
2025-08-31 11:01:37.210 | INFO | remote_commands_tab:init_ui:184 - 远程命令标签页UI初始化完成
2025-08-31 11:01:37.211 | INFO | __main__:__init__:32 - 主窗口初始化完成
2025-08-31 11:01:39.317 | INFO | server_connection_tab:connect_to_server:188 - 尝试连接服务器
2025-08-31 11:01:39.402 | INFO | server_connection_tab:connect_to_server:207 - 成功连接到服务器: 192.168.3.157
2025-08-31 11:01:54.528 | INFO | server_connection_tab:save_config:155 - 保存配置
2025-08-31 11:01:54.529 | INFO | server_connection_tab:save_config:181 - 配置已保存到: c:\Users\xiaji\Documents\个人文件夹\夏骥\桌面部署\config.json
2025-08-31 11:01:57.411 | INFO | server_connection_tab:connect_to_server:188 - 尝试连接服务器
2025-08-31 11:01:57.492 | INFO | server_connection_tab:connect_to_server:207 - 成功连接到服务器: 192.168.3.157
2025-08-31 11:01:58.932 | INFO | __main__:on_tab_changed:35 - 标签页切换到: 1
2025-08-31 11:01:58.933 | INFO | remote_commands_tab:set_ssh_client:187 - 设置SSH客户端
2025-08-31 11:01:58.933 | INFO | remote_commands_tab:set_server_config:198 - 设置服务器配置: git_url=http://192.168.3.241:3000/xiaji/webstatus.git, remote_dir=/home/xiaji
2025-08-31 11:02:03.902 | INFO | remote_commands_tab:clone_repository:235 - 克隆仓库
2025-08-31 11:02:03.903 | INFO | remote_commands_tab:run:53 - 执行远程命令: mkdir -p /home/xiaji && cd /home/xiaji && git clone http://192.168.3.241:3000/xiaji/webstatus.git
2025-08-31 11:02:03.914 | ERROR | remote_commands_tab:run:104 - 命令执行失败,退出状态: 128
2025-08-31 11:04:10.367 | INFO | __main__:<module>:56 - 启动应用程序
2025-08-31 11:04:10.389 | INFO | __main__:__init__:13 - 初始化主窗口
2025-08-31 11:04:10.390 | INFO | server_connection_tab:__init__:14 - 初始化服务器连接标签页
2025-08-31 11:04:10.396 | INFO | server_connection_tab:init_ui:93 - 服务器连接标签页UI初始化完成
2025-08-31 11:04:10.396 | INFO | server_connection_tab:load_config:96 - 加载配置文件
2025-08-31 11:04:10.396 | INFO | server_connection_tab:load_config:103 - 成功加载配置文件: c:\Users\xiaji\Documents\个人文件夹\夏骥\桌面部署\config.json
2025-08-31 11:04:10.397 | INFO | server_connection_tab:on_alias_changed:122 - 选择别名: 测试机
2025-08-31 11:04:10.399 | INFO | remote_commands_tab:__init__:116 - 初始化远程命令标签页
2025-08-31 11:04:10.402 | INFO | remote_commands_tab:init_ui:226 - 远程命令标签页UI初始化完成
2025-08-31 11:04:10.402 | INFO | __main__:__init__:32 - 主窗口初始化完成
2025-08-31 11:04:11.854 | INFO | server_connection_tab:connect_to_server:188 - 尝试连接服务器
2025-08-31 11:04:11.954 | INFO | server_connection_tab:connect_to_server:207 - 成功连接到服务器: 192.168.3.157
2025-08-31 11:04:13.472 | INFO | __main__:on_tab_changed:35 - 标签页切换到: 1
2025-08-31 11:04:13.473 | INFO | remote_commands_tab:set_ssh_client:229 - 设置SSH客户端
2025-08-31 11:04:13.474 | INFO | remote_commands_tab:set_server_config:240 - 设置服务器配置: git_url=http://192.168.3.241:3000/xiaji/webstatus.git, remote_dir=/home/xiaji
2025-08-31 11:04:13.475 | INFO | remote_commands_tab:refresh_directory:329 - 刷新目录列表
2025-08-31 11:04:13.477 | INFO | remote_commands_tab:run:53 - 执行远程命令: cd /home/xiaji && pwd && ls -la
2025-08-31 11:04:13.486 | INFO | remote_commands_tab:run:101 - 命令执行成功: cd /home/xiaji && pwd && ls -la
2025-08-31 11:04:18.574 | INFO | remote_commands_tab:refresh_directory:329 - 刷新目录列表
2025-08-31 11:04:18.576 | INFO | remote_commands_tab:run:53 - 执行远程命令: cd /home/xiaji && pwd && ls -la
2025-08-31 11:04:18.584 | INFO | remote_commands_tab:run:101 - 命令执行成功: cd /home/xiaji && pwd && ls -la
2025-08-31 11:05:13.449 | INFO | __main__:<module>:56 - 启动应用程序
2025-08-31 11:05:13.473 | INFO | __main__:__init__:13 - 初始化主窗口
2025-08-31 11:05:13.474 | INFO | server_connection_tab:__init__:14 - 初始化服务器连接标签页
2025-08-31 11:05:13.482 | INFO | server_connection_tab:init_ui:93 - 服务器连接标签页UI初始化完成
2025-08-31 11:05:13.482 | INFO | server_connection_tab:load_config:96 - 加载配置文件
2025-08-31 11:05:13.482 | INFO | server_connection_tab:load_config:103 - 成功加载配置文件: c:\Users\xiaji\Documents\个人文件夹\夏骥\桌面部署\config.json
2025-08-31 11:05:13.484 | INFO | server_connection_tab:on_alias_changed:122 - 选择别名: 测试机
2025-08-31 11:05:13.485 | INFO | remote_commands_tab:__init__:116 - 初始化远程命令标签页
2025-08-31 11:05:13.486 | INFO | remote_commands_tab:init_ui:229 - 远程命令标签页UI初始化完成
2025-08-31 11:05:13.486 | INFO | __main__:__init__:32 - 主窗口初始化完成
2025-08-31 11:05:25.546 | INFO | server_connection_tab:connect_to_server:188 - 尝试连接服务器
2025-08-31 11:05:25.636 | INFO | server_connection_tab:connect_to_server:207 - 成功连接到服务器: 192.168.3.157
2025-08-31 11:05:28.431 | INFO | __main__:on_tab_changed:35 - 标签页切换到: 1
2025-08-31 11:05:28.432 | INFO | remote_commands_tab:set_ssh_client:232 - 设置SSH客户端
2025-08-31 11:05:28.433 | INFO | remote_commands_tab:set_server_config:243 - 设置服务器配置: git_url=http://192.168.3.241:3000/xiaji/webstatus.git, remote_dir=/home/xiaji
2025-08-31 11:05:28.433 | INFO | remote_commands_tab:refresh_directory:332 - 刷新目录列表
2025-08-31 11:05:28.433 | INFO | remote_commands_tab:refresh_directory:344 - 使用用户输入目录: /home/xiaji
2025-08-31 11:05:28.435 | INFO | remote_commands_tab:run:53 - 执行远程命令: cd /home/xiaji && pwd && ls -la
2025-08-31 11:05:28.447 | INFO | remote_commands_tab:run:101 - 命令执行成功: cd /home/xiaji && pwd && ls -la
2025-08-31 11:05:38.554 | INFO | remote_commands_tab:refresh_directory:332 - 刷新目录列表
2025-08-31 11:05:38.555 | INFO | remote_commands_tab:refresh_directory:344 - 使用用户输入目录: /home/xiaji/statuspage
2025-08-31 11:05:38.556 | INFO | remote_commands_tab:run:53 - 执行远程命令: cd /home/xiaji/statuspage && pwd && ls -la
2025-08-31 11:05:38.563 | ERROR | remote_commands_tab:run:104 - 命令执行失败,退出状态: 1
2025-08-31 11:06:07.009 | INFO | remote_commands_tab:refresh_directory:332 - 刷新目录列表
2025-08-31 11:06:07.010 | INFO | remote_commands_tab:refresh_directory:344 - 使用用户输入目录: /home/xiaji/webstatus
2025-08-31 11:06:07.011 | INFO | remote_commands_tab:run:53 - 执行远程命令: cd /home/xiaji/webstatus && pwd && ls -la
2025-08-31 11:06:07.020 | INFO | remote_commands_tab:run:101 - 命令执行成功: cd /home/xiaji/webstatus && pwd && ls -la

View File

@@ -4,6 +4,8 @@
"username": "xiaji", "username": "xiaji",
"password": "xiaji", "password": "xiaji",
"port": 22, "port": 22,
"project": "statuspage" "project": "statuspage",
"git_url": "http://192.168.3.241:3000/xiaji/webstatus.git",
"remote_dir": "/home/xiaji"
} }
} }

18
main.py
View File

@@ -32,12 +32,24 @@ class MainWindow(QMainWindow):
logger.info("主窗口初始化完成") logger.info("主窗口初始化完成")
def on_tab_changed(self, index): def on_tab_changed(self, index):
logger.info(f"切换到标签页: {index}") logger.info(f"标签页切换到: {index}")
# 当切换到远程命令标签页时传递SSH客户端 # 当切换到远程命令标签页时传递SSH客户端和服务器配置
if index == 1: # 远程命令标签页的索引 if index == 1: # 远程命令标签页
ssh_client = self.server_connection_tab.get_ssh_client() ssh_client = self.server_connection_tab.get_ssh_client()
self.remote_commands_tab.set_ssh_client(ssh_client) self.remote_commands_tab.set_ssh_client(ssh_client)
# 获取当前选中的服务器配置
current_alias = self.server_connection_tab.alias_combo.currentText()
if current_alias and current_alias in self.server_connection_tab.config_data:
server_config = self.server_connection_tab.config_data[current_alias]
git_url = server_config.get("git_url", "")
remote_dir = server_config.get("remote_dir", "")
self.remote_commands_tab.set_server_config(git_url, remote_dir)
else:
# 如果没有配置远程目录,初始化为默认目录
self.remote_commands_tab.current_dir_display.setText("~")
self.remote_commands_tab.refresh_directory()
if __name__ == "__main__": if __name__ == "__main__":
logger.add("app.log", rotation="10 MB") logger.add("app.log", rotation="10 MB")

View File

@@ -135,18 +135,77 @@ class RemoteCommandsTab(QWidget):
git_layout.addLayout(install_git_layout) git_layout.addLayout(install_git_layout)
# 克隆项目 # 克隆项目
clone_layout = QFormLayout() clone_layout = QHBoxLayout()
self.repo_url_input = QLineEdit()
clone_layout.addRow("仓库URL:", self.repo_url_input)
# 左侧仓库URL和目录信息
left_layout = QFormLayout()
self.repo_url_input = QLineEdit()
left_layout.addRow("仓库URL:", self.repo_url_input)
self.remote_dir_display = QLineEdit()
self.remote_dir_display.setReadOnly(True)
left_layout.addRow("远程目录:", self.remote_dir_display)
clone_layout.addLayout(left_layout)
# 右侧:按钮
right_layout = QVBoxLayout()
self.clone_button = QPushButton("克隆项目") self.clone_button = QPushButton("克隆项目")
self.clone_button.clicked.connect(self.clone_repository) self.clone_button.clicked.connect(self.clone_repository)
clone_layout.addRow(self.clone_button) right_layout.addWidget(self.clone_button)
right_layout.addStretch()
clone_layout.addLayout(right_layout)
git_layout.addLayout(clone_layout) git_layout.addLayout(clone_layout)
git_group.setLayout(git_layout) git_group.setLayout(git_layout)
main_layout.addWidget(git_group) main_layout.addWidget(git_group)
# 目录管理组
dir_group = QGroupBox("目录管理")
dir_layout = QVBoxLayout()
# 当前目录显示
current_dir_layout = QHBoxLayout()
current_dir_layout.addWidget(QLabel("当前目录:"))
self.current_dir_display = QLineEdit()
# 允许用户输入当前目录路径
# self.current_dir_display.setReadOnly(True)
# 添加回车键刷新目录功能
self.current_dir_display.returnPressed.connect(self.refresh_directory)
current_dir_layout.addWidget(self.current_dir_display)
# 刷新目录按钮
self.refresh_dir_button = QPushButton("刷新目录")
self.refresh_dir_button.clicked.connect(self.refresh_directory)
current_dir_layout.addWidget(self.refresh_dir_button)
dir_layout.addLayout(current_dir_layout)
# 目录列表
dir_list_layout = QHBoxLayout()
dir_list_layout.addWidget(QLabel("目录内容:"))
self.dir_list_text = QTextEdit()
self.dir_list_text.setReadOnly(True)
self.dir_list_text.setMaximumHeight(150)
dir_list_layout.addWidget(self.dir_list_text)
dir_layout.addLayout(dir_list_layout)
# 删除目录
delete_dir_layout = QHBoxLayout()
delete_dir_layout.addWidget(QLabel("删除目录:"))
self.delete_dir_input = QLineEdit()
delete_dir_layout.addWidget(self.delete_dir_input)
self.delete_dir_button = QPushButton("删除目录")
self.delete_dir_button.clicked.connect(self.delete_directory)
delete_dir_layout.addWidget(self.delete_dir_button)
dir_layout.addLayout(delete_dir_layout)
dir_group.setLayout(dir_layout)
main_layout.addWidget(dir_group)
# 命令输出区域 # 命令输出区域
output_group = QGroupBox("命令输出") output_group = QGroupBox("命令输出")
output_layout = QVBoxLayout() output_layout = QVBoxLayout()
@@ -180,6 +239,16 @@ class RemoteCommandsTab(QWidget):
self.status_label.setText("未连接到服务器") self.status_label.setText("未连接到服务器")
self.status_label.setStyleSheet("color: red;") self.status_label.setStyleSheet("color: red;")
def set_server_config(self, git_url, remote_dir):
logger.info(f"设置服务器配置: git_url={git_url}, remote_dir={remote_dir}")
self.repo_url_input.setText(git_url)
self.remote_dir_display.setText(remote_dir)
# 如果设置了远程目录,也设置为当前目录
if remote_dir:
self.current_dir_display.setText(remote_dir)
self.refresh_directory()
def install_git(self): def install_git(self):
logger.info("安装Git") logger.info("安装Git")
@@ -224,11 +293,20 @@ class RemoteCommandsTab(QWidget):
QMessageBox.warning(self, "警告", "请输入仓库URL") QMessageBox.warning(self, "警告", "请输入仓库URL")
return return
remote_dir = self.remote_dir_display.text().strip()
self.output_text.clear() self.output_text.clear()
self.status_label.setText("正在克隆仓库...") self.status_label.setText("正在克隆仓库...")
# 构建克隆命令
if remote_dir:
# 如果指定了远程目录,先创建目录(如果不存在),然后克隆到指定目录
clone_command = f"mkdir -p {remote_dir} && cd {remote_dir} && git clone {repo_url}"
else:
clone_command = f"git clone {repo_url}"
# 创建并启动线程执行命令 # 创建并启动线程执行命令
self.command_thread = RemoteCommandThread(self.ssh_client, f"git clone {repo_url}") self.command_thread = RemoteCommandThread(self.ssh_client, clone_command)
self.command_thread.output_signal.connect(self.append_output) self.command_thread.output_signal.connect(self.append_output)
self.command_thread.finished_signal.connect(self.on_command_finished) self.command_thread.finished_signal.connect(self.on_command_finished)
self.command_thread.start() self.command_thread.start()
@@ -241,7 +319,81 @@ class RemoteCommandsTab(QWidget):
self.status_label.setText(message) self.status_label.setText(message)
self.status_label.setStyleSheet("color: green;") self.status_label.setStyleSheet("color: green;")
QMessageBox.information(self, "成功", message) QMessageBox.information(self, "成功", message)
# 如果是目录相关操作,刷新目录列表
if "删除" in message or "目录" in message:
self.refresh_directory()
else: else:
self.status_label.setText(message) self.status_label.setText(message)
self.status_label.setStyleSheet("color: red;") self.status_label.setStyleSheet("color: red;")
QMessageBox.warning(self, "错误", message) QMessageBox.warning(self, "错误", message)
def refresh_directory(self):
logger.info("刷新目录列表")
if not self.ssh_client:
QMessageBox.warning(self, "警告", "请先连接到服务器")
return
current_dir = self.current_dir_display.text().strip()
if not current_dir:
current_dir = "~" # 默认用户主目录
self.current_dir_display.setText(current_dir)
logger.info(f"使用默认目录: {current_dir}")
else:
logger.info(f"使用用户输入目录: {current_dir}")
self.status_label.setText("正在刷新目录列表...")
# 创建并启动线程执行命令
command = f"cd {current_dir} && pwd && ls -la"
self.command_thread = RemoteCommandThread(self.ssh_client, command)
self.command_thread.output_signal.connect(self.append_dir_output)
self.command_thread.finished_signal.connect(self.on_dir_refresh_finished)
self.command_thread.start()
def append_dir_output(self, text):
self.dir_list_text.append(text)
def on_dir_refresh_finished(self, success, message):
if success:
self.status_label.setText("目录列表已刷新")
self.status_label.setStyleSheet("color: green;")
else:
self.status_label.setText("刷新目录列表失败")
self.status_label.setStyleSheet("color: red;")
QMessageBox.warning(self, "错误", f"刷新目录列表失败: {message}")
def delete_directory(self):
logger.info("删除目录")
if not self.ssh_client:
QMessageBox.warning(self, "警告", "请先连接到服务器")
return
dir_to_delete = self.delete_dir_input.text().strip()
if not dir_to_delete:
QMessageBox.warning(self, "警告", "请输入要删除的目录名")
return
current_dir = self.current_dir_display.text().strip()
if not current_dir:
current_dir = "~"
# 确认删除
reply = QMessageBox.question(self, "确认删除",
f"确定要删除目录 '{current_dir}/{dir_to_delete}' 及其所有内容吗?\n此操作不可撤销!",
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.No:
return
self.output_text.clear()
self.status_label.setText("正在删除目录...")
# 创建并启动线程执行命令
command = f"cd {current_dir} && rm -rf {dir_to_delete}"
self.command_thread = RemoteCommandThread(self.ssh_client, command)
self.command_thread.output_signal.connect(self.append_output)
self.command_thread.finished_signal.connect(self.on_command_finished)
self.command_thread.start()

View File

@@ -59,6 +59,12 @@ class ServerConnectionTab(QWidget):
self.project_input = QLineEdit() self.project_input = QLineEdit()
config_layout.addRow("项目名称:", self.project_input) config_layout.addRow("项目名称:", self.project_input)
self.git_url_input = QLineEdit()
config_layout.addRow("Git地址:", self.git_url_input)
self.remote_dir_input = QLineEdit()
config_layout.addRow("远程目录:", self.remote_dir_input)
config_group.setLayout(config_layout) config_group.setLayout(config_layout)
main_layout.addWidget(config_group) main_layout.addWidget(config_group)
@@ -121,6 +127,8 @@ class ServerConnectionTab(QWidget):
self.password_input.setText(server_info.get("password", "")) self.password_input.setText(server_info.get("password", ""))
self.port_input.setText(str(server_info.get("port", "22"))) self.port_input.setText(str(server_info.get("port", "22")))
self.project_input.setText(server_info.get("project", "")) self.project_input.setText(server_info.get("project", ""))
self.git_url_input.setText(server_info.get("git_url", ""))
self.remote_dir_input.setText(server_info.get("remote_dir", ""))
def add_new_alias(self): def add_new_alias(self):
logger.info("添加新别名") logger.info("添加新别名")
@@ -157,7 +165,9 @@ class ServerConnectionTab(QWidget):
"username": self.username_input.text(), "username": self.username_input.text(),
"password": self.password_input.text(), "password": self.password_input.text(),
"port": int(self.port_input.text()), "port": int(self.port_input.text()),
"project": self.project_input.text() "project": self.project_input.text(),
"git_url": self.git_url_input.text(),
"remote_dir": self.remote_dir_input.text()
} }
# 更新配置数据 # 更新配置数据