Changeset - 022d436c39ee
[Not reviewed]
0 1 0
Lance Edgar - 9 years ago 2015-11-30 14:39:20
ledgar@sacfoodcoop.com
Add `files.move_lpt()` function.

And get rid of `minimal_move()`. Hopefully a little closer now...
1 file changed with 7 insertions and 9 deletions:
0 comments (0 inline, 0 general)
rattail/files.py
Show inline comments
 
@@ -181,31 +181,29 @@ def overwriting_move(src, dst):
 
        dst = os.path.join(dst, os.path.basename(src))
 
    if os.path.exists(dst):
 
        os.remove(dst)
 
    shutil.move(src, dst)
 

	
 

	
 
def minimal_move(src, dst):
 
def move_lpt(src, dst):
 
    """
 
    Move a source file to a destination path, in as few operations as possible.
 
    "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
 
    :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.
 
    Note that this function's signature differs from ``shutil.move()`` in that
 
    the ``dst`` parameter is always assumed to be a LPT port, e.g. ``'LPT1'``,
 
    and never a "file" path.
 
    """
 
    real_dst = os.path.join(dst, shutil._basename(src))
 
    try:
 
        os.rename(src, real_dst)
 
        os.rename(src, dst)
 
    except OSError:
 
        shutil.copyfile(src, real_dst)
 
        shutil.copyfile(src, 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)