PyConsoleCMDTools

Installation
pip install consolecmdtools
pip install --upgrade consolecmdtools
python -m consolecmdtools
Get Started
import consolecmdtools as cct
print(cct.__version__)
Functions
>>> cct.banner("hello, world!")
>>> cct.md5("blah blah blah")
'55e562bfee2bde4f9e71b8885eb5e303'
>>> cct.md5(42)
'a1d0c6e83f027327d8461063f4ac58a6'
>>> cct.md5('file.txt')
'd07aa6ddab4d6d2d2891aa9f3625a5db'
>>> cct.md5('file.txt', force_text=True)
'3d8e577bddb17db339eae0b3d9bcf180'
>>> cct.crc32("blah blah blah")
753353432
>>> cct.crc32(42)
841265288
>>> cct.crc32('file.txt')
1030388931
>>> cct.crc32('file.txt', force_text=True)
3774289445
>>> cct.main_color('image.jpg')
(152, 156, 69)
>>> cct.main_color('http://image-url/image', is_url=True)
(152, 156, 69)
>>> cct.main_color('image.jpg', scale=500)
(152, 156, 69)
>>> cct.main_color('image.jpg', triplet='hex')
'#989C45'
>>> cct.clear_screen()
>>> cct.get_py_cmd()
'python3'
>>> cct.run_cmd("echo hello")
*
| __RUN COMMAND__________________________
| (Command) echo hello
hello
`
>>> cct.read_cmd("echo hello")
| (_command) echo hello
'hello\n'
>>> cct.read_cmd("echo hello", verbose=False)
'hello\n'
>>> cct.read_cmd("notexist")
| (_command) echo hello
| (Warn) Command Failed:
'Error Messages'
>>> cct.resolve_value(42)
42
>>> cct.resolve_value({"Windows": "win", "Darwin": "macOS", "*": "Linux"})
'Linux'
>>> cct.is_cmd_exist("ls")
True
>>> cct.install_package("git")
True
>>> cct.install_package(name="ping3", manager="pip3")
True
>>> cct.install_package({
"Windows": "pypy",
"Darwin": "python",
"Linux": "python3"
})
True
>>> cct.install_package({
"Linux": "python3",
"*": "python"
})
True
>>> cct.install_package("git", manager={
"Windows": "choco",
"Darwin": "port",
"Linux": "snap",
"*": "npm"
})
>>> cct.get_path("./file.txt")
Path('/path/to/file.txt')
>>> cct.get_path("./file.txt").split('/')
['path', 'to', 'file.txt']
>>> cct.get_path("./file.txt").path
'./file.txt'
>>> cct.get_path("./file.txt").abs
>>> cct.get_path("./file.txt").exists
True
>>> cct.get_path("./file.txt").is_file
True
>>> cct.get_path("./file.txt").is_dir
False
>>> cct.get_path("/path/to/file.txt").basename
'file.txt'
>>> cct.get_path("/path/to/file.txt").ext
'txt'
>>> cct.get_path("/path/to/file.txt").stem
'file'
>>> cct.get_path("/path/to/file.txt").parent
'/path/to'
>>> cct.get_path("/path/to/file.txt").parent.basename
'to'
>>> cct.select_path()
'/path/to/file'
>>> cct.select_path(multiple=True)
['/path/to/file1', '/path/to/file2']
>>> cct.select_path(dir=True)
'/path/to/dir'
>>> cct.bfs_walk("/path/to/root")
['/path/to/root', '/path/to/root/folder', '/path/to/root/folder/file1', '/path/to/root/folder/file2']
>>> cct.get_paths("/path/to/root", filter=lambda path: path.name.startswith("f"))
['/path/to/root/folder', '/path/to/root/folder/file1', '/path/to/root/folder/file2']
>>> cct.ls_tree(root="/path/to/root")
📂 root\
├──📁 folder\
│ ├──📄 file1
│ ├──📄 file2
>>> cct.ls_tree(root="/path/to/root", show_icon=False, ascii=True)
root/
|-- folder/
| |-- file1
| |-- file2
>>> cct.ls_tree(root="/path/to/root", to_visible=lambda path: path.is_dir())
📂 root\
├──📁 folder\
>>> cct.ls_tree(root="/path/to/root", to_highlight=lambda path: path.name == "file1")
📂 root\
├──📁 folder\
│ ├──📄 file1
│ ├──📄 file2
>>> cct.ls_tree(root="/path/to/root", add_suffix=lambda path: "(current)" if pathe.name == "file1" else "")
📂 root\
├──📁 folder\
│ ├──📄 file1 (current)
│ ├──📄 file2
>>> cct.show_in_file_manager("/path/to/file")
>>> cct.show_in_file_manager("/path/to/file", ask=True)
>>> cct.diff("str1", "str2")
[
"-str1",
"+str2"
]
>>> cct.diff("str1", "str2", meta=True)
[
"--- <class 'str'>",
"+++ <class 'str'>",
"@@ -1 +1 @@",
"-str1",
"+str2"
]
>>> cct.diff(["a", "b"], ["a", "b", "c"])
[
"+c"
]
>>> cct.diff(["a", "b"], ["a", "b", "c"], context=2)
[
" a",
" b",
"+c"
]
>>> cct.diff("/path/to/file1", "/path/to/file2")
>>> cct.diff("/path/to/file1", "str")
>>> cct.diff('str', 'str')
[]
>>> cct.update_file('file', 'http://file-url')
False
>>> cct.read_file('file')
"file content"
>>> cct.move_file("/path/to/src", "/path/to/dst")
>>> cct.move_file("/path/to/src", "/path/to/dst", copy=True)
>>> cct.move_file("/path/to/src", "/path/to/dst", backup=True)
>>> cct.move_file("/path/to/src", "/path/to/dst", ensure=True)
>>> cct.move_file("/path/to/src", "/path/to/dst", msgout=print)
>>> cct.copy_file("/path/to/src", "/path/to/dst")
>>> cct.ajax('http://ajax-url')
{'result': 'data'}
>>> cct.ajax('http://ajax-url', {'data': 'value'})
{'result': 'data'}
>>> cct.ajax('http://ajax-url', method='post')
{'result': 'data'}
>>> if not cct.is_admin():
... cct.runas_admin(__file__)
... else:
...