On December 25, 2010 12:17:01 pm kfj wrote:
> Yuval, you don't need the test

fixed.  do you want to add the script to your repo (I can't and I don't think 
you can simply give write access to personal repos like that one)?


> I should have written the docu earlier... well, I suppose it's better
> late than never.

it's very helpful, thank you!
Yuv
#!/usr/bin/python
# -*- coding: utf-8 -*-

gpl = r"""
    ptoimggen.py - scan a pto file and generate placeholder images
                   and project file to use when debugging
                
    Copyright (C) 2010  Kay F. Jahnke
    Copyright (C) 2010  Yuval Levy

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import sys
import argparse
import parse_pto
import random
import os

# I needed a routine to scan i-lines in pto files and make sure Hugin does
# not complain about missing images or other things.

def imgfile_to_i_lines ( scan ) :


    scan.make_member_access() # makes accessing the data more comfortable ;-)

    # parse all the i lines
    for line in scan.i :

        # get the width, height, and image file name from the i line
        width = line.w.value        # extract the desired values
        height = line.h.value

        # remove the path from the filename
        # postfix the name with '_dummy.jpg' to avoid overwriting
        # existing files and to save space by using the jpg format
        name = os.path.basename ( line.n.value ) + '_dummy.jpg'
        line.n.value = name         # we modify the data in the scan

        # generate random RGB values for the placeholder image
        r = random.randint(0, 255)
        g = random.randint(0, 255)
        b = random.randint(0, 255)

        # comopose the ImageMagick convert command
        cmd = 'convert -size %dx%d xc:"rgb(%d,%d,%d)" -quality 1 %s' % (width, height, r, g , b, name)
        # tell me you're doing something
        print cmd
        # execute it
        os.system(cmd)
            
    # output a modified pto using filenames without a path
    dummified_pto = "dummified_" + scan.filename # that's what we call it
    outfile = open ( dummified_pto , 'w' )       # open the file for writing
    scan.pto ( outfile )

def main() :
    
    # we create an argument parser
    
    parser = argparse.ArgumentParser (
        formatter_class=argparse.RawDescriptionHelpFormatter ,
        description = gpl + '''
    We ask users to post pto files that cause errors
    with their bug reports, but not the actual images to
    avoid straining bandwidth and online storage.

    The first thing a bug hunter does to analyze the pto
    file is to fix the images. This script does it by
    creating placeholder images and a dummy project file
    to play with.

    ''' )
    
    parser.add_argument('-p', '--pto',
                        metavar='<pto file>',
                        type=str,
                        help='pto file to be processed')

    if len ( sys.argv ) < 2 :
        parser.print_help()
        return

    args = parser.parse_args( sys.argv[1:] )

    scan = parse_pto.pto_scan ( args.pto )
    imgfile_to_i_lines ( scan )

# are we main? if so, do the main thing...

if __name__ == "__main__":
    main()

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to