File: tool_gpsbabel.py

package info (click to toggle)
pytrainer 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 4,876 kB
  • sloc: python: 15,914; perl: 6,084; xml: 195; sql: 151; makefile: 83; sh: 45
file content (65 lines) | stat: -rw-r--r-- 2,080 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: iso-8859-1 -*-

#Copyright (C) Fiz Vazquez vud1@sindominio.net
# Modified by dgranda

#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 2
#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, write to the Free Software
#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

import logging
import os, sys, subprocess
from lxml import etree

class gpsbabel():
	def __init__(self, parent = None, data_path = None):
		self.parent = parent
		self.pytrainer_main = parent.parent
		self.tmpdir = self.pytrainer_main.profile.tmpdir
		self.main_data_path = data_path
		self.data_path = os.path.dirname(__file__)

	def getName(self):
		return _("GPSBabel")

	def getVersion(self):
		process = subprocess.Popen(['gpsbabel', '-V'],
		                           stdout=subprocess.PIPE,
		                           stderr=subprocess.PIPE)
		stdout, stderr = process.communicate()
		if process.returncode == 0:
			version = stdout.split()
			try:
				return version[2]
			except:
				logging.error("Unexpected result from gpsbabel -V")
				return None
		return None

	def getSourceLocation(self):
		return "http://www.gpsbabel.org/"

	def deviceExists(self):
		try:
			process = subprocess.Popen('lsmod | grep garmin_gps',
			                           stdout=subprocess.PIPE,
			                           stderr=subprocess.PIPE,
			                           shell=True)
			stdout, stderr = process.communicate()
			# stdout is empty if no garmin_gps module loaded
			return stdout != ''
		except:
			return False

	def isPresent(self):
		return self.getVersion() is not None