dekshell 0.2.0__py3-none-any.whl → 0.2.1__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.
@@ -1,4 +1,5 @@
1
1
  import os
2
+ import shutil
2
3
  import sys
3
4
  import tempfile
4
5
  import getpass
@@ -17,10 +18,12 @@ from dektools.download import download_from_http
17
18
  from dektools.ps.process import process_detail, process_kill, process_list_all
18
19
  from dektools.time import now
19
20
  from dektools.str import shlex_split, shlex_quote
21
+ from dektools.shell import shell_wrapper, is_user_admin
20
22
  from ...utils.beep import sound_notify
21
23
  from ..markers.base.core import MarkerBase, get_inner_vars
22
24
  from ..markers.invoke import InvokeMarker, GotoMarker
23
25
  from ..redirect import search_bin_by_path_tree
26
+ from .properties import current_os
24
27
 
25
28
 
26
29
  def _is_true(x):
@@ -103,6 +106,26 @@ def _xeval(expression, default=_xeval_default, translate=False):
103
106
  return default
104
107
 
105
108
 
109
+ def _install(name):
110
+ def posix(exe):
111
+ s = f"{exe} install -y {name}"
112
+ if is_user_admin():
113
+ s = 'sudo ' + command
114
+ return s
115
+
116
+ if shutil.which('apt-get'):
117
+ command = posix('apt-get')
118
+ elif shutil.which('yum'):
119
+ command = posix('yum')
120
+ elif shutil.which('brew'):
121
+ command = f"brew install {name}"
122
+ elif shutil.which('choco'):
123
+ command = f"choco install -y {name}"
124
+ else:
125
+ raise FileNotFoundError(f"Can't find a valid installer to install {name}")
126
+ shell_wrapper(command)
127
+
128
+
106
129
  path_common_methods = {
107
130
  'cd': os.chdir,
108
131
  'cwd': lambda: os.getcwd(),
@@ -122,6 +145,7 @@ default_methods = {
122
145
  'o2s': obj2str,
123
146
  'now': now,
124
147
  'getpass': getpass.getpass,
148
+ 'install': _install,
125
149
  'Path': Path,
126
150
  'path': {
127
151
  **path_common_methods,
@@ -2,15 +2,21 @@ import os
2
2
  import sys
3
3
  import shutil
4
4
  import tempfile
5
+ import sysconfig
6
+ import platform
5
7
  from pathlib import Path
6
8
  from sysconfig import get_paths
7
9
  from importlib import metadata
10
+ from extra_platforms import current_os as extra_platforms_current_os
8
11
  from dektools.module import ModuleProxy
9
12
  from dektools.time import DateTime
13
+ from dektools.file import read_text
10
14
  from ...utils.serializer import serializer
11
15
  from ..redirect import shell_name
12
16
 
13
17
  current_shell = shutil.which(shell_name, path=get_paths()['scripts'])
18
+ current_os = extra_platforms_current_os()
19
+ user_is_root = "posix" in os.name and os.geteuid() == 0
14
20
 
15
21
 
16
22
  def make_shell_properties(shell):
@@ -54,6 +60,16 @@ default_properties = {
54
60
  'win': is_on_win,
55
61
  'ps': os.pathsep,
56
62
  },
63
+ 'platform': {
64
+ 'cygwin': sys.platform == 'cygwin',
65
+ 'mingw': sysconfig.get_platform() == 'mingw',
66
+ 'msys': sys.platform == 'msys',
67
+ 'wsl': 'Microsoft' in read_text('/proc/version', default=''),
68
+ 'win': platform.system() == 'Windows',
69
+ 'mac': platform.system() == 'Darwin',
70
+ 'linux': platform.system() == 'Linux',
71
+ 'x': current_os,
72
+ },
57
73
  'path': {
58
74
  'root': Path(path_root),
59
75
  'home': Path(path_home),
@@ -1,10 +1,11 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dekshell
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Author-Email: sanzenwin <sanzenwin@gmail.com>
5
5
  License: MIT
6
6
  Requires-Python: >=3.8
7
7
  Requires-Dist: packaging<=23.1
8
+ Requires-Dist: extra-platforms<=3.1.0
8
9
  Requires-Dist: dektools[date,fetch,ps,tab]<1.0.0
9
10
  Requires-Dist: dekmedia[audio]<1.0.0
10
11
  Description-Content-Type: text/markdown
@@ -1,13 +1,13 @@
1
- dekshell-0.2.0.dist-info/METADATA,sha256=UNL_okQfODZUDKq426dmTCFXn9Th_HHFPXun-j0hUKo,527
2
- dekshell-0.2.0.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
- dekshell-0.2.0.dist-info/entry_points.txt,sha256=d-kbfULiUTZWIBBsrQF3J_-wESncF-4K2rwHT08grlI,75
1
+ dekshell-0.2.1.dist-info/METADATA,sha256=0jGedm9N3S639uZTygfJFhKUKA6Q_5LxEvPcZ5Tk8iA,565
2
+ dekshell-0.2.1.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
3
+ dekshell-0.2.1.dist-info/entry_points.txt,sha256=d-kbfULiUTZWIBBsrQF3J_-wESncF-4K2rwHT08grlI,75
4
4
  dekshell/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  dekshell/click/__entry__.py,sha256=CMuxUzXoEe4TcHFZwv-MNFwHnu1HSZCDpXFpqQ814uM,42
6
6
  dekshell/click/__init__.py,sha256=rFzB_exzPQaIcbbms5PdHAU3NGdl2MBaYbq9v7g7BOI,1870
7
7
  dekshell/core/__init__.py,sha256=Cp--1j2jpJzchXR98HiRp2QAiOHz8HXm8iy6ZChIWmc,5207
8
8
  dekshell/core/contexts/__init__.py,sha256=ynsfv37azOKfI2UKd0iPl2M6iBW-k5cb1BqSLOWuJpI,482
9
- dekshell/core/contexts/methods.py,sha256=UNJ20SFGeAhnso7ACc0whOVMB9DAFfz6LeV7s7bLcpc,5684
10
- dekshell/core/contexts/properties.py,sha256=aLHtyUWedbFPQw33V5vQZTc4TeLMTC-AO6e7PhBZKbk,1570
9
+ dekshell/core/contexts/methods.py,sha256=x2htk99DWVj6pR1HS5KPXGIG7t60xA1MXJi8SsOyTpw,6372
10
+ dekshell/core/contexts/properties.py,sha256=e_QRqH7nflvCT14BD9z6_dg9KVMXkRNtVjE11wBFqFM,2204
11
11
  dekshell/core/markers/__init__.py,sha256=bmGMbZRqsOohMKjH0AReFxZ-nIPFF6YgPJMFT6gTJEw,1725
12
12
  dekshell/core/markers/base/__init__.py,sha256=AQYr7H0F06izu5jhu8EgLYJ2ERzJh0eS38h9gtl6OZs,13067
13
13
  dekshell/core/markers/base/core.py,sha256=99aRcSXohpfTW5OSO1CUyvnptr21ueKjizCk-FK6rcM,10830
@@ -36,4 +36,4 @@ dekshell/utils/cmd.py,sha256=_WG7K-CO-WQkI9ERyrhI2d4yT-DX3OjjJWbNzhmsPus,1197
36
36
  dekshell/utils/pkg.py,sha256=TgYqRqawoJfjkxt6UAHnp9ttmpjuHiWRFbqxADOS1VE,1337
37
37
  dekshell/utils/serializer.py,sha256=aIdF2Wzo-qHmIshv46jn1XD0X66vQ1JFdU-g3ZFbH2w,386
38
38
  dekshell/utils/shell.py,sha256=0NoA2-SOOMinbmZZipwzL-npBbzPOdWEfdPVYqq5G5g,92
39
- dekshell-0.2.0.dist-info/RECORD,,
39
+ dekshell-0.2.1.dist-info/RECORD,,