python-startfile 0.0.1__py2.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.
LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ChenyangGao <https://github.com/ChenyangGao>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ChenyangGao <https://github.com/ChenyangGao>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.1
2
+ Name: python-startfile
3
+ Version: 0.0.1
4
+ Summary: Python startfile.
5
+ Home-page: https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-startfile
6
+ License: MIT
7
+ Keywords: startfile
8
+ Author: ChenyangGao
9
+ Author-email: wosiwujm@gmail.com
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 2
16
+ Classifier: Programming Language :: Python :: 2.7
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.4
19
+ Classifier: Programming Language :: Python :: 3.5
20
+ Classifier: Programming Language :: Python :: 3.6
21
+ Classifier: Programming Language :: Python :: 3.7
22
+ Classifier: Programming Language :: Python :: 3.8
23
+ Classifier: Programming Language :: Python :: 3.9
24
+ Classifier: Programming Language :: Python :: 3.10
25
+ Classifier: Programming Language :: Python :: 3.11
26
+ Classifier: Programming Language :: Python :: 3.12
27
+ Classifier: Topic :: Software Development
28
+ Classifier: Topic :: Software Development :: Libraries
29
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
30
+ Project-URL: Repository, https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-startfile
31
+ Description-Content-Type: text/markdown
32
+
33
+ # Python startfile.
34
+
35
+ ## Installation
36
+
37
+ You can install via [pypi](https://pypi.org/project/python-startfile/)
38
+
39
+ ```console
40
+ pip install -U python-startfile
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ ### Module
46
+
47
+ ```python
48
+ >>> from startfile import startfile, startfile_async
49
+ ```
50
+
51
+ ### Commad
52
+
53
+ ```console
54
+ $ python -m startfile -h
55
+ usage: startfile.py [-h] [-v] [path ...]
56
+
57
+ Start file(s) with its/their associated application.
58
+
59
+ positional arguments:
60
+ path paths to files or directories
61
+
62
+ options:
63
+ -h, --help show this help message and exit
64
+ -v, --version print the current version
65
+ ```
66
+
@@ -0,0 +1,6 @@
1
+ LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
2
+ startfile.py,sha256=UdJle55LQvbSS9UVlmA-YiSzdItEk3lpKwQu3JJ4k8k,2290
3
+ python_startfile-0.0.1.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
4
+ python_startfile-0.0.1.dist-info/METADATA,sha256=smGHG8DLb3wTKv9gCg8ecai-bp_MH3x9yBPbTbRv3qg,2004
5
+ python_startfile-0.0.1.dist-info/WHEEL,sha256=5cEDLREhpnNYpDlijc02-Q_4r7AkXMYW6R1JITTLLOQ,92
6
+ python_startfile-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 1.8.1
3
+ Root-Is-Purelib: true
4
+ Tag: py2.py3-none-any
startfile.py ADDED
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env python3
2
+ # coding: utf-8
3
+
4
+ __author__ = "ChenyangGao <https://chenyanggao.github.io>"
5
+ __version__ = (0, 0, 1)
6
+ __all__ = ["startfile", "startfile_async"]
7
+
8
+ if __name__ == "__main__":
9
+ from argparse import ArgumentParser, RawTextHelpFormatter
10
+
11
+ parser = ArgumentParser(
12
+ description="Start file(s) with its/their associated application.",
13
+ formatter_class=RawTextHelpFormatter,
14
+ )
15
+ parser.add_argument("paths", nargs="*", metavar="path", help="paths to files or directories")
16
+ parser.add_argument("-v", "--version", action="store_true", help="print the current version")
17
+
18
+ args = parser.parse_args()
19
+ if args.version:
20
+ print(".".join(map(str, __version__)))
21
+ raise SystemExit(0)
22
+ paths = args.paths
23
+ if not paths:
24
+ parser.parse_args(["-h"])
25
+
26
+ try:
27
+ from os import startfile
28
+ except ImportError:
29
+ from asyncio import create_subprocess_exec, create_subprocess_shell
30
+ from platform import system
31
+ from subprocess import run
32
+
33
+ async def run_command(command):
34
+ if isinstance(command, str):
35
+ process = await create_subprocess_shell(command)
36
+ else:
37
+ process = await create_subprocess_exec(*command)
38
+ await process.communicate()
39
+
40
+ match system():
41
+ case "Linux":
42
+ def startfile(path, /, *args):
43
+ run(["xdg-open", path, *args])
44
+ async def startfile_async(path, /, *args):
45
+ await run_command(["xdg-open", path, *args])
46
+ case "Darwin":
47
+ def startfile(path, /, *args):
48
+ run(["open", path, *args])
49
+ async def startfile_async(path, /, *args):
50
+ await run_command(["open", path, *args])
51
+ case "Windows":
52
+ def startfile(path, /, *args):
53
+ run(["start", path, *args])
54
+ async def startfile_async(path, /, *args):
55
+ await run_command(["start", path, *args])
56
+ case _:
57
+ raise RuntimeError("can't get startfile")
58
+ else:
59
+ from asyncio import to_thread
60
+ from functools import wraps
61
+
62
+ @wraps(startfile)
63
+ async def startfile_aysnc(*args, **kwds):
64
+ return await to_thread(startfile, *args, **kwds)
65
+
66
+
67
+ if __name__ == "__main__":
68
+ for path in paths:
69
+ startfile(path)
70
+