Python Extension Module for the best System Interaction, based on Rust.
- Faster then Python OS and Python Subprocess Module.
- Great Interaction, fast Import.
- Runs Greate on Windows and Unix.
Install with pip
-
pymainprocess
pip install -U --no-cache-dir pymainprocess
-
-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
pip install git+https://github.com/pymainprocess/pymainprocess
-
-
- Install Rust (Only Unix)
-
pip install https://github.com/pymainprocess/pymainprocess/archive/master.zip
import pymainprocess as proc
command = 'apt-get update'
# Simple Run
proc.call(command)
# Run a Sudo
proc.sudo(command)
# Safe all output
stdout, stderr = proc.call(command, stdout=True, stderr=True)
# Safe all ouput as sudo
stdout, stderr = proc.sudo(command, stdout=True, stderr=True)
# Get only stdout
stdout = proc.call(command, stdout=True)
# Get only stderr
stderr = proc.call(command, stderr=True)
# Now as sudo
stdout = proc.sudo(command, stdout=True)
# Now as sudo
stderr = proc.sudo(command, stderr=True)
# Create a New Function
def cmd(command: str):
# Get the pid
pid = proc.fork(rust=True)
# Now make the Command as List
command = command.split(" ")
# Now get the needed varibles
file = command[0]
args = command
# Wait for PID 0
if proc.wait(pid):
proc.execvp(file, args, rust=True)
# Now Test the Function
command = 'ls -A'
cmd(command)
# A Simple walk will sort all Files and Dirs in the Given Path
path = proc.path.join('/', 'usr', 'local')
result = proc.path.walk(path)
# A Recursive Run will list the Current Path with all Sub Paths
result = proc.path.walk(path, recursive=True)
(.venv) alex@DESKTOP-E4UA3DM:~/pymainprocess$ python
Python 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymainprocess as proc
>>> path = '/usr/local'
>>> result = proc.path.walk(path)
>>> result2 = proc.path.walk(path, recursive=True)
>>>
>>> result
{'local': {'dirs': ['etc', 'man', 'share', 'sbin', 'games', 'src', 'lib', 'bin', 'include'], 'files': []}}
>>>
>>> result2
{'local': {'dirs': [{'etc': {'files': [], 'dirs': []}}, {'man': {'dirs': [], 'files': []}}, {'share': {'dirs': [{'xml': {'files': [], 'dirs': [{'entities': {'files': [], 'dirs': []}}, {'misc': {'dirs': [], 'files': []}}, {'schema': {'files': [], 'dirs': []}}, {'declaration': {'dirs': [], 'files': []}}]}}, {'man': {'dirs': [], 'files': []}}, {'sgml': {'dirs': [{'entities': {'dirs': [], 'files': []}}, {'stylesheet': {'dirs': [], 'files': []}}, {'dtd': {'dirs': [], 'files': []}}, {'misc': {'dirs': [], 'files': []}}, {'declaration': {'files': [], 'dirs': []}}], 'files': []}}, {'fonts': {'files': [], 'dirs': []}}, {'ca-certificates': {'dirs': [], 'files': []}}], 'files': []}}, {'sbin': {'files': [], 'dirs': []}}, {'games': {'files': [], 'dirs': []}}, {'src': {'dirs': [], 'files': []}}, {'lib': {'files': [], 'dirs': [{'python3.12': {'files': [], 'dirs': [{'dist-packages': {'dirs': [], 'files': []}}]}}]}}, {'bin': {'files': ['maturin', 'cargo-deb', 'cargo-clone', 'mdbook'], 'dirs': []}}, {'include': {'dirs': [], 'files': []}}], 'files': []}}
>>>
The Output can be very Big, for this is Include as Function walksearch
>>> proc.path.walksearch(result2, ['lib', 'python3.12'])
{'files': [], 'dirs': [{'dist-packages': {'dirs': [], 'files': []}}]}
>>>