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

Package file

source code

This module contains file- and path-related methods, classes, and modules.
Submodules [hide private]
  • 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 [hide private]
 
unlink_quietly(*paths)
Like the standard os.unlink() function, this function attempts to delete a file.
source code
 
recursively_remove(dir)
Recursively remove all files and directories below and including a specified directory.
source code
 
list_recursively(dir)
Recursively list the contents of a directory.
source code
 
copy_recursively(source_dir, target_dir)
Recursively copy a source directory (and all its contents) to a target directory.
source code
 
copy(files, target_dir, create_target=False)
Copy one or more files to a target directory.
source code
 
touch(files, times=None)
Similar to the Unix touch command, this function:
source code
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.
source code
 
__find_matches(pattern_pieces, directory)
Used by eglob.
source code
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.
source code
str
universal_path(path)
Converts a path name from its operating system-specific format to a universal path notation.
source code
str
native_path(path)
Converts a path name from universal path notation to the operating system-specific format.
source code
Variables [hide private]
  __package__ = None
hash(x)
Function Details [hide private]

unlink_quietly(*paths)

source code 
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)

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

list_recursively(dir)

source code 
Recursively list the contents of a directory. Yields the contents of the directory and all subdirectories. This method returns a generator, so it evaluates its recursive walk lazily.
Parameters:
  • dir (str) - Path to directory to list
Raises:
  • ValueError - If dir does not exist, or if dir exists but is not a directory.

copy_recursively(source_dir, target_dir)

source code 
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)

source code 
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)

source code 

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)

source code 
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='.')

source code 

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)

source code 
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)

source code 
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.