From b7cdaa02c865b0fc4ed44bd8e478fdd14a9279a8 Mon Sep 17 00:00:00 2001 From: xiaji Date: Sun, 31 Aug 2025 11:02:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90git=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../remote_commands_tab.cpython-38.pyc | Bin 6967 -> 7527 bytes .../server_connection_tab.cpython-38.pyc | Bin 6020 -> 6253 bytes app.log | 22 ++++++++++ config.json | 4 +- main.py | 14 +++++-- remote_commands_tab.py | 38 +++++++++++++++--- server_connection_tab.py | 12 +++++- 7 files changed, 80 insertions(+), 10 deletions(-) diff --git a/__pycache__/remote_commands_tab.cpython-38.pyc b/__pycache__/remote_commands_tab.cpython-38.pyc index 8a0ac300e21ee37d1b402619175ff05af5f5a7ae..5e92f1cb6fb422880c15ae6c551d6f2fc21357e1 100644 GIT binary patch delta 1463 zcmZWo-HRJl6u);SnM@{=NizA|)!J-V79v}1t!-%_f)vDux(l_nkSZaYNq3XxV|z2H zY)A+iTct}uy;@ke#Yvy~v{fPqE7hlhi1-IYd^6o$-~10e=O#@-2k!5lbLO0L&;6Zq ze>k<5HZJ=88iDW6-ND*i>O13{PT%8~^<~ovS?0$i>-&VbNLGJ`q{4&mb)6dM?Sgd{ zR^uc7yZ_y;)FU0Y?E_S7y+_(4=Wi>HVaaV$_V*=9Ce{Gx0Vim=`jisk;YJI3wB3%@ zR?uz}$m6kPOX*R_6atS>+3hH>nn73rfQPK6BKX$Dnfh*_#AEDlj|Ct=T&Ps~nTz%-GeE+~sY z0xH6ubDpvl0`l^CqXdL_Rx^fik1`C{H$u2nX8ICz?03cgM?ekXV??5h;7*g0^jH|?y>N~>!& z9|kigmf#p7DY8lxS)m#YQk|+)lTlNtA*rAn66jC=N!lPCN>WB^X7 z@}aE25<~DR2sUx3McZ_nSW;WsCih%|2U3L2w{1H4j7N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g5Xg{i|PIvib_67tlbnh*AKtzO=l)%Ifn^*}m4!Ic+*^wNGaAxnz4ZME%@z zkfV=-|8;bRV~nF4QIm@nO&4f_8*&_*>2uY?F~V_}V+Ti`;{->6gCe35?Z9bNrOCoT zK3<|(8s&QeU0lTxYdDG#1OZJ_zyPO&L(CfJju4B5<9iagO-qQanBs~5N8?ZUPS~gL zlcQ58OA6xa^;`8D3v~MLdgIQ$^`)h#@=rEt+!Gb3xzo9+Je?W0()k>nVXxb|6`srw v!hW_5g3k6w!r=_}9_8R|7a45kUSO%n?tl-CD(I@(qqQx)rlgOJtLvP}< diff --git a/__pycache__/server_connection_tab.cpython-38.pyc b/__pycache__/server_connection_tab.cpython-38.pyc index 741e8c308d3c8bbeebea3b78a8984012ae04e9a3..bfb4c0b39939571d337e9c1b7cacf22267277ae5 100644 GIT binary patch delta 1177 zcmZvb&u$4;7HH)*>Hgb?u<`Lo~ozPID~ zzSUmc`CqqjOxHt1e*Sz?nOVuK7`+PoUl~-A(9J`O#38wqqqs3@IK)nseL!k%+H<4Q zO{44h+-8yUr@$0<{n;P6PGgH8Z*G+ht#;H6%4=I0WTWcVq33CEw>c^*o}u+#e^%DA z?uWeH?x=NOcebWKDigT_aho0R?)upMgvL=(GES_-SEZ;7^7ry}kydYRD`BidvwUOu z(Z-$2UzBvY{O8&7^LtCrZ$I4l{b%t&od&C71X>}jpPS{m5-a3p=jKbiYO?%y7kEBL zXIZ5qSO+j6c50u2R>^6ve2^1U;e7Ttxg94iP;lTjx#QbBB3pH2Y}SJO((%y1W%3?x-fC&bKAmM$Rkd-!l49qcXjw3RNBjSpYfMM~AVZk-=hj9{mL~HcK zh&;IN2Fr5Xwt-jbUk)z#9G_fA9q1$6v}10)$2d=vfvRQSf^unuH#iCn&>+>WD?ja7 z@bgAHiT8-d(YE0xhftjwWd+D_(o06k82MJJxe-6%sq>*5z_tTfP=Q?Pma|RMC~tPu z#jW{rzpKg}O!P&@?1Z!8h?&_PWXCbd3B&|q5;281i8zJmlc>V?tRENq#II&CuwP26 zMVPT{*c(bGmZrtt*aux()7_lZ09L+43?dF74kCsShs6)E~nx7d!@fhZulC92AqLV@9nz{bS=#L<~OD05iRi+MiIFBbCSGxBzfPA-jELI4R6bW5O=)=Y<}WP31p zFfm5LctT0G2mb)llP7P6vk3p-)DbJXu zxrn$vyeTj2G;Di19k5d#aD+iNB`eCG%F$NO8kl4@W|B-Sm zy!^EsPnclUn~EK3Fno4mqgd2vHL-Z+sGSCOTH}FkE)h|RSWy$~tQPB-;YVeV6ww2` zN7>{*l{?T{o^sYhd9z9aNb)W9eEFmLLxM^E-kpxW5C#~rzyK3ok}YY!HeENx#xv5A zldkj08tSx5R`XvqeUk3xN$qrCSR~R80o_5vs8ih1nj-}v3qAn?KJb7G>g*9If7X)F zlE8(vh$h64K*du?v;GxI(>XSpe!%D;ANT4|} zG}C9(&jKYdl#*0*tR`5k=`fr|m7zX!JikzsSzRWGIsA#QVJKu0Lo+-j2as{nNk&ML zObC@r$b^NLT2L`4QBZwqoly`(`Th0i%A@0I)0V0mb zCCTEbWLX6qHK6V}tIJ;kZ$X$W)#+~A)4oN%TQ>mnJQlpvWt)joP1K-%#J(F;ClDtQ z3y5}sieoODrTD+l1m6e_C(faq!Wm6`04eq`n@%mH(~M?t;$Ke{AG C)7(w~ diff --git a/app.log b/app.log index 2663fe2..cf8d5d6 100644 --- a/app.log +++ b/app.log @@ -64,3 +64,25 @@ 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: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__::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 diff --git a/config.json b/config.json index 40607d9..06d9799 100644 --- a/config.json +++ b/config.json @@ -4,6 +4,8 @@ "username": "xiaji", "password": "xiaji", "port": 22, - "project": "statuspage" + "project": "statuspage", + "git_url": "http://192.168.3.241:3000/xiaji/webstatus.git", + "remote_dir": "/home/xiaji" } } \ No newline at end of file diff --git a/main.py b/main.py index 9d46503..9f52dc2 100644 --- a/main.py +++ b/main.py @@ -32,12 +32,20 @@ class MainWindow(QMainWindow): logger.info("主窗口初始化完成") def on_tab_changed(self, index): - logger.info(f"切换到标签页: {index}") + logger.info(f"标签页切换到: {index}") - # 当切换到远程命令标签页时,传递SSH客户端 - if index == 1: # 远程命令标签页的索引 + # 当切换到远程命令标签页时,传递SSH客户端和服务器配置 + if index == 1: # 远程命令标签页 ssh_client = self.server_connection_tab.get_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) if __name__ == "__main__": logger.add("app.log", rotation="10 MB") diff --git a/remote_commands_tab.py b/remote_commands_tab.py index 06bd5dc..88b6997 100644 --- a/remote_commands_tab.py +++ b/remote_commands_tab.py @@ -135,13 +135,27 @@ class RemoteCommandsTab(QWidget): git_layout.addLayout(install_git_layout) # 克隆项目 - clone_layout = QFormLayout() - self.repo_url_input = QLineEdit() - clone_layout.addRow("仓库URL:", self.repo_url_input) + clone_layout = QHBoxLayout() + # 左侧:仓库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.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_group.setLayout(git_layout) @@ -180,6 +194,11 @@ class RemoteCommandsTab(QWidget): self.status_label.setText("未连接到服务器") 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) + def install_git(self): logger.info("安装Git") @@ -224,11 +243,20 @@ class RemoteCommandsTab(QWidget): QMessageBox.warning(self, "警告", "请输入仓库URL") return + remote_dir = self.remote_dir_display.text().strip() + self.output_text.clear() 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.finished_signal.connect(self.on_command_finished) self.command_thread.start() diff --git a/server_connection_tab.py b/server_connection_tab.py index 752df06..d5f0ff4 100644 --- a/server_connection_tab.py +++ b/server_connection_tab.py @@ -59,6 +59,12 @@ class ServerConnectionTab(QWidget): self.project_input = QLineEdit() 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) main_layout.addWidget(config_group) @@ -121,6 +127,8 @@ class ServerConnectionTab(QWidget): self.password_input.setText(server_info.get("password", "")) self.port_input.setText(str(server_info.get("port", "22"))) 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): logger.info("添加新别名") @@ -157,7 +165,9 @@ class ServerConnectionTab(QWidget): "username": self.username_input.text(), "password": self.password_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() } # 更新配置数据