This file is indexed.

/usr/share/doc/twisted-doc/examples/gpsfix.py is in twisted-doc 11.1.0-1ubuntu2.

This file is owned by root:root, with mode 0o644.

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python

# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

"""
GPSTest is a simple example using the SerialPort transport and the NMEA 0183
and Rockwell Zodiac GPS protocols to display fix data as it is received from
the device.
"""
from twisted.python import log, usage
import sys

if sys.platform == 'win32':
    from twisted.internet import win32eventreactor
    win32eventreactor.install()


class GPSFixLogger:
    def handle_fix(self, *args):
      """
      handle_fix gets called whenever either rockwell.Zodiac or nmea.NMEAReceiver
      receives and decodes fix data.  Generally, GPS receivers will report a
      fix at 1hz. Implementing only this method is sufficient for most purposes
      unless tracking of ground speed, course, utc date, or detailed satellite
      information is necessary.

      For example, plotting a map from MapQuest or a similar service only
      requires longitude and latitude.
      """
      log.msg('fix:\n' + 
      '\n'.join(map(lambda n: '  %s = %s' % tuple(n), zip(('utc', 'lon', 'lat', 'fix', 'sat', 'hdp', 'alt', 'geo', 'dgp'), map(repr, args)))))

class GPSOptions(usage.Options):
    optFlags = [
        ['zodiac', 'z', 'Use Rockwell Zodiac (DeLorme Earthmate) [default: NMEA 0183]'],
    ]
    optParameters = [
        ['outfile', 'o', None, 'Logfile [default: sys.stdout]'],
        ['baudrate', 'b', None, 'Serial baudrate [default: 4800 for NMEA, 9600 for Zodiac]'],
        ['port', 'p', '/dev/ttyS0', 'Serial Port device'],
    ]


if __name__ == '__main__':
    from twisted.internet import reactor
    from twisted.internet.serialport import SerialPort

    o = GPSOptions()
    try:
        o.parseOptions()
    except usage.UsageError, errortext:
        print '%s: %s' % (sys.argv[0], errortext)
        print '%s: Try --help for usage details.' % (sys.argv[0])
        raise SystemExit, 1

    logFile = o.opts['outfile']
    if logFile is None:
        logFile = sys.stdout
    log.startLogging(logFile)

    if o.opts['zodiac']:
        from twisted.protocols.gps.rockwell import Zodiac as GPSProtocolBase
        baudrate = 9600
    else:
        from twisted.protocols.gps.nmea import NMEAReceiver as GPSProtocolBase
        baudrate = 4800
    class GPSTest(GPSProtocolBase, GPSFixLogger):
        pass
    
    if o.opts['baudrate']:
        baudrate = int(o.opts['baudrate'])


    port = o.opts['port']
    log.msg('Attempting to open %s at %dbps as a %s device' % (port, baudrate, GPSProtocolBase.__name__))
    s = SerialPort(GPSTest(), o.opts['port'], reactor, baudrate=baudrate)
    reactor.run()