tea.shell
Module¶
Module mimics some of the behaviors of the builtin shutil
.
It adds logging to all operations and abstracting some other useful shell commands (functions).
-
tea.shell.
split
(s, posix=True)[source]¶ Split the string s using shell-like syntax.
Parameters: Returns: List of string parts
Return type: list of str
-
tea.shell.
search
(path, matcher='*', dirs=False, files=True)[source]¶ Recursive search function.
Parameters: Yields: str – Found files and directories
-
tea.shell.
chdir
(directory)[source]¶ Change the current working directory.
Parameters: directory (str) – Directory to go to.
-
tea.shell.
goto
(*args, **kwds)[source]¶ Context object for changing directory.
Parameters: Usage:
>>> with goto(directory) as ok: ... if not ok: ... print 'Error' ... else: ... print 'All OK'
-
tea.shell.
mkdir
(path, mode=493, delete=False)[source]¶ Make a directory.
Create a leaf directory and all intermediate ones. Works like
mkdir
, except that any intermediate path segment (not just the rightmost) will be created if it does not exist. This is recursive.Parameters: Returns: True if succeeded else False
Return type:
-
tea.shell.
copy
(source, destination)[source]¶ Copy file or directory.
Parameters: Returns: True if the operation is successful, False otherwise.
Return type:
-
tea.shell.
gcopy
(pattern, destination)[source]¶ Copy all file found by glob.glob(pattern) to destination directory.
Parameters: Returns: True if the operation is successful, False otherwise.
Return type:
-
tea.shell.
move
(source, destination)[source]¶ Move a file or directory (recursively) to another location.
If the destination is on our current file system, then simply use rename. Otherwise, copy source to the destination and then remove source.
Parameters: Returns: True if the operation is successful, False otherwise.
Return type:
-
tea.shell.
gmove
(pattern, destination)[source]¶ Move all file found by glob.glob(pattern) to destination directory.
Parameters: Returns: True if the operation is successful, False otherwise.
Return type:
-
tea.shell.
remove
(path)[source]¶ Delete a file or directory.
Parameters: path (str) – Path to the file or directory that needs to be deleted. Returns: True if the operation is successful, False otherwise. Return type: bool
-
tea.shell.
gremove
(pattern)[source]¶ Remove all file found by glob.glob(pattern).
Parameters: pattern (str) – Pattern of files to remove Returns: True if the operation is successful, False otherwise. Return type: bool
-
tea.shell.
read
(path, encoding='utf-8')[source]¶ Read the content of the file.
Parameters: Returns: File content or empty string if there was an error
Return type: