From 11b60f1f009fb75aed2af3b32e2fdd85b578002a Mon Sep 17 00:00:00 2001 From: Johannes Wienke Date: Thu, 5 Jun 2014 22:22:45 +0200 Subject: [PATCH 1/4] Require python3 in shebang line Encode the explicit requirement on python 3 in the shebang line for script usage. --- utils/multires/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 utils/multires/generate.py diff --git a/utils/multires/generate.py b/utils/multires/generate.py old mode 100644 new mode 100755 index c8ec7fd..97a5493 --- a/utils/multires/generate.py +++ b/utils/multires/generate.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Requires Python 3.2+ From 35dd0235092348535c9eaa2ed3f11b3e187186bf Mon Sep 17 00:00:00 2001 From: Johannes Wienke Date: Thu, 5 Jun 2014 22:35:16 +0200 Subject: [PATCH 2/4] Check for nona and add command line argument Checks for a nona executable and adds a command line argument to specify an executable. The argument is required from the user in case nona cannot be found on the path. --- utils/multires/generate.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/utils/multires/generate.py b/utils/multires/generate.py index 97a5493..2dc02d2 100755 --- a/utils/multires/generate.py +++ b/utils/multires/generate.py @@ -27,6 +27,10 @@ import argparse from PIL import Image import os import math +from distutils.spawn import find_executable + +# find external programs +nona = find_executable('nona') # Parse input parser = argparse.ArgumentParser(description='Generate a Pannellum multires tile set from an equirectangular panorama.') @@ -38,6 +42,9 @@ parser.add_argument('-s', '--tilesize', dest='tileSize', default=512, type=int, help='tile size in pixels (default: 512)') parser.add_argument('--png', action='store_true', help='output PNG tiles instead of JPEG tiles') +parser.add_argument('-n', '--nona', default=nona, required=nona is None, + metavar='EXECUTABLE', + help='location of the nona executable to use') args = parser.parse_args() # Create output directory @@ -75,7 +82,7 @@ with open(os.path.join(args.output, 'cubic.pto'), 'w') as f: # Create cube faces print('Generating cube faces...') -os.system('nona -o ' + os.path.join(args.output, 'face') + ' ' + os.path.join(args.output, 'cubic.pto')) +os.system(args.nona + ' -o ' + os.path.join(args.output, 'face') + ' ' + os.path.join(args.output, 'cubic.pto')) faces = ['face0000.tif', 'face0001.tif', 'face0002.tif', 'face0003.tif', 'face0004.tif', 'face0005.tif'] # Generate tiles From 27f48187b6fdd5aa1b6d05589ef2dfb14f61f3c5 Mon Sep 17 00:00:00 2001 From: Johannes Wienke Date: Thu, 5 Jun 2014 22:37:01 +0200 Subject: [PATCH 3/4] Let argparse print default values Use a formatter for argparse to print default values instead of doing this manually. --- utils/multires/generate.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utils/multires/generate.py b/utils/multires/generate.py index 2dc02d2..aa52c11 100755 --- a/utils/multires/generate.py +++ b/utils/multires/generate.py @@ -33,13 +33,14 @@ from distutils.spawn import find_executable nona = find_executable('nona') # Parse input -parser = argparse.ArgumentParser(description='Generate a Pannellum multires tile set from an equirectangular panorama.') +parser = argparse.ArgumentParser(description='Generate a Pannellum multires tile set from an equirectangular panorama.', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('inputFile', metavar='INPUT', help='full equirectangular panorama to be processed') parser.add_argument('-o', '--output', dest='output', default='./output', - help='output directory (default: ./output)') + help='output directory') parser.add_argument('-s', '--tilesize', dest='tileSize', default=512, type=int, - help='tile size in pixels (default: 512)') + help='tile size in pixels') parser.add_argument('--png', action='store_true', help='output PNG tiles instead of JPEG tiles') parser.add_argument('-n', '--nona', default=nona, required=nona is None, From 91005f8e6145e95290133047b21157d5b4c30cb9 Mon Sep 17 00:00:00 2001 From: Johannes Wienke Date: Thu, 5 Jun 2014 22:40:49 +0200 Subject: [PATCH 4/4] Replace system calls with subprocess Replaces the os.system call for nona with a subprocess.check_call call to get informed about errors when calling nona instead of silently ignoring them before failing with missing files. --- utils/multires/generate.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/multires/generate.py b/utils/multires/generate.py index aa52c11..b8121a8 100755 --- a/utils/multires/generate.py +++ b/utils/multires/generate.py @@ -28,6 +28,7 @@ from PIL import Image import os import math from distutils.spawn import find_executable +import subprocess # find external programs nona = find_executable('nona') @@ -83,7 +84,7 @@ with open(os.path.join(args.output, 'cubic.pto'), 'w') as f: # Create cube faces print('Generating cube faces...') -os.system(args.nona + ' -o ' + os.path.join(args.output, 'face') + ' ' + os.path.join(args.output, 'cubic.pto')) +subprocess.check_call([args.nona, '-o', os.path.join(args.output, 'face'), os.path.join(args.output, 'cubic.pto')]) faces = ['face0000.tif', 'face0001.tif', 'face0002.tif', 'face0003.tif', 'face0004.tif', 'face0005.tif'] # Generate tiles