diff --git a/.gitignore b/.gitignore index 56c85b6..64b85fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,10 @@ +.settings +*.pyc +.project +.pydevproject # files for git to ignore .DS_STORE *.sublime-project *.sublime-workspace *.idea -*__pycache__ \ No newline at end of file +*__pycache__ diff --git a/gps/__init__.py b/gpspy3/__init__.py similarity index 58% rename from gps/__init__.py rename to gpspy3/__init__.py index 05bce89..c93c8fb 100644 --- a/gps/__init__.py +++ b/gpspy3/__init__.py @@ -6,8 +6,18 @@ api_major_version = 5 # bumped on incompatible changes api_minor_version = 0 # bumped on compatible changes -from .gps import * -from .misc import * +#Setup a logger that can be imported and used +import logging + +logger = logging.getLogger(__name__) +handler = logging.StreamHandler() +formatter = logging.Formatter( + '%(asctime)s %(name)-12s %(levelname)-8s %(message)s') +handler.setFormatter(formatter) +logger.addHandler(handler) +logger.setLevel(logging.DEBUG) + # The 'client' module exposes some C utility functions for Python clients. # The 'packet' module exposes the packet getter via a Python interface. + diff --git a/gps/client.py b/gpspy3/client.py similarity index 98% rename from gps/client.py rename to gpspy3/client.py index 2467c57..cde3535 100644 --- a/gps/client.py +++ b/gpspy3/client.py @@ -5,6 +5,8 @@ import socket import sys import select #, exceptions +from gpspy3 import logger + if sys.hexversion >= 0x2060000: import json # For Python 2.6 @@ -86,7 +88,7 @@ def read(self): if eol == -1: # ensure that data is available on the socket if not self.waiting(timeout=1): - print("gps.client: no data available on socket") + logger.warn("gps.client: no data available on socket") return -1 frag = self.sock.recv(4096) self.linebuffer += frag.decode() # convert to str diff --git a/gps/fake.py b/gpspy3/fake.py similarity index 99% rename from gps/fake.py rename to gpspy3/fake.py index c65aa0b..d8cc37c 100644 --- a/gps/fake.py +++ b/gpspy3/fake.py @@ -69,7 +69,7 @@ """ import os, sys, time, signal, pty, termios # fcntl, array, struct import threading, socket, select # exceptions -import gps +import gpspy3.gps import packet as sniffer # The two magic numbers below have to be derived from observation. If diff --git a/gps/gps.py b/gpspy3/gps.py similarity index 98% rename from gps/gps.py rename to gpspy3/gps.py index 305f960..6b8ee4c 100644 --- a/gps/gps.py +++ b/gpspy3/gps.py @@ -17,12 +17,12 @@ # The JSON parts of this (which will be reused by any new interface) # now live in a different module. # -from .client import * -from .misc import iso_time +from gpspy3.misc import iso_time +from gpspy3.client import * +from gpspy3 import logger NaN = float('nan') - def isnan(x): return str(x) == 'nan' @@ -286,7 +286,7 @@ def default(k, dflt, vbit=0): self.utc = default("time", None, TIME_SET) if self.utc is not None: # Time can be either Unix time as a float or an ISO8601 string - print("GPS: received fix.time type={}".format(type(self.fix.time))) # TODO: Remove after verified + logger.info("GPS: received fix.time type={}".format(type(self.fix.time))) # TODO: Remove after verified if isinstance(self.fix.time, float): # changed from type(self.fix.time) == type(0.0): self.fix.time = self.utc elif isinstance(self.fix.time, bytes): # added @@ -374,7 +374,7 @@ def stream(self, flags=0, devpath=None): if switch == '-v': verbose = True if len(arguments) > 2: - print('Usage: gps.py [-v] [host [port]]') + logger.error('Usage: gps.py [-v] [host [port]]') sys.exit(1) opts = {"verbose": verbose} diff --git a/gps/misc.py b/gpspy3/misc.py similarity index 100% rename from gps/misc.py rename to gpspy3/misc.py diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..04836db --- /dev/null +++ b/setup.py @@ -0,0 +1,21 @@ +import os +from setuptools import setup, find_packages +from pip.req import parse_requirements +from pip.download import PipSession + +install_reqs = parse_requirements("requirements.txt", session=PipSession()) +reqs = [str(ir.req) for ir in install_reqs] + +setup( + name = "gpspy3", + version = "0.1.0", + packages=find_packages(), + author = "", + author_email = "", + description = (""), + license = "", + keywords = "", + url = "", + install_requires=reqs +) +