Hello all,

first, many thanks to Kay for his Python pto parser that served as basis for 
what follows.

second, a big disclaimer:  my Python experience is very limited.  

Nevertheless, in about half hour of googling and fiddling, I achieved what I 
needed now.

We ask users to provide the pto file associated with bugs reports.  Usually 
just the pto is enough, so to save time, bandwidth, disk space we do not ask 
for the actual images.

As a consequence the first thing that we need to do if we want to visualize a 
project in the GUI is to create placeholder images.

This is what the attached script does.  Tested in Ubuntu.  Requires 
ImageMagick, Python, Kay's pto parser and python-argparse

sudo apt-get install imagemagick python python-argparse
bzr branch lp:~kfj/+junk/script

save the script inside script/main (unless Kay adds it to the repo, then it 
will come automatically)

call with ptoimggen.py -p <PTO-FILE>

Probably Kay will find plenty of ways to improve on this.  More power to him.  
I had enough difficulties finding my way around his code - about the same as I 
have finding my way around the Hugin source code (hint hint comments hint).

Thank you, Kay!
Yuv
#!/usr/bin/python
# -*- coding: utf-8 -*-

gpl = r"""
    ptoimggen.py - scan a pto file and generate bogus images
                   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 all lines in the pto file
    for line in scan.sequential :

        # parse the i lines
        if line.header == 'i' :

            # get the width, height, and image file name from the i line
            width = line.members[0].value
            height = line.members[1].value
            name = line.members[34].value
            # 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)" %s' % (width, height, r, g , b, name)
            # tell me you're doing something
            print cmd
            # execute it
            os.system(cmd)

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.

    This code is very weak and assumes that the image
    name is arguments #34, true at the time of writing.
    You might be dealing with an older pto file (with less
    arguments) or a newer one (with more).  If the result
    is not what you expected, count the arguments and
    fix it around line 45 of this script.
    ''' )
    
    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