Package grizzled :: Package file
[frames] | no frames]

Package file

This module contains file- and path-related methods, classes, and modules.
Submodules
  • grizzled.file.includer: The grizzled.file.includer module contains a class that can be used to process includes within a text file, returning a file-like object.

Functions
 
unlink_quietly(*paths)
Like the standard os.unlink() function, this function attempts to delete a file.
 
recursively_remove(dir)
Recursively remove all files and directories below and including a specified directory.
 
copy_recursively(source_dir, target_dir)
Recursively copy a source directory (and all its contents) to a target directory.
 
copy(files, target_dir, create_target=False)
Copy one or more files to a target directory.
 
touch(files, times=None)
Similar to the Unix touch command, this function:
list
pathsplit(path)
Split a path into an array of path components, using the file separator ('/' on POSIX systems, '' on Windows) that's appropriate for the underlying operating system.
list
eglob(pattern, directory='.')
Extended glob function that supports the all the wildcards supported by the Python standard glob routine, as well as a special "**" wildcard that recursively matches any directory.
str
universal_path(path)
Converts a path name from its operating system-specific format to a universal path notation.
str
native_path(path)
Converts a path name from universal path notation to the operating system-specific format.
Function Details

unlink_quietly(*paths)

 
Like the standard os.unlink() function, this function attempts to delete a file. However, it swallows any exceptions that occur during the unlink operation, making it more suitable for certain uses (e.g., in atexit handlers).
Parameters:
  • paths (str or list) - path(s) to unlink

recursively_remove(dir)

 
Recursively remove all files and directories below and including a specified directory.
Parameters:
  • dir (str) - path to directory to remove

copy_recursively(source_dir, target_dir)

 
Recursively copy a source directory (and all its contents) to a target directory.
Parameters:
  • source_dir (str) - Source directory to copy recursively. This path must exist and must specify a directory; otherwise, this function throws a ValueError
  • target_dir (str) - Directory to which to copy the contents of source_dir. This directory must not already exist.
Raises:
  • ValueError - If: source_dir does not exist; source_dir exists but is not a directory; or target_dir exists but is not a directory.

copy(files, target_dir, create_target=False)

 
Copy one or more files to a target directory.
Parameters:
  • files (str or list) - single file path or a list of file paths to be copied
  • target_dir (str) - path to target directory
  • create_target (bool) - If True, copy() will attempt to create the target directory if it does not exist. If False, copy() will throw an exception if the target directory does not exist.
Raises:
  • OSError - target_dir does not exist, and create_target is False

touch(files, times=None)

 

Similar to the Unix touch command, this function:

  • updates the access and modification times for any existing files in a list of files
  • creates any non-existent files in the list of files

If any file in the list is a directory, this function will throw an exception.

Parameters:
  • files (list or str) - pathname or list of pathnames of files to be created or updated
  • times (tuple) - tuple of the form (atime, mtime), identical to what is passed to the standard os.utime() function. If this tuple is None, then the current time is used.

pathsplit(path)

 
Split a path into an array of path components, using the file separator ('/' on POSIX systems, '' on Windows) that's appropriate for the underlying operating system. Does not take drive letters into account. If there's a Windows drive letter in the path, it'll end up with the first component.
Parameters:
  • path (str) - path to split. Can be relative or absolute
Returns: list
a list of path components

eglob(pattern, directory='.')

 

Extended glob function that supports the all the wildcards supported by the Python standard glob routine, as well as a special "**" wildcard that recursively matches any directory. Examples:

**/*.py all files ending in '.py' under the current directory
foo/**/bar all files name 'bar' anywhere under subdirectory 'foo'
Parameters:
  • pattern (str) - The wildcard pattern. Must be a simple pattern with no directories.
  • directory (str) - The directory in which to do the globbing.
Returns: list
A list of matched files, or an empty list for no match

universal_path(path)

 
Converts a path name from its operating system-specific format to a universal path notation. Universal path notation always uses a Unix-style "/" to separate path elements. A universal path can be converted to a native (operating system-specific) path via the native_path() function. Note that on POSIX-compliant systems, this function simply returns the path parameter unmodified.
Parameters:
  • path (str) - the path to convert to universal path notation
Returns: str
the universal path.

native_path(path)

 
Converts a path name from universal path notation to the operating system-specific format. Universal path notation always uses a Unix-style "/" to separate path elements. A native path can be converted to a universal path via the universal_path() function. Note that on POSIX-compliant systems, this function simply returns the path parameter unmodified.
Parameters:
  • path (str) - the path to convert to native path notation
Returns: str
the native path.