diff --git a/rattail/files.py b/rattail/files.py index 5ef4cef846d6440f72ac02d2aba58217665abc52..e5406f0f5f9513e6820ccd8bd242e2b0c548d6fd 100644 --- a/rattail/files.py +++ b/rattail/files.py @@ -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