24 import datetime, sys, os, time |
24 import datetime, sys, os, time |
25 from math import * |
25 from math import * |
26 import xml.etree.ElementTree as etree |
26 import xml.etree.ElementTree as etree |
27 from optparse import OptionParser |
27 from optparse import OptionParser |
28 |
28 |
|
29 def which (program): # test if program is executable or exists in PATH |
|
30 def is_exe (fp): return os.path.isfile (fp) and os.access (fp, os.X_OK) |
|
31 fpath, fname = os.path.split (program) |
|
32 if fpath: |
|
33 if is_exe (program): return program |
|
34 else: |
|
35 for path in os.environ ["PATH"].split (os.pathsep): |
|
36 path = path.strip ('"') |
|
37 exe_file = os.path.join (path, program) |
|
38 if is_exe (exe_file): return exe_file |
|
39 return None |
|
40 |
29 parser = OptionParser('usage: %prog [options] input-file.gpx') |
41 parser = OptionParser('usage: %prog [options] input-file.gpx') |
30 parser.add_option('-g', action='store', type='string', dest='gnuplot', |
42 parser.add_option('-g', action='store', type='string', dest='gnuplot', |
31 default='/usr/bin/gnuplot', help='PATH to the gnuplot binary (or .exe)', metavar='PATH') |
43 default='gnuplot', help='PATH to the gnuplot binary (or .exe)', metavar='PATH') |
32 (options, args) = parser.parse_args() |
44 (options, args) = parser.parse_args() |
33 |
45 |
34 # the path to the gnuplot binary |
46 # find gnuplot binary |
35 gnuPlotCmd = options.gnuplot |
47 gnuPlotCmd = which (options.gnuplot) |
36 if not os.path.exists (gnuPlotCmd): |
48 if not gnuPlotCmd: |
37 print gnuPlotCmd, 'does not exist' |
49 print '***', options.gnuplot, 'does not exist or is not executable\n' |
38 parser.print_help () |
50 parser.print_help () |
39 sys.exit () |
51 sys.exit () |
40 |
52 |
41 if len(args) < 1: |
53 if len(args) < 1: |
42 parser.print_help () |
54 parser.print_help () |