Changeset - bd3380eccf7f
[Not reviewed]
0 1 0
Lance Edgar - 9 years ago 2015-11-30 12:46:49
ledgar@sacfoodcoop.com
Add `files.minimal_move()` function, for "moving" files to LPT ports.

This code has yet to be tested in production, hopefully it does the trick.
1 file changed with 22 insertions and 0 deletions:
0 comments (0 inline, 0 general)
rattail/files.py
Show inline comments
 
@@ -184,6 +184,28 @@ def overwriting_move(src, dst):
 
    shutil.move(src, dst)
 

	
 

	
 
def minimal_move(src, dst):
 
    """
 
    Move a source file to a destination path, in as few operations as possible.
 

	
 
    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
 
    :func:`python:shutil.move()` and "gutted" as much as was practical.
 

	
 
    Note that one difference from ``shutil.move()`` is that in this function,
 
    the ``dst`` parameter is always assumed to be a directory(-like) path, and
 
    never a "file" path.  There also is no check for the final destination's
 
    existence, etc.
 
    """
 
    real_dst = os.path.join(dst, shutil._basename(src))
 
    try:
 
        os.rename(src, real_dst)
 
    except OSError:
 
        shutil.copyfile(src, real_dst)
 
        os.unlink(src)
 

	
 

	
 
def resource_path(path):
 
    """
 
    Obtain a resource file path, extracting the resource and/or coercing the
0 comments (0 inline, 0 general)