rattail.files
¶
File Utilities
This module contains various utility functions for use with the filesystem.
- rattail.files.count_lines(path, encoding=None)[source]¶
Counts the number of lines in a text file. Some attempt is made to ensure cross-platform compatibility.
- rattail.files.creation_time(path)[source]¶
Returns the “naive” (i.e. not timezone-aware) creation timestamp for a file.
- Parameters:
path¶ (string) – Path to the file.
- Returns:
The creation timestamp for the file.
- Return type:
datetime.datetime
instance
- rattail.files.locking_copy(src, destdir, timeout=None)[source]¶
Implements a “locking” version of the standard library’s
shutil.copy()
function.This exists to provide a more atomic method for copying a file into a folder which is being watched by a file monitor. The assumption is that the monitor is configured to watch for file “locks” and therefore only process files once they have had their locks removed. See also The Profile “watch_locks” Option.
- rattail.files.locking_copy_old(src, dst, timeout=None)[source]¶
Implements a “locking” version of the standard library’s
shutil.copy()
function.This exists to provide a more atomic method for copying a file into a folder which is being watched by a file monitor. The assumption is that the monitor is configured to watch for file “locks” and therefore only process files once they have had their locks removed. See also The Profile “watch_locks” Option.
- Parameters:
src¶ (string) – Path to the source file.
dst¶ (string) – Path to the destination file (or directory).
Number of seconds to wait for the file lock to clear, if it already exists. This value may be specified as an integer or float, or string (which will be coerced to a float).
Note
There is no default value for the timeout, which means that by default, the function will wait indefinitely for the lock to clear.
- rattail.files.move_lpt(src, dst)[source]¶
“Move” a source file to a LPT port, on Windows only.
This is an experimental function which will hopefully provide a more reliable way to send a print job directly to a parallel port (e.g. ‘LPT1’) on Windows systems. The function body was copied from
shutil.move()
and “gutted” as much as was practical.Note that this function’s signature differs from
shutil.move()
in that thedst
parameter is always assumed to be a LPT port, e.g.'LPT1'
, and never a “file” path.
- rattail.files.overwriting_move(src, dst)[source]¶
Convenience function which is equivalent to
shutil.move()
, except it will cause the destination file to be overwritten if it exists.
- rattail.files.resource_path(path)[source]¶
Obtain a resource file path, extracting the resource and/or coercing the path as necessary.
- Parameters:
path¶ (string) – May be either a package resource specifier, or a regular file path.
- Returns:
Absolute file path to the resource.
- Return type:
string
If
path
is a package resource specifier, and the package containing it is a zipped egg, then the resource will be extracted and the resultant filename will be returned.