tea.shutil

This module mimics the behavior of the builtin shutil module from the standard python library, adding logging to all operations.

Also, it adds a few useful additional functions to the module.

tea.shutil.chdir(directory)

Change the current working directory

tea.shutil.copy(source, destination)

Copy file or directory

tea.shutil.copyfile(source, destination)

Copy data and mode bits (“cp source destination”).

The destination may be a directory.

Parameters:
  • source (str) – Source file (file to copy).
  • destination (str) – Destination file or directory (where to copy).
Return type:

bool

Returns:

True if the operation is successful, False otherwise.

tea.shutil.copyfile2(source, destination)

Copy data and all stat info (“cp -p source destination”).

The destination may be a directory.

Parameters:
  • source (str) – Source file (file to copy).
  • destination (str) – Destination file or directory (where to copy).
Return type:

bool

Returns:

True if the operation is successful, False otherwise.

tea.shutil.copytree(source, destination, symlinks=False)

Recursively copy a directory tree using copy2().

The destination directory must not already exist.

If the optional symlinks flag is true, symbolic links in the source tree result in symbolic links in the destination tree; if it is false, the contents of the files pointed to by symbolic links are copied.

Parameters:
  • source (str) – Source directory (directory to copy).
  • destination (str) – Destination directory (where to copy).
  • symlinks (bool) – Follow symbolic links.
Return type:

bool

Returns:

True if the operation is successful, False otherwise.

tea.shutil.gcopy(pattern, destination)

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

tea.shutil.gmove(pattern, destination)

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

class tea.shutil.goto(directory, create=False)

Context object for changing directory.

Usage:

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

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.shutil.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.shutil.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.shutil.rmfile(path)

Delete a file

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

Recursively delete a directory tree.

Parameters:path (str) – Path to the directory that needs to be deleted.
Return type:bool
Returns:True if the operation is successful, False otherwise.
tea.shutil.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 also directories that match the pattern
tea.shutil.split(s, posix=True)

Split the string s using shell-like syntax

Project Versions

Previous topic

tea.scm

Next topic

tea.system

This Page