/usr/share/pytrainer/extensions/gpx2garmin/gpx2garmin.py is in pytrainer 1.11.0-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #!/usr/bin/env python
import gtk
import subprocess
import re
class gpx2garmin:
def __init__(self, parent = None, pytrainer_main = None, conf_dir = None, options = None):
self.limit = options["gpx2garminmaxpoints"]
self.device = options["gpx2garmindevice"]
self.conf_dir = conf_dir
self.gpxfile = None
self.tmpgpxfile = "/tmp/_gpx2garmin.gpx"
self.pytrainer_main = pytrainer_main
def prepareGPX(self):
' create an output file and insert a name into the <trk> stanza '
f = open(self.tmpgpxfile, 'w')
name = 'default'
for line in open(self.gpxfile):
if re.search('^<name>.+</name>$', line):
name = line
elif re.search('^<trk>$', line):
line = '%s%s' % (line, name)
f.write(line)
f.close()
def exportGPX(self):
' export the GPX file using gpsbabel '
cmd = ["gpsbabel", "-t", "-i", "gpx", "-f", self.tmpgpxfile, "-o", "garmin"]
if self.limit is not None:
cmd = cmd + ["-x", "simplify,count=%s" % self.limit]
cmd = cmd + ["-F", self.device]
return subprocess.call(cmd)
def run(self, id, activity=None):
' main extension method '
self.gpxfile = "%s/gpx/%s.gpx" % (self.conf_dir, id)
self.log = "Export "
try:
self.prepareGPX()
if self.exportGPX() == 1:
# assume no device present?
self.log = self.log + "failed - no device present?"
else:
self.log = self.log + "succeeded!"
except:
self.log = self.log + "failed!"
md = gtk.MessageDialog(self.pytrainer_main.windowmain.window1, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, self.log)
md.set_title(_("gpx2garmin Extension"))
md.set_modal(False)
md.run()
md.destroy()
|