python-startfile 0.0.1__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.
|
@@ -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,30 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "python-startfile"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "Python startfile."
|
|
5
|
+
authors = ["ChenyangGao <wosiwujm@gmail.com>"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "readme.md"
|
|
8
|
+
homepage = "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-startfile"
|
|
9
|
+
repository = "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-startfile"
|
|
10
|
+
keywords = ["startfile"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"License :: OSI Approved :: MIT License",
|
|
13
|
+
"Development Status :: 5 - Production/Stable",
|
|
14
|
+
"Programming Language :: Python",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Topic :: Software Development",
|
|
18
|
+
"Topic :: Software Development :: Libraries",
|
|
19
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
20
|
+
]
|
|
21
|
+
include = [
|
|
22
|
+
"LICENSE",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[build-system]
|
|
26
|
+
requires = ["poetry-core"]
|
|
27
|
+
build-backend = "poetry.core.masonry.api"
|
|
28
|
+
|
|
29
|
+
[[tool.poetry.packages]]
|
|
30
|
+
include = "startfile.py"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Python startfile.
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
You can install via [pypi](https://pypi.org/project/python-startfile/)
|
|
6
|
+
|
|
7
|
+
```console
|
|
8
|
+
pip install -U python-startfile
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Module
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
>>> from startfile import startfile, startfile_async
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Commad
|
|
20
|
+
|
|
21
|
+
```console
|
|
22
|
+
$ python -m startfile -h
|
|
23
|
+
usage: startfile.py [-h] [-v] [path ...]
|
|
24
|
+
|
|
25
|
+
Start file(s) with its/their associated application.
|
|
26
|
+
|
|
27
|
+
positional arguments:
|
|
28
|
+
path paths to files or directories
|
|
29
|
+
|
|
30
|
+
options:
|
|
31
|
+
-h, --help show this help message and exit
|
|
32
|
+
-v, --version print the current version
|
|
33
|
+
```
|
|
@@ -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
|
+
|