how to detect if a file is complete
Andy Gimblett
gimbo at ftech.net
Thu Apr 4 14:46:12 EST 2002
On Thu, Apr 04, 2002 at 07:01:43AM -0800, harm wrote:
> I want to write a python script which checks a dir and copies all
> files to another dir. But there is the possibility that the file is
> not yet complete. (This are rather large Postscript files >100mb).
> Therefore I need to detect if the file is complete.
>
> The files are copied on the samba-share by Adobe Acrobat Distiller,
> therefore i cannot save some check file like $FILENAME.complete...
>
> Is there some other way (using python) to detect if the file is
> complete?
Define complete.
If the file has a well-defined structure (eg XML) or even just some
indication of its length, you might stand a chance. If it's just
random plain text, how would you tell complete from incomplete? I
don't know anything about Postscript internals but I imagine it uses
some concept of correct/broken, maybe this would help?
Alternative approach: use fuser to see what processes have the file
open. I don't know how this would work with samba though...
Obviously the unix system will have no concept of the Distiller
process, so presumably it would be a process id associated with
samba... Mumble mumble, try it and see I suppose. :-)
Second alternative approach: don't copy any files created in the last
n minutes. If you know Distiller never takes longer than 2 minutes to
do its stuff, set n to 3, or 5, or whatever, and you'll be sure you're
only copying complete files. This may or may not be an acceptable
solution, depending on the time-criticality of the application. If it
doesn't matter that it takes 10 minutes for the file to appear at its
destination, this is a very simple and effective solution to your
problem.
Good luck,
Andy
--
Andy Gimblett - Programmer - Frontier Internet Services Limited
Tel: 029 20 820 044 Fax: 029 20 820 035 http://www.frontier.net.uk/
Statements made are at all times subject to Frontier's Terms and
Conditions of Business, which are available upon request.
More information about the Python-list
mailing list