wtsh 26.5.17__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wtsh-26.5.17/LICENSE +201 -0
- wtsh-26.5.17/PKG-INFO +205 -0
- wtsh-26.5.17/README.md +194 -0
- wtsh-26.5.17/pyproject.toml +22 -0
- wtsh-26.5.17/setup.cfg +4 -0
- wtsh-26.5.17/wtsh.egg-info/PKG-INFO +205 -0
- wtsh-26.5.17/wtsh.egg-info/SOURCES.txt +12 -0
- wtsh-26.5.17/wtsh.egg-info/dependency_links.txt +1 -0
- wtsh-26.5.17/wtsh.egg-info/entry_points.txt +2 -0
- wtsh-26.5.17/wtsh.egg-info/requires.txt +1 -0
- wtsh-26.5.17/wtsh.egg-info/top_level.txt +1 -0
- wtsh-26.5.17/wtsh.py +174 -0
- wtsh-26.5.17/wtsh_container/build/lib/wtsh_container/container_information.py +71 -0
- wtsh-26.5.17/wtsh_container/wtsh_container/container_information.py +24 -0
wtsh-26.5.17/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
wtsh-26.5.17/PKG-INFO
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wtsh
|
|
3
|
+
Version: 26.5.17
|
|
4
|
+
Summary: wtsh shell v26
|
|
5
|
+
Author-email: wazzge <2334498769@qq.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: cmd2
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# wtsh - 基于cmd2的插件化交互式命令行Shell
|
|
13
|
+
|
|
14
|
+
wtsh 是一个基于 Python cmd2 库开发的交互式命令行 Shell,提供了基本的文件系统操作和容器环境检测功能。
|
|
15
|
+
|
|
16
|
+
## 托管仓库
|
|
17
|
+
- [Gitee](https://gitee.com/wazzge/wtsh)
|
|
18
|
+
|
|
19
|
+
## 功能特性
|
|
20
|
+
|
|
21
|
+
- **交互式命令行界面**:基于 cmd2 框架,支持命令自动补全和历史记录
|
|
22
|
+
- **文件系统操作**:支持 ls、cat、cd、clear 等基本命令
|
|
23
|
+
- **容器环境检测**:自动识别 Docker、Podman、LXC 等容器运行时环境
|
|
24
|
+
- **彩色提示符**:显示用户名、当前目录和操作系统平台信息
|
|
25
|
+
|
|
26
|
+
## 安装要求
|
|
27
|
+
|
|
28
|
+
- Python 3.10+ (Windows7不支持)
|
|
29
|
+
- cmd2 库
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
## 快速开始
|
|
33
|
+
|
|
34
|
+
### 运行方式
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
python wtsh.py
|
|
38
|
+
```
|
|
39
|
+
如果安装后运行:
|
|
40
|
+
```bash
|
|
41
|
+
wtsh
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
启动后会显示欢迎信息:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
Welcome to the wtsh shell!wtsh version 26.5.17
|
|
49
|
+
username@/current/directory:platform>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 命令列表
|
|
53
|
+
|
|
54
|
+
### 基础命令
|
|
55
|
+
|
|
56
|
+
| 命令 | 描述 | 示例 |
|
|
57
|
+
|------|------|------|
|
|
58
|
+
| `ls` | 列出当前目录下的文件和文件夹 | `ls` |
|
|
59
|
+
| `cat <file>` | 显示文件内容 | `cat README.md` |
|
|
60
|
+
| `cd <dir>` | 切换目录 | `cd /home/user` |
|
|
61
|
+
| `clear` | 清屏 | `clear` |
|
|
62
|
+
| `exit` | 退出 Shell | `exit` |
|
|
63
|
+
|
|
64
|
+
### 系统信息
|
|
65
|
+
|
|
66
|
+
| 命令 | 描述 |
|
|
67
|
+
|------|------|
|
|
68
|
+
| `aboutus` | 显示 wtsh 版本和系统信息 |
|
|
69
|
+
| `whichcontainer` | 检测当前是否运行在容器环境中 |
|
|
70
|
+
| `restore_prompt` | 还原提示符为默认样式 |
|
|
71
|
+
|
|
72
|
+
## 命令详解
|
|
73
|
+
|
|
74
|
+
### ls
|
|
75
|
+
|
|
76
|
+
列出当前目录下的所有文件和目录:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
username@/home:linux> ls
|
|
80
|
+
Documents
|
|
81
|
+
Downloads
|
|
82
|
+
Desktop
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### cat
|
|
86
|
+
|
|
87
|
+
显示指定文件的内容:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
username@/home:linux> cat example.txt
|
|
91
|
+
Hello, wtsh!
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### cd
|
|
95
|
+
|
|
96
|
+
切换到指定目录:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
username@/home:linux> cd Documents
|
|
100
|
+
username@/home/Documents:linux>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### clear
|
|
104
|
+
|
|
105
|
+
清除终端屏幕内容。
|
|
106
|
+
|
|
107
|
+
### exit
|
|
108
|
+
|
|
109
|
+
退出 wtsh Shell,返回系统命令行。
|
|
110
|
+
|
|
111
|
+
### aboutus
|
|
112
|
+
|
|
113
|
+
显示 wtsh 的版本信息和运行时平台:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
username@/home:linux> aboutus
|
|
117
|
+
wtsh version: 26.5.17
|
|
118
|
+
wtsh plugin protocol version: 7.2.0
|
|
119
|
+
wtsh plugin protocol name: wtsh.plugins
|
|
120
|
+
wtsh plugin protocol platform: entry_points
|
|
121
|
+
wtsh main runtime platform(OS platform): linux
|
|
122
|
+
supported plugin types: entrypoints+cmd2.commandset
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### whichcontainer
|
|
126
|
+
|
|
127
|
+
检测当前运行环境是否为容器,并显示容器运行时和名称:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
username@/home:linux> whichcontainer
|
|
131
|
+
docker my-container
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
支持检测的容器类型:
|
|
135
|
+
- Docker
|
|
136
|
+
- Podman
|
|
137
|
+
- LXC
|
|
138
|
+
- Host(非容器环境)
|
|
139
|
+
|
|
140
|
+
### restore_prompt
|
|
141
|
+
|
|
142
|
+
将提示符恢复为默认样式,移除容器信息显示。
|
|
143
|
+
|
|
144
|
+
## 提示符说明
|
|
145
|
+
|
|
146
|
+
wtsh 的提示符包含以下信息(带颜色):
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
\033[32m{username}\033[0m@\033[34m{current_dir}\033[0m:\033[33m{platform}\033[0m>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
- **绿色**:用户名
|
|
153
|
+
- **蓝色**:当前工作目录
|
|
154
|
+
- **黄色**:操作系统平台
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
## 插件系统
|
|
159
|
+
|
|
160
|
+
wtsh 支持通过插件机制扩展功能,采用 Python `entry_points` 作为插件发现机制。
|
|
161
|
+
|
|
162
|
+
### 插件机制
|
|
163
|
+
|
|
164
|
+
wtsh 在启动时会自动扫描 `wtsh.plugins` 组下的所有 entry points,并动态加载:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
for ep in entry_points(group="wtsh.plugins"):
|
|
168
|
+
ep.load()
|
|
169
|
+
print(f'Loaded plugin {ep.name}')
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 插件协议信息
|
|
173
|
+
|
|
174
|
+
- **插件协议名称**:`wtsh.plugins`
|
|
175
|
+
- **插件协议版本**:7.2.0
|
|
176
|
+
- **插件平台**:`entry_points`
|
|
177
|
+
- **支持的插件类型**:`entrypoints+cmd2.commandset`
|
|
178
|
+
|
|
179
|
+
### 插件加载
|
|
180
|
+
|
|
181
|
+
插件会在 wtsh 启动时自动加载,加载成功后会显示:
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
Loaded plugin plugin_name
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
如果没有找到插件或加载失败,会显示相应的提示信息。
|
|
188
|
+
|
|
189
|
+
## 支持的平台
|
|
190
|
+
|
|
191
|
+
wtsh 可以在以下操作系统上运行:
|
|
192
|
+
|
|
193
|
+
- Linux
|
|
194
|
+
- Windows
|
|
195
|
+
- macOS
|
|
196
|
+
- KaihongOS (只支持在兼容层中安装,不支持直接在KaihongOS上运行,因为KaihongOS没有用户态python环境。之后KaihongOS会逐步开放用户可达的docker)
|
|
197
|
+
|
|
198
|
+
## 许可证
|
|
199
|
+
|
|
200
|
+
Apache License 2.0
|
|
201
|
+
|
|
202
|
+
## 版本历史
|
|
203
|
+
|
|
204
|
+
- **26.5.17**:当前版本,优化whl打包、docker镜像和容器检测功能,容器检测功能移除“自动附加到提示符”以防止信息泄露
|
|
205
|
+
- **26.5.0**:初始版本,包含基础文件操作和容器检测功能
|
wtsh-26.5.17/README.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# wtsh - 基于cmd2的插件化交互式命令行Shell
|
|
2
|
+
|
|
3
|
+
wtsh 是一个基于 Python cmd2 库开发的交互式命令行 Shell,提供了基本的文件系统操作和容器环境检测功能。
|
|
4
|
+
|
|
5
|
+
## 托管仓库
|
|
6
|
+
- [Gitee](https://gitee.com/wazzge/wtsh)
|
|
7
|
+
|
|
8
|
+
## 功能特性
|
|
9
|
+
|
|
10
|
+
- **交互式命令行界面**:基于 cmd2 框架,支持命令自动补全和历史记录
|
|
11
|
+
- **文件系统操作**:支持 ls、cat、cd、clear 等基本命令
|
|
12
|
+
- **容器环境检测**:自动识别 Docker、Podman、LXC 等容器运行时环境
|
|
13
|
+
- **彩色提示符**:显示用户名、当前目录和操作系统平台信息
|
|
14
|
+
|
|
15
|
+
## 安装要求
|
|
16
|
+
|
|
17
|
+
- Python 3.10+ (Windows7不支持)
|
|
18
|
+
- cmd2 库
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## 快速开始
|
|
22
|
+
|
|
23
|
+
### 运行方式
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
python wtsh.py
|
|
27
|
+
```
|
|
28
|
+
如果安装后运行:
|
|
29
|
+
```bash
|
|
30
|
+
wtsh
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
启动后会显示欢迎信息:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
Welcome to the wtsh shell!wtsh version 26.5.17
|
|
38
|
+
username@/current/directory:platform>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 命令列表
|
|
42
|
+
|
|
43
|
+
### 基础命令
|
|
44
|
+
|
|
45
|
+
| 命令 | 描述 | 示例 |
|
|
46
|
+
|------|------|------|
|
|
47
|
+
| `ls` | 列出当前目录下的文件和文件夹 | `ls` |
|
|
48
|
+
| `cat <file>` | 显示文件内容 | `cat README.md` |
|
|
49
|
+
| `cd <dir>` | 切换目录 | `cd /home/user` |
|
|
50
|
+
| `clear` | 清屏 | `clear` |
|
|
51
|
+
| `exit` | 退出 Shell | `exit` |
|
|
52
|
+
|
|
53
|
+
### 系统信息
|
|
54
|
+
|
|
55
|
+
| 命令 | 描述 |
|
|
56
|
+
|------|------|
|
|
57
|
+
| `aboutus` | 显示 wtsh 版本和系统信息 |
|
|
58
|
+
| `whichcontainer` | 检测当前是否运行在容器环境中 |
|
|
59
|
+
| `restore_prompt` | 还原提示符为默认样式 |
|
|
60
|
+
|
|
61
|
+
## 命令详解
|
|
62
|
+
|
|
63
|
+
### ls
|
|
64
|
+
|
|
65
|
+
列出当前目录下的所有文件和目录:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
username@/home:linux> ls
|
|
69
|
+
Documents
|
|
70
|
+
Downloads
|
|
71
|
+
Desktop
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### cat
|
|
75
|
+
|
|
76
|
+
显示指定文件的内容:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
username@/home:linux> cat example.txt
|
|
80
|
+
Hello, wtsh!
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### cd
|
|
84
|
+
|
|
85
|
+
切换到指定目录:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
username@/home:linux> cd Documents
|
|
89
|
+
username@/home/Documents:linux>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### clear
|
|
93
|
+
|
|
94
|
+
清除终端屏幕内容。
|
|
95
|
+
|
|
96
|
+
### exit
|
|
97
|
+
|
|
98
|
+
退出 wtsh Shell,返回系统命令行。
|
|
99
|
+
|
|
100
|
+
### aboutus
|
|
101
|
+
|
|
102
|
+
显示 wtsh 的版本信息和运行时平台:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
username@/home:linux> aboutus
|
|
106
|
+
wtsh version: 26.5.17
|
|
107
|
+
wtsh plugin protocol version: 7.2.0
|
|
108
|
+
wtsh plugin protocol name: wtsh.plugins
|
|
109
|
+
wtsh plugin protocol platform: entry_points
|
|
110
|
+
wtsh main runtime platform(OS platform): linux
|
|
111
|
+
supported plugin types: entrypoints+cmd2.commandset
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### whichcontainer
|
|
115
|
+
|
|
116
|
+
检测当前运行环境是否为容器,并显示容器运行时和名称:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
username@/home:linux> whichcontainer
|
|
120
|
+
docker my-container
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
支持检测的容器类型:
|
|
124
|
+
- Docker
|
|
125
|
+
- Podman
|
|
126
|
+
- LXC
|
|
127
|
+
- Host(非容器环境)
|
|
128
|
+
|
|
129
|
+
### restore_prompt
|
|
130
|
+
|
|
131
|
+
将提示符恢复为默认样式,移除容器信息显示。
|
|
132
|
+
|
|
133
|
+
## 提示符说明
|
|
134
|
+
|
|
135
|
+
wtsh 的提示符包含以下信息(带颜色):
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
\033[32m{username}\033[0m@\033[34m{current_dir}\033[0m:\033[33m{platform}\033[0m>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
- **绿色**:用户名
|
|
142
|
+
- **蓝色**:当前工作目录
|
|
143
|
+
- **黄色**:操作系统平台
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
## 插件系统
|
|
148
|
+
|
|
149
|
+
wtsh 支持通过插件机制扩展功能,采用 Python `entry_points` 作为插件发现机制。
|
|
150
|
+
|
|
151
|
+
### 插件机制
|
|
152
|
+
|
|
153
|
+
wtsh 在启动时会自动扫描 `wtsh.plugins` 组下的所有 entry points,并动态加载:
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
for ep in entry_points(group="wtsh.plugins"):
|
|
157
|
+
ep.load()
|
|
158
|
+
print(f'Loaded plugin {ep.name}')
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### 插件协议信息
|
|
162
|
+
|
|
163
|
+
- **插件协议名称**:`wtsh.plugins`
|
|
164
|
+
- **插件协议版本**:7.2.0
|
|
165
|
+
- **插件平台**:`entry_points`
|
|
166
|
+
- **支持的插件类型**:`entrypoints+cmd2.commandset`
|
|
167
|
+
|
|
168
|
+
### 插件加载
|
|
169
|
+
|
|
170
|
+
插件会在 wtsh 启动时自动加载,加载成功后会显示:
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
Loaded plugin plugin_name
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
如果没有找到插件或加载失败,会显示相应的提示信息。
|
|
177
|
+
|
|
178
|
+
## 支持的平台
|
|
179
|
+
|
|
180
|
+
wtsh 可以在以下操作系统上运行:
|
|
181
|
+
|
|
182
|
+
- Linux
|
|
183
|
+
- Windows
|
|
184
|
+
- macOS
|
|
185
|
+
- KaihongOS (只支持在兼容层中安装,不支持直接在KaihongOS上运行,因为KaihongOS没有用户态python环境。之后KaihongOS会逐步开放用户可达的docker)
|
|
186
|
+
|
|
187
|
+
## 许可证
|
|
188
|
+
|
|
189
|
+
Apache License 2.0
|
|
190
|
+
|
|
191
|
+
## 版本历史
|
|
192
|
+
|
|
193
|
+
- **26.5.17**:当前版本,优化whl打包、docker镜像和容器检测功能,容器检测功能移除“自动附加到提示符”以防止信息泄露
|
|
194
|
+
- **26.5.0**:初始版本,包含基础文件操作和容器检测功能
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "wtsh"
|
|
3
|
+
version = "26.5.17"
|
|
4
|
+
description = "wtsh shell v26"
|
|
5
|
+
dependencies = ["cmd2"]
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
authors = [{name="wazzge",email="2334498769@qq.com"}]
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["setuptools>=61.0","wheel"]
|
|
14
|
+
build-backend = "setuptools.build_meta"
|
|
15
|
+
|
|
16
|
+
[tool.setuptools]
|
|
17
|
+
py-modules = ["wtsh"]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
[project.scripts]
|
|
22
|
+
wtsh = "wtsh:main"
|
wtsh-26.5.17/setup.cfg
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wtsh
|
|
3
|
+
Version: 26.5.17
|
|
4
|
+
Summary: wtsh shell v26
|
|
5
|
+
Author-email: wazzge <2334498769@qq.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: cmd2
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# wtsh - 基于cmd2的插件化交互式命令行Shell
|
|
13
|
+
|
|
14
|
+
wtsh 是一个基于 Python cmd2 库开发的交互式命令行 Shell,提供了基本的文件系统操作和容器环境检测功能。
|
|
15
|
+
|
|
16
|
+
## 托管仓库
|
|
17
|
+
- [Gitee](https://gitee.com/wazzge/wtsh)
|
|
18
|
+
|
|
19
|
+
## 功能特性
|
|
20
|
+
|
|
21
|
+
- **交互式命令行界面**:基于 cmd2 框架,支持命令自动补全和历史记录
|
|
22
|
+
- **文件系统操作**:支持 ls、cat、cd、clear 等基本命令
|
|
23
|
+
- **容器环境检测**:自动识别 Docker、Podman、LXC 等容器运行时环境
|
|
24
|
+
- **彩色提示符**:显示用户名、当前目录和操作系统平台信息
|
|
25
|
+
|
|
26
|
+
## 安装要求
|
|
27
|
+
|
|
28
|
+
- Python 3.10+ (Windows7不支持)
|
|
29
|
+
- cmd2 库
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
## 快速开始
|
|
33
|
+
|
|
34
|
+
### 运行方式
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
python wtsh.py
|
|
38
|
+
```
|
|
39
|
+
如果安装后运行:
|
|
40
|
+
```bash
|
|
41
|
+
wtsh
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
启动后会显示欢迎信息:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
Welcome to the wtsh shell!wtsh version 26.5.17
|
|
49
|
+
username@/current/directory:platform>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 命令列表
|
|
53
|
+
|
|
54
|
+
### 基础命令
|
|
55
|
+
|
|
56
|
+
| 命令 | 描述 | 示例 |
|
|
57
|
+
|------|------|------|
|
|
58
|
+
| `ls` | 列出当前目录下的文件和文件夹 | `ls` |
|
|
59
|
+
| `cat <file>` | 显示文件内容 | `cat README.md` |
|
|
60
|
+
| `cd <dir>` | 切换目录 | `cd /home/user` |
|
|
61
|
+
| `clear` | 清屏 | `clear` |
|
|
62
|
+
| `exit` | 退出 Shell | `exit` |
|
|
63
|
+
|
|
64
|
+
### 系统信息
|
|
65
|
+
|
|
66
|
+
| 命令 | 描述 |
|
|
67
|
+
|------|------|
|
|
68
|
+
| `aboutus` | 显示 wtsh 版本和系统信息 |
|
|
69
|
+
| `whichcontainer` | 检测当前是否运行在容器环境中 |
|
|
70
|
+
| `restore_prompt` | 还原提示符为默认样式 |
|
|
71
|
+
|
|
72
|
+
## 命令详解
|
|
73
|
+
|
|
74
|
+
### ls
|
|
75
|
+
|
|
76
|
+
列出当前目录下的所有文件和目录:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
username@/home:linux> ls
|
|
80
|
+
Documents
|
|
81
|
+
Downloads
|
|
82
|
+
Desktop
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### cat
|
|
86
|
+
|
|
87
|
+
显示指定文件的内容:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
username@/home:linux> cat example.txt
|
|
91
|
+
Hello, wtsh!
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### cd
|
|
95
|
+
|
|
96
|
+
切换到指定目录:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
username@/home:linux> cd Documents
|
|
100
|
+
username@/home/Documents:linux>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### clear
|
|
104
|
+
|
|
105
|
+
清除终端屏幕内容。
|
|
106
|
+
|
|
107
|
+
### exit
|
|
108
|
+
|
|
109
|
+
退出 wtsh Shell,返回系统命令行。
|
|
110
|
+
|
|
111
|
+
### aboutus
|
|
112
|
+
|
|
113
|
+
显示 wtsh 的版本信息和运行时平台:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
username@/home:linux> aboutus
|
|
117
|
+
wtsh version: 26.5.17
|
|
118
|
+
wtsh plugin protocol version: 7.2.0
|
|
119
|
+
wtsh plugin protocol name: wtsh.plugins
|
|
120
|
+
wtsh plugin protocol platform: entry_points
|
|
121
|
+
wtsh main runtime platform(OS platform): linux
|
|
122
|
+
supported plugin types: entrypoints+cmd2.commandset
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### whichcontainer
|
|
126
|
+
|
|
127
|
+
检测当前运行环境是否为容器,并显示容器运行时和名称:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
username@/home:linux> whichcontainer
|
|
131
|
+
docker my-container
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
支持检测的容器类型:
|
|
135
|
+
- Docker
|
|
136
|
+
- Podman
|
|
137
|
+
- LXC
|
|
138
|
+
- Host(非容器环境)
|
|
139
|
+
|
|
140
|
+
### restore_prompt
|
|
141
|
+
|
|
142
|
+
将提示符恢复为默认样式,移除容器信息显示。
|
|
143
|
+
|
|
144
|
+
## 提示符说明
|
|
145
|
+
|
|
146
|
+
wtsh 的提示符包含以下信息(带颜色):
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
\033[32m{username}\033[0m@\033[34m{current_dir}\033[0m:\033[33m{platform}\033[0m>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
- **绿色**:用户名
|
|
153
|
+
- **蓝色**:当前工作目录
|
|
154
|
+
- **黄色**:操作系统平台
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
## 插件系统
|
|
159
|
+
|
|
160
|
+
wtsh 支持通过插件机制扩展功能,采用 Python `entry_points` 作为插件发现机制。
|
|
161
|
+
|
|
162
|
+
### 插件机制
|
|
163
|
+
|
|
164
|
+
wtsh 在启动时会自动扫描 `wtsh.plugins` 组下的所有 entry points,并动态加载:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
for ep in entry_points(group="wtsh.plugins"):
|
|
168
|
+
ep.load()
|
|
169
|
+
print(f'Loaded plugin {ep.name}')
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 插件协议信息
|
|
173
|
+
|
|
174
|
+
- **插件协议名称**:`wtsh.plugins`
|
|
175
|
+
- **插件协议版本**:7.2.0
|
|
176
|
+
- **插件平台**:`entry_points`
|
|
177
|
+
- **支持的插件类型**:`entrypoints+cmd2.commandset`
|
|
178
|
+
|
|
179
|
+
### 插件加载
|
|
180
|
+
|
|
181
|
+
插件会在 wtsh 启动时自动加载,加载成功后会显示:
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
Loaded plugin plugin_name
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
如果没有找到插件或加载失败,会显示相应的提示信息。
|
|
188
|
+
|
|
189
|
+
## 支持的平台
|
|
190
|
+
|
|
191
|
+
wtsh 可以在以下操作系统上运行:
|
|
192
|
+
|
|
193
|
+
- Linux
|
|
194
|
+
- Windows
|
|
195
|
+
- macOS
|
|
196
|
+
- KaihongOS (只支持在兼容层中安装,不支持直接在KaihongOS上运行,因为KaihongOS没有用户态python环境。之后KaihongOS会逐步开放用户可达的docker)
|
|
197
|
+
|
|
198
|
+
## 许可证
|
|
199
|
+
|
|
200
|
+
Apache License 2.0
|
|
201
|
+
|
|
202
|
+
## 版本历史
|
|
203
|
+
|
|
204
|
+
- **26.5.17**:当前版本,优化whl打包、docker镜像和容器检测功能,容器检测功能移除“自动附加到提示符”以防止信息泄露
|
|
205
|
+
- **26.5.0**:初始版本,包含基础文件操作和容器检测功能
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
wtsh.py
|
|
5
|
+
wtsh.egg-info/PKG-INFO
|
|
6
|
+
wtsh.egg-info/SOURCES.txt
|
|
7
|
+
wtsh.egg-info/dependency_links.txt
|
|
8
|
+
wtsh.egg-info/entry_points.txt
|
|
9
|
+
wtsh.egg-info/requires.txt
|
|
10
|
+
wtsh.egg-info/top_level.txt
|
|
11
|
+
wtsh_container/build/lib/wtsh_container/container_information.py
|
|
12
|
+
wtsh_container/wtsh_container/container_information.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cmd2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
wtsh
|
wtsh-26.5.17/wtsh.py
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
import cmd2
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
import subprocess
|
|
7
|
+
from importlib.metadata import entry_points
|
|
8
|
+
import getpass
|
|
9
|
+
from cmd2 import with_default_category
|
|
10
|
+
import importlib
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
#导入commandset模式的插件包
|
|
15
|
+
try:
|
|
16
|
+
for ep in entry_points(group="wtsh.plugins"):
|
|
17
|
+
ep.load()
|
|
18
|
+
print(f'Loaded plugin {ep.name}')
|
|
19
|
+
except ModuleNotFoundError as e:
|
|
20
|
+
print("No plugins found")
|
|
21
|
+
except ImportError as e:
|
|
22
|
+
print(e)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@with_default_category("basic_in_main && wtsh_inner_commands")
|
|
26
|
+
class Wtsh(cmd2.Cmd):
|
|
27
|
+
def __init__(self):
|
|
28
|
+
super().__init__(auto_load_commands=True, include_py=True)
|
|
29
|
+
self.self_in_py=True
|
|
30
|
+
self.intro = "Welcome to the wtsh shell!wtsh version 26.5.17"
|
|
31
|
+
self.prompt = self._prompt()
|
|
32
|
+
|
|
33
|
+
#下一步添加初始化文件支持(用户目录或系统中的.wtshrc)
|
|
34
|
+
def _prompt(self):
|
|
35
|
+
try:
|
|
36
|
+
user = getpass.getuser()
|
|
37
|
+
cwd = os.getcwd()
|
|
38
|
+
# Add ANSI color codes: green for user, blue for cwd, yellow for platform
|
|
39
|
+
return "\033[32m{0}\033[0m@\033[34m{1}\033[0m:\033[33m{2}\033[0m>".format(user, cwd, sys.platform)
|
|
40
|
+
except Exception as e:
|
|
41
|
+
return "(wtsh6)"
|
|
42
|
+
def emptyline(self):
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
def _whether_main_in_venv(self):#检查主程序是否在虚拟环境中运行--未加入提示符.
|
|
46
|
+
"""Check if the current environment is a virtual environment."""
|
|
47
|
+
if sys.prefix != sys.base_prefix:
|
|
48
|
+
return "(venv)"
|
|
49
|
+
return ""
|
|
50
|
+
#右侧提示符,cmd2=4.0.0以上才可用
|
|
51
|
+
#def get_rprompt(self):
|
|
52
|
+
#return sys.platform
|
|
53
|
+
def do_exit(self, args): #容器化场景需要调整
|
|
54
|
+
"""Exit the shell."""
|
|
55
|
+
self.poutput("Bye")
|
|
56
|
+
return True
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def do_aboutus(self,args):
|
|
60
|
+
"""Display information about this shell."""
|
|
61
|
+
wtsh_main_version="26.5.17"
|
|
62
|
+
wtsh_plugin_protocol_version="7.2.0"
|
|
63
|
+
wtsh_plugin_protocol_name="wtsh.plugins"
|
|
64
|
+
wtsh_plugin_protocol_platform="entry_points"
|
|
65
|
+
wtsh_main_runtime_platform=sys.platform
|
|
66
|
+
supported_plugin_types="entrypoints+cmd2.commandset --by cmd2"
|
|
67
|
+
self.poutput(f"wtsh version: {wtsh_main_version}")
|
|
68
|
+
self.poutput(f"wtsh plugin protocol version: {wtsh_plugin_protocol_version}")
|
|
69
|
+
self.poutput(f"wtsh plugin protocol name: {wtsh_plugin_protocol_name}")
|
|
70
|
+
self.poutput(f"wtsh plugin protocol platform: {wtsh_plugin_protocol_platform}")
|
|
71
|
+
self.poutput(f"wtsh main runtime platform(OS platform): {wtsh_main_runtime_platform}")
|
|
72
|
+
self.poutput(f"supported plugin types: {supported_plugin_types}")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def do_ls(self,args):
|
|
79
|
+
"""List all files and directories"""
|
|
80
|
+
try:
|
|
81
|
+
for i in os.listdir('.'):
|
|
82
|
+
self.poutput(i)
|
|
83
|
+
except Exception as e:
|
|
84
|
+
self.perror(str(e))
|
|
85
|
+
|
|
86
|
+
def do_cat(self,args):
|
|
87
|
+
"""Print the content of a file"""
|
|
88
|
+
try:
|
|
89
|
+
with open(args,'r') as f:
|
|
90
|
+
self.poutput(f.read())
|
|
91
|
+
except Exception as e:
|
|
92
|
+
self.perror(str(e))
|
|
93
|
+
def do_cd(self,args):
|
|
94
|
+
"""Change directory"""
|
|
95
|
+
if args:
|
|
96
|
+
try:
|
|
97
|
+
os.chdir(args)
|
|
98
|
+
self.prompt = self._prompt() # 更新提示符
|
|
99
|
+
except Exception as e:
|
|
100
|
+
self.perror(str(e))
|
|
101
|
+
|
|
102
|
+
def do_clear(self,args):
|
|
103
|
+
"""Clear the screen"""
|
|
104
|
+
try:
|
|
105
|
+
print('\033[2J\033[H', end='')
|
|
106
|
+
self.prompt = self._prompt() # 更新提示符
|
|
107
|
+
except Exception as e:
|
|
108
|
+
if os.name=='nt':
|
|
109
|
+
subprocess.run(['cls'],shell=False)
|
|
110
|
+
else:
|
|
111
|
+
subprocess.run(['clear'],shell=False)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
#容器插件需要修改提示符
|
|
115
|
+
def do_whichcontainer(self, args):
|
|
116
|
+
"""获取当前容器的名称"""
|
|
117
|
+
return self._whichcontainer()
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _whichcontainer(self):
|
|
121
|
+
# 获取当前容器的名称
|
|
122
|
+
cgroup=open("/proc/1/cgroup").read() if os.path.exists("/proc/1/cgroup") else ""
|
|
123
|
+
if os.path.exists("/run/.containerenv") or os.path.exists("/var/run/.containerenv") or "libpod" in cgroup:
|
|
124
|
+
runtime="podman"
|
|
125
|
+
|
|
126
|
+
elif "docker" in cgroup:
|
|
127
|
+
runtime="docker"
|
|
128
|
+
elif "lxc" in cgroup:
|
|
129
|
+
runtime="lxc"
|
|
130
|
+
|
|
131
|
+
else:
|
|
132
|
+
runtime="host"
|
|
133
|
+
|
|
134
|
+
try:
|
|
135
|
+
container_name=os.environ.get('HOSTNAME')
|
|
136
|
+
except Exception as e:
|
|
137
|
+
print(e)
|
|
138
|
+
container_name=""
|
|
139
|
+
|
|
140
|
+
whichcontainer=f'{runtime} {container_name}'
|
|
141
|
+
self.poutput(whichcontainer)
|
|
142
|
+
#以下命令很危险--泄露基础设施信息,建议注释掉
|
|
143
|
+
#self.prompt+="\033[32m"+"["+whichcontainer+"]"+"\033[0m"
|
|
144
|
+
|
|
145
|
+
def do_restore_prompt(self,args):
|
|
146
|
+
"""还原提示符"""
|
|
147
|
+
self.prompt=self._prompt()
|
|
148
|
+
|
|
149
|
+
def do_dexec(self,args):
|
|
150
|
+
"""在distrobox容器内执行宿主机命令"""
|
|
151
|
+
if os.getenv("DISTROBOX_ENTER")=="1":
|
|
152
|
+
try:
|
|
153
|
+
result=subprocess.run(["distrobox-host-exec"]+args.split(),shell=False,check=False,text=True,capture_output=True) #在distrobox容器内执行宿主机命令(未测试)
|
|
154
|
+
if result.stdout:
|
|
155
|
+
self.poutput(result.stdout)
|
|
156
|
+
if result.stderr:
|
|
157
|
+
self.perror(result.stderr)
|
|
158
|
+
return result.returncode==0 #是不是字符串0
|
|
159
|
+
except Exception as e:
|
|
160
|
+
self.perror(str(e))
|
|
161
|
+
return False
|
|
162
|
+
else:
|
|
163
|
+
self.perror("You are not in a distrobox container,this command only work in distrobox container.")
|
|
164
|
+
return False
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
#主程序执行
|
|
170
|
+
def main():
|
|
171
|
+
app = Wtsh()
|
|
172
|
+
app.cmdloop()
|
|
173
|
+
if __name__ == '__main__':
|
|
174
|
+
main()
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import cmd2
|
|
2
|
+
from cmd2 import CommandSet, with_argparser,with_default_category
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
import os
|
|
6
|
+
import getpass
|
|
7
|
+
@with_default_category("container_infomation")
|
|
8
|
+
class container_info(CommandSet):
|
|
9
|
+
def __init__(self):
|
|
10
|
+
super().__init__()
|
|
11
|
+
# 最简单实现:修改主程序提示符
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def do_container_info_version(self, args):
|
|
15
|
+
self._cmd.poutput("1.0")
|
|
16
|
+
|
|
17
|
+
def do_whichcontainer(self, args):
|
|
18
|
+
# 获取当前容器的名称
|
|
19
|
+
cgroup=open("/proc/1/cgroup").read() if os.path.exists("/proc/1/cgroup") else ""
|
|
20
|
+
if "docker" in cgroup:
|
|
21
|
+
runtime="docker"
|
|
22
|
+
elif "lxc" in cgroup:
|
|
23
|
+
runtime="lxc"
|
|
24
|
+
elif "podman" in cgroup:
|
|
25
|
+
runtime="podman"
|
|
26
|
+
|
|
27
|
+
else:
|
|
28
|
+
runtime="host"
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
container_name=os.environ.get('HOSTNAME')
|
|
32
|
+
except Exception as e:
|
|
33
|
+
print(e)
|
|
34
|
+
container_name=""
|
|
35
|
+
|
|
36
|
+
whichcontainer=f'{runtime} {container_name}'
|
|
37
|
+
self._cmd.poutput(whichcontainer)
|
|
38
|
+
return whichcontainer
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _whichcontainer(self):
|
|
42
|
+
# 获取当前容器的名称
|
|
43
|
+
cgroup=open("/proc/1/cgroup").read() if os.path.exists("/proc/1/cgroup") else ""
|
|
44
|
+
if "docker" in cgroup:
|
|
45
|
+
runtime="docker"
|
|
46
|
+
elif "lxc" in cgroup:
|
|
47
|
+
runtime="lxc"
|
|
48
|
+
elif "podman" in cgroup:
|
|
49
|
+
runtime="podman"
|
|
50
|
+
|
|
51
|
+
else:
|
|
52
|
+
runtime="host"
|
|
53
|
+
|
|
54
|
+
try:
|
|
55
|
+
container_name=os.environ.get('HOSTNAME')
|
|
56
|
+
except Exception as e:
|
|
57
|
+
print(e)
|
|
58
|
+
container_name=""
|
|
59
|
+
|
|
60
|
+
whichcontainer=f'{runtime} {container_name}'
|
|
61
|
+
self._cmd.poutput(whichcontainer)
|
|
62
|
+
return whichcontainer
|
|
63
|
+
|
|
64
|
+
def get_prompt(self):
|
|
65
|
+
cinfo=self._whichcontainer()
|
|
66
|
+
return f"[{cinfo}] {self.prompt}" if cinfo != "" else self.prompt
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import cmd2
|
|
2
|
+
from cmd2 import CommandSet, with_argparser,with_default_category
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
import os
|
|
6
|
+
import getpass
|
|
7
|
+
@with_default_category("container_infomation")
|
|
8
|
+
class container_info(CommandSet):
|
|
9
|
+
def __init__(self):
|
|
10
|
+
super().__init__()
|
|
11
|
+
# 最简单实现:修改主程序提示符
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def do_container_info_version(self, args):
|
|
15
|
+
self._cmd.poutput("1.0")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|