funshell 1.0.2__py3-none-any.whl

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.
__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ """
2
+ 执行shell
3
+ """
4
+
5
+ from .run import run_shell, run_shell_list
6
+
7
+ __all__ = ["run_shell", "run_shell_list"]
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: funshell
3
+ Version: 1.0.2
4
+ Summary: funshell
5
+ Author-email: 牛哥 <niuliangtao@qq.com>, farfarfun <farfarfun@qq.com>
6
+ Maintainer-email: 牛哥 <niuliangtao@qq.com>, farfarfun <farfarfun@qq.com>
7
+ Project-URL: Organization, https://github.com/farfarfun
8
+ Project-URL: Repository, https://github.com/farfarfun/funshell
9
+ Project-URL: Releases, https://github.com/farfarfun/funshell/releases
10
+ Requires-Python: >=3.6
11
+ Description-Content-Type: text/markdown
12
+
13
+ # funshell
@@ -0,0 +1,7 @@
1
+ __init__.py,sha256=AtEC-Lx18X6Ykn-U00hBsainBjDEdgNZsaARN4pyql0,107
2
+ run/__init__.py,sha256=DfT73qTQfSYnRNMSO5jZgHdb4cztKAJ_leoVq4aKd8g,108
3
+ run/core.py,sha256=bqs24dAqcEyssUSEFJMs6K83r-hqFpks34j6W__RvUc,1202
4
+ funshell-1.0.2.dist-info/METADATA,sha256=GbejpI8PpxZ4GmNIQBVHvEf6hcuXxp1MCqB2bNB6yLU,482
5
+ funshell-1.0.2.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
6
+ funshell-1.0.2.dist-info/top_level.txt,sha256=P0axbid9mrJNPFcHQEu0jGy2UKwobBP4D607Zo587ZQ,13
7
+ funshell-1.0.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ __init__
2
+ run
run/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ """
2
+ 执行shell
3
+ """
4
+
5
+ from .core import run_shell, run_shell_list
6
+
7
+ __all__ = ["run_shell", "run_shell_list"]
run/core.py ADDED
@@ -0,0 +1,42 @@
1
+ import subprocess
2
+ import sys
3
+
4
+
5
+ def run_shell(command: str, printf=True) -> str:
6
+ """
7
+ 执行shell命令
8
+ """
9
+ if printf:
10
+ try:
11
+ cmd = subprocess.Popen(
12
+ command,
13
+ stdin=subprocess.PIPE,
14
+ stderr=sys.stderr,
15
+ close_fds=True,
16
+ stdout=sys.stdout,
17
+ universal_newlines=True,
18
+ shell=True,
19
+ bufsize=1,
20
+ )
21
+ cmd.communicate()
22
+ return str(cmd.returncode)
23
+ except Exception as e:
24
+ return f"run shell error:{e}"
25
+ else:
26
+ try:
27
+ outputs = subprocess.Popen(
28
+ command, stdout=subprocess.PIPE, shell=True
29
+ ).communicate()
30
+ outputs = [i.decode("utf-8")[:-1] for i in outputs if i is not None]
31
+ outputs = [i for i in outputs if len(i.strip()) > 0]
32
+ return "".join(outputs)
33
+ except Exception as e:
34
+ return f"run shell error:{e}"
35
+
36
+
37
+ def run_shell_list(command_list: list[str], printf=True) -> str:
38
+ """
39
+ 批量执行shell命令
40
+ """
41
+ command = " && ".join(command_list)
42
+ return run_shell(command, printf=printf)