~ubuntu-branches/ubuntu/precise/pytrainer/precise

« back to all changes in this revision

Viewing changes to import/tool_gpsbabel.py

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-02-04 06:07:11 UTC
  • mfrom: (4.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100204060711-25n5aw66w5egeiph
Tags: 1.7.1-1ubuntu1
* Merge from debian testing, remaining changes:
  - debian/control:
    + Replace Depends on iceweasel with firefox | abrowser.
    + Bump python-dev,debhelper build-dependencies.
    - Drop dependency on python-glade2 (libglade -> gtkbuilder transition).
  - debian/rules:
    + Append --install-laoyut=deb to setup.py install to prevent a build
      failure with Python 2.6.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: iso-8859-1 -*-
 
2
 
 
3
#Copyright (C) Fiz Vazquez vud1@sindominio.net
 
4
# Modified by dgranda
 
5
 
 
6
#This program is free software; you can redistribute it and/or
 
7
#modify it under the terms of the GNU General Public License
 
8
#as published by the Free Software Foundation; either version 2
 
9
#of the License, or (at your option) any later version.
 
10
 
 
11
#This program is distributed in the hope that it will be useful,
 
12
#but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#GNU General Public License for more details.
 
15
 
 
16
#You should have received a copy of the GNU General Public License
 
17
#along with this program; if not, write to the Free Software
 
18
#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
19
 
 
20
import logging
 
21
import os, sys, commands
 
22
import StringIO
 
23
from lxml import etree
 
24
import dateutil.parser
 
25
from dateutil.tz import * # for tzutc()
 
26
 
 
27
from pytrainer.lib.system import checkConf
 
28
 
 
29
class gpsbabel():
 
30
        def __init__(self, parent = None, data_path = None):
 
31
                self.parent = parent
 
32
                self.conf = checkConf()
 
33
                self.tmpdir = self.conf.getValue("tmpdir")
 
34
                self.main_data_path = data_path
 
35
                self.data_path = os.path.dirname(__file__)
 
36
 
 
37
        def getName(self):
 
38
                return _("GPSBabel")
 
39
 
 
40
        def getVersion(self):
 
41
                result = commands.getstatusoutput('gpsbabel -V')
 
42
                if result[0] == 0:
 
43
                        version = result[1].split()
 
44
                        try:
 
45
                                return version[2]
 
46
                        except:
 
47
                                logging.error("Unexpected result from gpsbabel -V")
 
48
                                return None
 
49
                return None
 
50
 
 
51
        def getSourceLocation(self):
 
52
                return "http://www.gpsbabel.org/"
 
53
 
 
54
        def deviceExists(self):
 
55
                try:
 
56
                        #TODO Check if this is correct???
 
57
                        outmod = commands.getstatusoutput('/sbin/lsmod | grep garmin_gps')
 
58
                        if outmod[0]==256:      #there is no garmin_gps module loaded
 
59
                                return False
 
60
                        else:
 
61
                                return True
 
62
                except:
 
63
                        return False
 
64
 
 
65
        def isPresent(self):
 
66
                if self.getVersion():
 
67
                        return True
 
68
                else:
 
69
                        return False
 
70
        
 
71
        def getDateTime(self, time_):
 
72
                # Time can be in multiple formats
 
73
                # - zulu                        2009-12-15T09:00Z
 
74
                # - local ISO8601       2009-12-15T10:00+01:00
 
75
                if time_ is None or time_ == "":
 
76
                        return (None, None)
 
77
                dateTime = dateutil.parser.parse(time_)
 
78
                timezone = dateTime.tzname()
 
79
                if timezone == 'UTC': #got a zulu time
 
80
                        local_dateTime = dateTime.astimezone(tzlocal()) #datetime with localtime offset (from OS)
 
81
                else:
 
82
                        local_dateTime = dateTime #use datetime as supplied
 
83
                utc_dateTime = dateTime.astimezone(tzutc()) #datetime with 00:00 offset
 
84
                return (utc_dateTime,local_dateTime)