tea.shell Module

This module mimics some of the behaviors of the builtin shutil module, adding logging to all operations and abstracting some other useful shell commands (functions).

tea.shell.split(s, posix=True)

Split the string s using shell-like syntax

tea.shell.search(path, matcher='*', dirs=False, files=True)

Recursive search function.

Parameters:
  • path – path to search recursively
  • matcher – string pattern to search for or function that returns True/False for a file argument
  • dirs – if True returns directories that match the pattern
  • files – if True returns files that match the patter
tea.shell.chdir(directory)

Change the current working directory

tea.shell.goto(*args, **kwds)

Context object for changing directory.

Usage:

>>> with goto(directory) as ok:
...     if not ok:
...         print 'Error'
...     else:
...         print 'All OK'
tea.shell.mkdir(path[, mode=0755])

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:
  • path (str) – directory to create
  • mode (int) – directory mode
  • delete (bool) – delete directory/file if exists
Return type:

bool

Returns:

True if succeeded else False

tea.shell.copy(source, destination)

Copy file or directory

tea.shell.gcopy(pattern, destination)

Copy all file found by glob.glob(pattern) to destination directory

tea.shell.move(source, destination)

Recursively move a file or directory 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:
  • source (str) – Source file or directory (file or directory to move).
  • destination (str) – Destination file or directory (where to move).
Return type:

bool

Returns:

True if the operation is successful, False otherwise.

tea.shell.gmove(pattern, destination)

Move all file found by glob.glob(pattern) to destination directory

tea.shell.remove(path)

Delete a file or directory

Parameters:path (str) – Path to the file or directory that needs to be deleted.
Return type:bool
Returns:True if the operation is successful, False otherwise.
tea.shell.gremove(pattern)

Remove all file found by glob.glob(pattern)

Parameters:pattern (str) – Pattern of files to remove
tea.shell.touch(path, content='', encoding='utf-8')

Create a file at the given path if it does not already exists.

Parameters:
  • path (str) – Path to the file.
  • content (str) – Optional content that will be written in the file.
  • encoding (str) – Encoding in which to write the content. Default: utf-8