xulbux 1.5.5__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.
- xulbux/__help__.py +74 -0
- xulbux/__init__.py +47 -0
- xulbux/_consts_.py +147 -0
- xulbux/xx_cmd.py +240 -0
- xulbux/xx_code.py +102 -0
- xulbux/xx_color.py +799 -0
- xulbux/xx_data.py +431 -0
- xulbux/xx_env_vars.py +60 -0
- xulbux/xx_file.py +50 -0
- xulbux/xx_format_codes.py +212 -0
- xulbux/xx_json.py +81 -0
- xulbux/xx_path.py +97 -0
- xulbux/xx_regex.py +124 -0
- xulbux/xx_string.py +116 -0
- xulbux/xx_system.py +75 -0
- xulbux-1.5.5.dist-info/METADATA +97 -0
- xulbux-1.5.5.dist-info/RECORD +20 -0
- xulbux-1.5.5.dist-info/WHEEL +4 -0
- xulbux-1.5.5.dist-info/entry_points.txt +2 -0
- xulbux-1.5.5.dist-info/licenses/LICENSE +21 -0
xulbux/xx_system.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import subprocess as _subprocess
|
|
2
|
+
import platform as _platform
|
|
3
|
+
import time as _time
|
|
4
|
+
import sys as _sys
|
|
5
|
+
import os as _os
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class System:
|
|
11
|
+
|
|
12
|
+
@staticmethod
|
|
13
|
+
def restart(prompt:object = None, wait:int = 0, continue_program:bool = False, force:bool = False) -> None:
|
|
14
|
+
"""Starts a system restart:<br>
|
|
15
|
+
`prompt` is the message to be displayed in the systems restart notification.<br>
|
|
16
|
+
`wait` is the time to wait until restarting in seconds.<br>
|
|
17
|
+
`continue_program` is whether to continue the current Python program after calling this function.<br>
|
|
18
|
+
`force` is whether to force a restart even if other processes are still running."""
|
|
19
|
+
system = _platform.system().lower()
|
|
20
|
+
if system == 'windows':
|
|
21
|
+
if not force:
|
|
22
|
+
output = _subprocess.check_output('tasklist', shell=True).decode()
|
|
23
|
+
processes = [line.split()[0] for line in output.splitlines()[3:] if line.strip()]
|
|
24
|
+
if len(processes) > 2: # EXCLUDING THE PYTHON PROCESS AND CMD
|
|
25
|
+
raise RuntimeError('Processes are still running. Use the parameter `force=True` to restart anyway.')
|
|
26
|
+
if prompt:
|
|
27
|
+
_os.system(f'shutdown /r /t {wait} /c "{prompt}"')
|
|
28
|
+
else:
|
|
29
|
+
_os.system('shutdown /r /t 0')
|
|
30
|
+
if continue_program:
|
|
31
|
+
print(f'Restarting in {wait} seconds...')
|
|
32
|
+
_time.sleep(wait)
|
|
33
|
+
elif system in ['linux', 'darwin']:
|
|
34
|
+
if not force:
|
|
35
|
+
output = _subprocess.check_output(['ps', '-A']).decode()
|
|
36
|
+
processes = output.splitlines()[1:] # EXCLUDE HEADER
|
|
37
|
+
if len(processes) > 2: # EXCLUDING THE PYTHON PROCESS AND PS
|
|
38
|
+
raise RuntimeError('Processes are still running. Use the parameter `force=True` to restart anyway.')
|
|
39
|
+
if prompt:
|
|
40
|
+
_subprocess.Popen(['notify-send', 'System Restart', prompt])
|
|
41
|
+
_time.sleep(wait)
|
|
42
|
+
try:
|
|
43
|
+
_subprocess.run(['sudo', 'shutdown', '-r', 'now'])
|
|
44
|
+
except _subprocess.CalledProcessError:
|
|
45
|
+
raise PermissionError('Failed to restart: insufficient privileges. Ensure sudo permissions are granted.')
|
|
46
|
+
if continue_program:
|
|
47
|
+
print(f'Restarting in {wait} seconds...')
|
|
48
|
+
_time.sleep(wait)
|
|
49
|
+
else:
|
|
50
|
+
raise NotImplementedError(f'Restart not implemented for `{system}`')
|
|
51
|
+
|
|
52
|
+
@staticmethod
|
|
53
|
+
def check_libs(lib_names:list[str], install_missing:bool = False, confirm_install:bool = True) -> None|list[str]:
|
|
54
|
+
"""Checks if the given list of libraries are installed. If not:
|
|
55
|
+
- If `install_missing` is `False` the missing libraries will be returned as a list.
|
|
56
|
+
- If `install_missing` is `True` the missing libraries will be installed. If `confirm_install` is `True` the user will first be asked if they want to install the missing libraries."""
|
|
57
|
+
missing = []
|
|
58
|
+
for lib in lib_names:
|
|
59
|
+
try: __import__(lib)
|
|
60
|
+
except ImportError: missing.append(lib)
|
|
61
|
+
if not missing:
|
|
62
|
+
return None
|
|
63
|
+
elif not install_missing:
|
|
64
|
+
return missing
|
|
65
|
+
if confirm_install:
|
|
66
|
+
print('The following required libraries are missing:')
|
|
67
|
+
for lib in missing:
|
|
68
|
+
print(f'- {lib}')
|
|
69
|
+
if input('Do you want to install them now (Y/n): ').strip().lower() not in ['', 'y', 'yes']:
|
|
70
|
+
raise ImportError('Missing required libraries.')
|
|
71
|
+
try:
|
|
72
|
+
_subprocess.check_call([_sys.executable, '-m', 'pip', 'install'] + missing)
|
|
73
|
+
return None
|
|
74
|
+
except _subprocess.CalledProcessError:
|
|
75
|
+
return missing
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: XulbuX
|
|
3
|
+
Version: 1.5.5
|
|
4
|
+
Summary: A library which includes a lot of really helpful functions.
|
|
5
|
+
Project-URL: Homepage, https://github.com/XulbuX-dev/Python/tree/main/Libraries/XulbuX
|
|
6
|
+
Project-URL: Bug Reports, https://github.com/XulbuX-dev/Python/issues
|
|
7
|
+
Project-URL: Documentation, https://github.com/XulbuX-dev/Python/wiki
|
|
8
|
+
Project-URL: Source Code, https://github.com/XulbuX-dev/Python/tree/main/Libraries/XulbuX/src
|
|
9
|
+
Project-URL: Changelog, https://github.com/XulbuX-dev/Python/blob/main/Libraries/XulbuX/CHANGELOG.md
|
|
10
|
+
Author-email: XulbuX <xulbux.real@gmail.com>
|
|
11
|
+
License: MIT License
|
|
12
|
+
|
|
13
|
+
Copyright (c) 2024 XulbuX
|
|
14
|
+
|
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
in the Software without restriction, including without limitation the rights
|
|
18
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
furnished to do so, subject to the following conditions:
|
|
21
|
+
|
|
22
|
+
The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
copies or substantial portions of the Software.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
SOFTWARE.
|
|
32
|
+
Keywords: classes,cmd,code,color,data,env,environment,file,format,functions,helper,helpful,json,library,methods,operations,path,presets,python,regex,string,structures,system,tools,types,utility,xulbux
|
|
33
|
+
Classifier: Intended Audience :: Developers
|
|
34
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
35
|
+
Classifier: Operating System :: OS Independent
|
|
36
|
+
Classifier: Programming Language :: Python :: 3
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
41
|
+
Requires-Python: >=3.10.0
|
|
42
|
+
Requires-Dist: keyboard>=0.13.5
|
|
43
|
+
Requires-Dist: mouse>=0.7.1
|
|
44
|
+
Requires-Dist: regex>=2023.10.3
|
|
45
|
+
Provides-Extra: dev
|
|
46
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
47
|
+
Description-Content-Type: text/markdown
|
|
48
|
+
|
|
49
|
+
# **$\color{#8085FF}\Huge\textsf{XulbuX}$**
|
|
50
|
+
|
|
51
|
+
**$\color{#8085FF}\textsf{XulbuX}$** is a library which includes a lot of really helpful classes, types and functions.
|
|
52
|
+
|
|
53
|
+
For the libraries latest changes, see the [change log](https://github.com/XulbuX-dev/Python/blob/main/Libraries/XulbuX/CHANGELOG.md).<br>
|
|
54
|
+
For precise information about the library, see the library's [Wiki page](https://github.com/XulbuX-dev/Python/wiki).
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
On all operating systems, run the following command:
|
|
60
|
+
```bash
|
|
61
|
+
pip install XulbuX
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
# GENERAL LIBRARY
|
|
69
|
+
import XulbuX as xx
|
|
70
|
+
# CUSTOM TYPES
|
|
71
|
+
from XulbuX import rgba, hsla, hexa
|
|
72
|
+
```
|
|
73
|
+
The library **$\color{#8085FF}\textsf{XulbuX}$** (*below used as* `xx` *with above imported types*) contains the following modules:
|
|
74
|
+
```python
|
|
75
|
+
• CUSTOM TYPES:
|
|
76
|
+
• rgba(int,int,int,float)
|
|
77
|
+
• hsla(int,int,int,float)
|
|
78
|
+
• hexa(str)
|
|
79
|
+
• PATH OPERATIONS xx.Path
|
|
80
|
+
• FILE OPERATIONS xx.File
|
|
81
|
+
• JSON FILE OPERATIONS xx.Json
|
|
82
|
+
• SYSTEM ACTIONS xx.System
|
|
83
|
+
• MANAGE ENVIRONMENT VARS xx.EnvVars
|
|
84
|
+
• CMD LOG AND ACTIONS xx.Cmd
|
|
85
|
+
• PRETTY PRINTING xx.FormatCodes
|
|
86
|
+
• COLOR OPERATIONS xx.Color
|
|
87
|
+
• DATA OPERATIONS xx.Data
|
|
88
|
+
• STR OPERATIONS xx.String
|
|
89
|
+
• CODE STRING OPERATIONS xx.Code
|
|
90
|
+
• REGEX PATTERN TEMPLATES xx.Regex
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
<br>
|
|
95
|
+
|
|
96
|
+
--------------------------------------------------------------
|
|
97
|
+
[View this library on PyPI](https://pypi.org/project/XulbuX/)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
xulbux/__help__.py,sha256=2p_CLFMoEu4Coqs2d3dFuoZ16NQTI6aZkctVjSmq7mE,4098
|
|
2
|
+
xulbux/__init__.py,sha256=8I7GLhkT_P3-KIDDZmAlbIgxmQfoh3ujgv5_aPzQt8g,1644
|
|
3
|
+
xulbux/_consts_.py,sha256=vquutpFVjJsGqRi78EboXbyMczqMdAPZVnAyqcwzJ6k,5313
|
|
4
|
+
xulbux/xx_cmd.py,sha256=9rmnq7YkgfzBoCpcyai0FKZTcBPpMjw3L15-FORUdnI,14070
|
|
5
|
+
xulbux/xx_code.py,sha256=wnQuA0gfxd-Q_sCW-R3Sqw4Ld6u4TQMRAJGzMgTDiqk,5520
|
|
6
|
+
xulbux/xx_color.py,sha256=TqsY5akT9vzHMWJZQ0Ggev5DIzfHaCcq0Tgd-sp15TM,42106
|
|
7
|
+
xulbux/xx_data.py,sha256=U9qzEZFVV_I6CgjbENfz2SuhvIN31Y9t_EtOhccF-6c,26127
|
|
8
|
+
xulbux/xx_env_vars.py,sha256=zN0xFtqukQO9TdR-Ci7sky4s5m2wjQQUfhrhdcNaS1Y,2394
|
|
9
|
+
xulbux/xx_file.py,sha256=CEv5n-ZG_l7HK2ClVQWRiqlERaHhHeGvy0W4rr8OrMI,2513
|
|
10
|
+
xulbux/xx_format_codes.py,sha256=O7DnVnzwa1riiHP9DbRtpMD1LNrOKMT4xpwngt49iPo,12939
|
|
11
|
+
xulbux/xx_json.py,sha256=Z4617tA2VJIdHxQIGCbx99ubLTYj1Dky75C7qiORkWg,4827
|
|
12
|
+
xulbux/xx_path.py,sha256=P_r8WzJygtDCFuQxcEONlkW_exkHxRaqJoUxnPBetyo,4338
|
|
13
|
+
xulbux/xx_regex.py,sha256=s3AsnlMrwblz57BjygV-fjgFn0AguopvZLCKWHVd3ZA,6921
|
|
14
|
+
xulbux/xx_string.py,sha256=gwwY8pTB7d6gJgp8lo8pUftnyJBna0VQ4oFFc_AmOjo,5297
|
|
15
|
+
xulbux/xx_system.py,sha256=2zqqT_oqCPDPzaUBSNMC8awRhSUHQtwIwju9pIQQQQ4,3797
|
|
16
|
+
xulbux-1.5.5.dist-info/METADATA,sha256=PorHfyAoYZ3R8blKx0TAlsqqT9qcZ5auVdlVBJ97L5Y,4162
|
|
17
|
+
xulbux-1.5.5.dist-info/WHEEL,sha256=3U_NnUcV_1B1kPkYaPzN-irRckL5VW_lytn0ytO_kRY,87
|
|
18
|
+
xulbux-1.5.5.dist-info/entry_points.txt,sha256=hfQ1MjdOLVbINRpbJVzNcqRbAouwYF4a-5kzO69zcHE,46
|
|
19
|
+
xulbux-1.5.5.dist-info/licenses/LICENSE,sha256=6NflEcvzFEe8_JFVNCPVwZBwBhlLLd4vqQi8WiX_Xk4,1084
|
|
20
|
+
xulbux-1.5.5.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 XulbuX
|
|
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.
|