(OT) python file-truncate on fc10 zero-fills file: who to ask?
John Pilkington
J.Pilk at tesco.net
Wed Mar 11 10:41:31 UTC 2009
Patrick O'Callaghan wrote:
> On Thu, 2009-03-05 at 15:32 +0000, John Pilkington wrote:
>> Hi: I'm asking here because this is the most fc10-oriented list that I
>> use and I thought someone might know the answer. I'd be happy to ask
>> elsewhere but don't know where might be the best place.
>>
>> I'm trying to do shrink-to-fit with video files on fc10 after tcrequant
>> was deprecated. vamps looks as if it will do the job but I think I need
>> to chop off a few kb from the end of the input file first to avoid a
>> failure exit. I can do this with dd but that's slow and file truncation
>> would be better. I can't see a command-line truncate but since I am
>> hacking the mythburn.py script I thought I had found the answer here, in
>> truncate([size]) :
>>
>> http://www.python.org/doc/2.5.2/lib/bltin-file-objects.html
>>
>> I've tried that. The file size shrinks as required but the result is
>> zero-filled. Here's some stripped-down test code:
>>
>> vobsize = os.path.getsize(source)
>> write("Initial vobsize is %s bytes" % vobsize)
>>
>> vobsize -= 2048
>> f=open(source,'wb')
>> f.truncate( vobsize )
>> f.close()
>>
>> vobsize = os.path.getsize(source)
>> write("vobsize after truncation is %s bytes" % vobsize)
>>
>> Is this a known problem with python, or in its fc10 implementation?
>> Where would be the best place to ask how to do this job?
>
> I've no idea, but I suspect you could probably write a tiny C program to
> do the truncation is less time than it would take to get an answer.
>
> poc
>
For the record - ie in case someone comes to this by Google - the
problem was solved by using f=open(source,'ab'), which opens the binary
file in append mode.
John P
More information about the kde
mailing list