xulbux 1.6.1__py3-none-any.whl → 1.6.3__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.
Potentially problematic release.
This version of xulbux might be problematic. Click here for more details.
- xulbux/__init__.py +1 -1
- xulbux/_consts_.py +18 -18
- xulbux/xx_color.py +102 -92
- xulbux/xx_console.py +0 -12
- xulbux/xx_env_path.py +1 -1
- xulbux/xx_format_codes.py +219 -95
- xulbux/xx_regex.py +41 -30
- xulbux/xx_system.py +53 -1
- {xulbux-1.6.1.dist-info → xulbux-1.6.3.dist-info}/METADATA +15 -15
- xulbux-1.6.3.dist-info/RECORD +21 -0
- xulbux-1.6.1.dist-info/RECORD +0 -21
- {xulbux-1.6.1.dist-info → xulbux-1.6.3.dist-info}/LICENSE +0 -0
- {xulbux-1.6.1.dist-info → xulbux-1.6.3.dist-info}/WHEEL +0 -0
- {xulbux-1.6.1.dist-info → xulbux-1.6.3.dist-info}/entry_points.txt +0 -0
- {xulbux-1.6.1.dist-info → xulbux-1.6.3.dist-info}/top_level.txt +0 -0
xulbux/xx_system.py
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
import subprocess as _subprocess
|
|
2
2
|
import platform as _platform
|
|
3
|
+
import ctypes as _ctypes
|
|
3
4
|
import time as _time
|
|
4
5
|
import sys as _sys
|
|
5
6
|
import os as _os
|
|
6
7
|
|
|
7
8
|
|
|
9
|
+
class ProcessNotFoundError(Exception):
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
|
|
8
13
|
class System:
|
|
9
14
|
|
|
15
|
+
@staticmethod
|
|
16
|
+
def is_elevated() -> bool:
|
|
17
|
+
"""Returns `True` if the current user is an admin and `False` otherwise."""
|
|
18
|
+
try:
|
|
19
|
+
if _os.name == "nt":
|
|
20
|
+
return _ctypes.windll.shell32.IsUserAnAdmin() != 0
|
|
21
|
+
elif _os.name == "posix":
|
|
22
|
+
return _os.geteuid() == 0
|
|
23
|
+
except:
|
|
24
|
+
pass
|
|
25
|
+
return False
|
|
26
|
+
|
|
10
27
|
@staticmethod
|
|
11
28
|
def restart(
|
|
12
29
|
prompt: object = None,
|
|
@@ -24,7 +41,7 @@ class System:
|
|
|
24
41
|
if not force:
|
|
25
42
|
output = _subprocess.check_output("tasklist", shell=True).decode()
|
|
26
43
|
processes = [line.split()[0] for line in output.splitlines()[3:] if line.strip()]
|
|
27
|
-
if len(processes) > 2: # EXCLUDING THE PYTHON PROCESS AND
|
|
44
|
+
if len(processes) > 2: # EXCLUDING THE PYTHON PROCESS AND CONSOLE
|
|
28
45
|
raise RuntimeError("Processes are still running. Use the parameter `force=True` to restart anyway.")
|
|
29
46
|
if prompt:
|
|
30
47
|
_os.system(f'shutdown /r /t {wait} /c "{prompt}"')
|
|
@@ -83,3 +100,38 @@ class System:
|
|
|
83
100
|
return None
|
|
84
101
|
except _subprocess.CalledProcessError:
|
|
85
102
|
return missing
|
|
103
|
+
|
|
104
|
+
@staticmethod
|
|
105
|
+
def elevate(win_title: str | None = None, args: list | None = None) -> bool:
|
|
106
|
+
"""Attempts to start a new process with elevated privileges.\n
|
|
107
|
+
---------------------------------------------------------------------------------
|
|
108
|
+
The param `win_title` is window the title of the elevated process.
|
|
109
|
+
The param `args` is the arguments to be passed to the elevated process.\n
|
|
110
|
+
After the elevated process started, the original process will exit.
|
|
111
|
+
This means, that this method has to be run at the beginning of the program or
|
|
112
|
+
will have to continue in a new window after elevation.\n
|
|
113
|
+
---------------------------------------------------------------------------------
|
|
114
|
+
Returns `True` if the current process already has elevated privileges and raises
|
|
115
|
+
a `PermissionError` if the user denied the elevation or the elevation failed."""
|
|
116
|
+
if System.is_elevated():
|
|
117
|
+
return True
|
|
118
|
+
if _os.name == "nt": # WINDOWS
|
|
119
|
+
if win_title:
|
|
120
|
+
args_str = f'-c "import ctypes; ctypes.windll.kernel32.SetConsoleTitleW(\\"{win_title}\\"); exec(open(\\"{_sys.argv[0]}\\").read())" {" ".join(args)}"'
|
|
121
|
+
else:
|
|
122
|
+
args_str = f'-c "exec(open(\\"{_sys.argv[0]}\\").read())" {" ".join(args)}'
|
|
123
|
+
result = _ctypes.windll.shell32.ShellExecuteW(None, "runas", _sys.executable, args_str, None, 1)
|
|
124
|
+
if result <= 32:
|
|
125
|
+
raise PermissionError("Failed to launch elevated process.")
|
|
126
|
+
else:
|
|
127
|
+
_sys.exit(0)
|
|
128
|
+
else: # POSIX
|
|
129
|
+
cmd = ["pkexec"]
|
|
130
|
+
if win_title:
|
|
131
|
+
cmd.extend(["--description", win_title])
|
|
132
|
+
cmd.extend([_sys.executable] + _sys.argv[1:] + ([] if args is None else args))
|
|
133
|
+
proc = _subprocess.Popen(cmd)
|
|
134
|
+
proc.wait()
|
|
135
|
+
if proc.returncode != 0:
|
|
136
|
+
raise PermissionError("Process elevation was denied.")
|
|
137
|
+
_sys.exit(0)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: xulbux
|
|
3
|
-
Version: 1.6.
|
|
3
|
+
Version: 1.6.3
|
|
4
4
|
Summary: A library which includes a lot of really helpful functions.
|
|
5
5
|
Author-email: XulbuX <xulbux.real@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -31,7 +31,7 @@ Project-URL: Documentation, https://github.com/XulbuX-dev/PythonLibraryXulbuX/wi
|
|
|
31
31
|
Project-URL: Homepage, https://github.com/XulbuX-dev/PythonLibraryXulbuX
|
|
32
32
|
Project-URL: License, https://github.com/XulbuX-dev/PythonLibraryXulbuX/blob/main/LICENSE
|
|
33
33
|
Project-URL: Source Code, https://github.com/XulbuX-dev/PythonLibraryXulbuX/tree/main/src
|
|
34
|
-
Keywords: xulbux,python,library,utility,helper,functions,tools,classes,types,methods,cmd,code,color,data,structures,env,environment,file,format,json,path,regex,string,system,operations,presets
|
|
34
|
+
Keywords: xulbux,python,library,utility,helper,functions,tools,classes,types,methods,cmd,console,code,color,data,structures,env,environment,file,format,json,path,regex,string,system,operations,presets
|
|
35
35
|
Classifier: Intended Audience :: Developers
|
|
36
36
|
Classifier: Programming Language :: Python :: 3
|
|
37
37
|
Classifier: Programming Language :: Python :: 3.10
|
|
@@ -89,19 +89,19 @@ from xulbux import rgba, hsla, hexa
|
|
|
89
89
|
# Modules
|
|
90
90
|
|
|
91
91
|
| | |
|
|
92
|
-
|
|
|
93
|
-
| <h3>[`xx_code`](https://github.com/XulbuX-dev/PythonLibraryXulbuX/wiki/xx_code)</h3>
|
|
94
|
-
| <h3>[`xx_color`](https://github.com/XulbuX-dev/PythonLibraryXulbuX/wiki/xx_color)</h3>
|
|
95
|
-
| <h3>[`xx_console`](https://github.com/XulbuX-dev/PythonLibraryXulbuX/wiki/xx_console)</h3>
|
|
96
|
-
| <h3>[`xx_data`](https://github.com/XulbuX-dev/PythonLibraryXulbuX/wiki/xx_data)</h3>
|
|
97
|
-
| <h3>[`xx_env_path`](https://github.com/XulbuX-dev/PythonLibraryXulbuX/wiki/xx_env_path)</h3>
|
|
98
|
-
| <h3
|
|
99
|
-
| <h3
|
|
100
|
-
| <h3>`xx_json`</h3>
|
|
101
|
-
| <h3>`xx_path`</h3>
|
|
102
|
-
| <h3>`xx_regex`</h3>
|
|
103
|
-
| <h3>[`xx_string`](https://github.com/XulbuX-dev/PythonLibraryXulbuX/wiki/xx_string)</h3>
|
|
104
|
-
| <h3>`xx_system`</h3>
|
|
92
|
+
| :--------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------- |
|
|
93
|
+
| <h3>[`xx_code`](https://github.com/XulbuX-dev/PythonLibraryXulbuX/wiki/xx_code)</h3> | advanced code-string operations (*changing the indent, finding function calls, ...*) |
|
|
94
|
+
| <h3>[`xx_color`](https://github.com/XulbuX-dev/PythonLibraryXulbuX/wiki/xx_color)</h3> | everything around colors (*converting, blending, searching colors in strings, ...*) |
|
|
95
|
+
| <h3>[`xx_console`](https://github.com/XulbuX-dev/PythonLibraryXulbuX/wiki/xx_console)</h3> | advanced actions related to the console (*pretty logging, advanced inputs, ...*) |
|
|
96
|
+
| <h3>[`xx_data`](https://github.com/XulbuX-dev/PythonLibraryXulbuX/wiki/xx_data)</h3> | advanced operations with data structures (*compare, generate path ID's, pretty print/format, ...*) |
|
|
97
|
+
| <h3>[`xx_env_path`](https://github.com/XulbuX-dev/PythonLibraryXulbuX/wiki/xx_env_path)</h3> | getting and editing the PATH variable (*get paths, check for paths, add paths, ...*) |
|
|
98
|
+
| <h3>[`xx_file`](https://github.com/XulbuX-dev/PythonLibraryXulbuX/wiki/xx_file)</h3> | advanced working with files (*create files, rename file-extensions, ...*) |
|
|
99
|
+
| <h3>[`xx_format_codes`](https://github.com/XulbuX-dev/PythonLibraryXulbuX/wiki/xx_format_codes)</h3> | easy pretty printing with custom format codes (*print, inputs, custom format codes to ANSI, ...*) |
|
|
100
|
+
| <h3>`xx_json`</h3> | advanced working with json files (*read, create, update, ...*) |
|
|
101
|
+
| <h3>`xx_path`</h3> | advanced path operations (*get paths, smart-extend relative paths, delete paths, ...*) |
|
|
102
|
+
| <h3>`xx_regex`</h3> | generated regex pattern-templates (*match bracket- and quote pairs, match colors, ...*) |
|
|
103
|
+
| <h3>[`xx_string`](https://github.com/XulbuX-dev/PythonLibraryXulbuX/wiki/xx_string)</h3> | helpful actions when working with strings. (*normalize, escape, decompose, ...*) |
|
|
104
|
+
| <h3>`xx_system`</h3> | advanced system actions (*restart with message, check installed Python libs, ...*) |
|
|
105
105
|
|
|
106
106
|
|
|
107
107
|
<br>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
xulbux/__init__.py,sha256=h83nzup1ahYhyQLejyU2uA3Ddb-gDTkGeQh6vV1naL0,1658
|
|
2
|
+
xulbux/_cli_.py,sha256=U25ZrtpQgpKXtvOSTBBbh7-AJ_WTeZ95A66DQARAqzo,3558
|
|
3
|
+
xulbux/_consts_.py,sha256=0JWj691rOojP8KKE_AJpF8O5WwMRJH4fAvzkwLXd1VM,4591
|
|
4
|
+
xulbux/xx_code.py,sha256=yBP5WxCxNxjBiS6nVAmUBJpD0hX6fgnh5RWq-NmrnaY,5222
|
|
5
|
+
xulbux/xx_color.py,sha256=cDlgrekH88ZEBj8leIIlJbYzsf1RdS8RW3oGvuUfvC0,45129
|
|
6
|
+
xulbux/xx_console.py,sha256=rd31686X9eXB8__lcLaV7unWzIdXGM2yMOt9zNCsGbs,15079
|
|
7
|
+
xulbux/xx_data.py,sha256=OEKLbI1XeNTrittdz3s3mvQk8YrBoSovj9O1H-b7ArY,25844
|
|
8
|
+
xulbux/xx_env_path.py,sha256=iv3Jw0TsNDbbL_NySnazvIP9Iv9swymhiJIr2B3EG8k,4388
|
|
9
|
+
xulbux/xx_file.py,sha256=-58YnqKvrs5idIF91UzEki7o7qnskFvnQYkBaRrp7Vw,3122
|
|
10
|
+
xulbux/xx_format_codes.py,sha256=Qibr5CbV-Ow7l-TTPElfnU_yZELFaD86CFkdKU-7m4Y,19832
|
|
11
|
+
xulbux/xx_json.py,sha256=q60lOj8Xg8c4L9cBu6SBZdJzFC7QbjDfFwcKKzBKj5w,5173
|
|
12
|
+
xulbux/xx_path.py,sha256=_xkH9cowPdi3nHw2q_TvN_i_5oG6GJut-QwPBLxnrAQ,4519
|
|
13
|
+
xulbux/xx_regex.py,sha256=S1-MIk2qG4vHdxuaHGhMe5PHfY1SF9kncg8iQ8HJgS4,8002
|
|
14
|
+
xulbux/xx_string.py,sha256=Wa3qHxnk7AIpAVAn1vI_GBtkfYFwy4F_Xtj83ojEPKc,7168
|
|
15
|
+
xulbux/xx_system.py,sha256=M3VGU3Tf3nDU59DjIJgDXJOqNB80Vr0wf15Vcnb5UCo,6430
|
|
16
|
+
xulbux-1.6.3.dist-info/LICENSE,sha256=6NflEcvzFEe8_JFVNCPVwZBwBhlLLd4vqQi8WiX_Xk4,1084
|
|
17
|
+
xulbux-1.6.3.dist-info/METADATA,sha256=dYwkecrzpal4hVChJVdbk0HYdJXluT5-8xxBqTj33xM,6948
|
|
18
|
+
xulbux-1.6.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
19
|
+
xulbux-1.6.3.dist-info/entry_points.txt,sha256=a3womfLIMZKnOFiyy-xnVb4g2qkZsHR5FbKKkljcGns,94
|
|
20
|
+
xulbux-1.6.3.dist-info/top_level.txt,sha256=FkK4EZajwfP36fnlrPaR98OrEvZpvdEOdW1T5zTj6og,7
|
|
21
|
+
xulbux-1.6.3.dist-info/RECORD,,
|
xulbux-1.6.1.dist-info/RECORD
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
xulbux/__init__.py,sha256=ayM2Gomwlns0lEDdbUZ6uxtrDIQRb0ldSOyqguQ_ON8,1658
|
|
2
|
-
xulbux/_cli_.py,sha256=U25ZrtpQgpKXtvOSTBBbh7-AJ_WTeZ95A66DQARAqzo,3558
|
|
3
|
-
xulbux/_consts_.py,sha256=2-swueg8B5retfsAQqmR8nFNc06tqAwpL__TOv3V4kw,4882
|
|
4
|
-
xulbux/xx_code.py,sha256=yBP5WxCxNxjBiS6nVAmUBJpD0hX6fgnh5RWq-NmrnaY,5222
|
|
5
|
-
xulbux/xx_color.py,sha256=sRW0Fr8CFfM2EsUubEO74aLRTseCu5VulXyjqDcahEw,44895
|
|
6
|
-
xulbux/xx_console.py,sha256=ydDPYyGZ5OVHIkCiJO_eaAJI-8k97L5vQ7v1SoUUmWI,15436
|
|
7
|
-
xulbux/xx_data.py,sha256=OEKLbI1XeNTrittdz3s3mvQk8YrBoSovj9O1H-b7ArY,25844
|
|
8
|
-
xulbux/xx_env_path.py,sha256=5CvKpItzA4n8nvF7RwOmZwgs4erGltZqRJ3VD-9dFzo,4388
|
|
9
|
-
xulbux/xx_file.py,sha256=-58YnqKvrs5idIF91UzEki7o7qnskFvnQYkBaRrp7Vw,3122
|
|
10
|
-
xulbux/xx_format_codes.py,sha256=TkdHaiKXpZxVoUN6oEcsGXITgxrxzkghMCde2Kw-kQg,14806
|
|
11
|
-
xulbux/xx_json.py,sha256=q60lOj8Xg8c4L9cBu6SBZdJzFC7QbjDfFwcKKzBKj5w,5173
|
|
12
|
-
xulbux/xx_path.py,sha256=_xkH9cowPdi3nHw2q_TvN_i_5oG6GJut-QwPBLxnrAQ,4519
|
|
13
|
-
xulbux/xx_regex.py,sha256=zyxkS1bLlrSq26ErhO4UtrimIhW71_a7kox6ArCoK58,7670
|
|
14
|
-
xulbux/xx_string.py,sha256=Wa3qHxnk7AIpAVAn1vI_GBtkfYFwy4F_Xtj83ojEPKc,7168
|
|
15
|
-
xulbux/xx_system.py,sha256=Eyf4MbZpaHHKv71SOcM_EK0bvT4PGG0KLwAXx4m60vo,3918
|
|
16
|
-
xulbux-1.6.1.dist-info/LICENSE,sha256=6NflEcvzFEe8_JFVNCPVwZBwBhlLLd4vqQi8WiX_Xk4,1084
|
|
17
|
-
xulbux-1.6.1.dist-info/METADATA,sha256=NLrtou5gw1j1FQ3PLIsI09UCoowzZg7xtJzVl5l9mi0,6836
|
|
18
|
-
xulbux-1.6.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
19
|
-
xulbux-1.6.1.dist-info/entry_points.txt,sha256=a3womfLIMZKnOFiyy-xnVb4g2qkZsHR5FbKKkljcGns,94
|
|
20
|
-
xulbux-1.6.1.dist-info/top_level.txt,sha256=FkK4EZajwfP36fnlrPaR98OrEvZpvdEOdW1T5zTj6og,7
|
|
21
|
-
xulbux-1.6.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|