Changeset - 3203b428288d
[Not reviewed]
0 1 0
Lance Edgar (lance) - 11 years ago 2013-06-08 14:57:50
lance@edbob.org
Added `files.overwriting_move()` convenience function.
1 file changed with 13 insertions and 0 deletions:
0 comments (0 inline, 0 general)
rattail/files.py
Show inline comments
 
@@ -89,24 +89,37 @@ def locking_copy(src, dst):
 

	
 
    :returns: ``None``
 
    """
 

	
 
    if os.path.isdir(dst):
 
        fn = os.path.basename(src)
 
        dst = os.path.join(dst, fn)
 

	
 
    with lockfile.FileLock(dst):
 
        shutil.copy(src, dst)
 

	
 

	
 
def overwriting_move(src, dst):
 
    """
 
    Convenience function which is equivalent to ``shutil.move()``, except it
 
    will cause the destination file to be overwritten if it exists.
 
    """
 

	
 
    if os.path.isdir(dst):
 
        dst = os.path.join(dst, os.path.basename(src))
 
    if os.path.exists(dst):
 
        os.remove(dst)
 
    shutil.move(src, dst)
 

	
 

	
 
def resource_path(path):
 
    """
 
    Obtain a resource file path, extracting the resource and/or coercing the
 
    path as necessary.
 

	
 
    :param path: May be either a package resource specifier, or a regular file
 
       path.
 
    :type path: string
 

	
 
    :returns: Absolute file path to the resource.
 
    :rtype: string
 

	
0 comments (0 inline, 0 general)