Spaces:
Paused
Paused
Download toolbox/os/command.py from miyuki2026/OpenMiniMind: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/miyuki2026/OpenMiniMind/resolve/main/toolbox/os/command.py
- Command line
-
hf download hf://spaces/miyuki2026/OpenMiniMind/toolbox/os/command.py
-
curl -L -o command.py https://huggingface.co/spaces/miyuki2026/OpenMiniMind/resolve/main/toolbox/os/command.py
1.36 kB
| #!/usr/bin/python3 | |
| # -*- coding: utf-8 -*- | |
| import os | |
| class Command(object): | |
| custom_command = [ | |
| "cd" | |
| ] | |
| def _get_cmd(command): | |
| command = str(command).strip() | |
| if command == "": | |
| return None | |
| cmd_and_args = command.split(sep=" ") | |
| cmd = cmd_and_args[0] | |
| args = " ".join(cmd_and_args[1:]) | |
| return cmd, args | |
| def popen(cls, command): | |
| cmd, args = cls._get_cmd(command) | |
| if cmd in cls.custom_command: | |
| method = getattr(cls, cmd) | |
| return method(args) | |
| else: | |
| resp = os.popen(command) | |
| result = resp.read() | |
| resp.close() | |
| return result | |
| def cd(cls, args): | |
| if args.startswith("/"): | |
| os.chdir(args) | |
| else: | |
| pwd = os.getcwd() | |
| path = os.path.join(pwd, args) | |
| os.chdir(path) | |
| def system(cls, command): | |
| return os.system(command) | |
| def __init__(self): | |
| pass | |
| def ps_ef_grep(keyword: str): | |
| cmd = "ps -ef | grep {}".format(keyword) | |
| rows = Command.popen(cmd) | |
| rows = str(rows).split("\n") | |
| rows = [row for row in rows if row.__contains__(keyword) and not row.__contains__("grep")] | |
| return rows | |
| if __name__ == "__main__": | |
| pass | |