← Back to team overview

phatch-dev team mailing list archive

[Merge] lp:~bryant-ohara/phatch/pep8check into lp:phatch

 

stani has proposed merging lp:~bryant-ohara/phatch/pep8check into lp:phatch.

    Requested reviews:
    stani (stani)


Looks good to me, I'll merge so others are not doing the same files.
-- 
https://code.launchpad.net/~bryant-ohara/phatch/pep8check/+merge/20462
Your team Phatch Developers is subscribed to branch lp:phatch.
=== modified file 'phatch/lib/__init__.py'
--- phatch/lib/__init__.py	2009-08-20 17:03:51 +0000
+++ phatch/lib/__init__.py	2010-03-02 17:48:22 +0000
@@ -9,6 +9,8 @@
 # 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, see http://www.gnu.org/licenses/
\ No newline at end of file
+# along with this program.  If not, see http://www.gnu.org/licenses/
+
+# Follows PEP8

=== modified file 'phatch/lib/events.py'
--- phatch/lib/events.py	2010-02-24 21:00:07 +0000
+++ phatch/lib/events.py	2010-03-02 17:48:22 +0000
@@ -9,10 +9,12 @@
 # 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, see http://www.gnu.org/licenses/
 
+# Follows PEP8
+
 """The aim of this library is to abstract pubsub."""
 #check this for the console version (wx should dissappear)
 try:
@@ -20,78 +22,86 @@
 except ImportError:
     from wx.lib.pubsub import ALL_TOPICS, Publisher
 
+
 #---Send
 class SendListener:
-    def __init__(self,topic=ALL_TOPICS):
-        self.topic  = topic
-        
+    def __init__(self, topic=ALL_TOPICS):
+        self.topic = topic
+
     def __call__(self, *args, **keyw):
-        data    = (args,keyw) #pack (see ReceiveListener.__call__)
-        return Publisher().sendMessage(self.topic,data)
-    
+        data = (args, keyw)  # pack (see ReceiveListener.__call__)
+        return Publisher().sendMessage(self.topic, data)
+
+
 class Sender:
-    def __getattr__(self,topic):
+    def __getattr__(self, topic):
         return SendListener(topic)
-    
-send    = Sender()
+
+send = Sender()
 
 #---Receive
-def subscribe(method,obj):
-    Publisher().subscribe(method,getattr(obj,method))
-    
+
+
+def subscribe(method, obj):
+    Publisher().subscribe(method, getattr(obj, method))
+
+
 class ReceiveListener:
-    def __init__(self,obj,method):
-        self.method = getattr(obj,method)
-        
-    def __call__(self,message):
-        args, keyw  = message.data #unpack (see SendListener.__call__)
+    def __init__(self, obj, method):
+        self.method = getattr(obj, method)
+
+    def __call__(self, message):
+        args, keyw = message.data  # unpack (see SendListener.__call__)
         return self.method(*args, **keyw)
-    
+
+
 class Receiver:
-    def __init__(self,name):
-        self._pubsub_name           = name
-        self._listeners             = []
-        
-    def subscribe(self,method):
+    def __init__(self, name):
+        self._pubsub_name = name
+        self._listeners = []
+
+    def subscribe(self, method):
         """Subscribe with some class magic.
         Example: self.subscribe('error') -> subscribe('frame.error')
         Afterwars you can call it with send.frame_error()"""
-        listener  = ReceiveListener(self,method)
+        listener = ReceiveListener(self, method)
         self._listeners.append(listener)
-        Publisher().subscribe(listener,'%s_%s' % (self._pubsub_name,method))
-        
-    def unsubscribe(self,method):
+        Publisher().subscribe(listener, '%s_%s' % (self._pubsub_name, method))
+
+    def unsubscribe(self, method):
         """Subscribe with some class magic.
         Example: self.subscribe('error') -> subscribe('frame.error')"""
-        listener  = ReceiveListener(self,method)
+        listener = ReceiveListener(self, method)
         self._listeners.remove(listener)
-        Publisher().unsubscribe(listener,'%s_%s' % (self._pubsub_name,method))
-        
+        Publisher().unsubscribe(listener,
+                                '%s_%s' % (self._pubsub_name, method))
+
     def unsubscribe_all(self):
         for listener in self._listeners:
             Publisher().unsubscribe(listener)
         self._listeners = []
-        
+
+
 def example():
     import sys
-    
+
     class Test(Receiver):
         def __init__(self):
             #register an instance
-            Receiver.__init__(self,'test')
+            Receiver.__init__(self, 'test')
             #register the method send.test_write -> self.write
             self.subscribe('write')
             self.phrase = 'planet'
-            
-        def write(self,phrase,error):
+
+        def write(self, phrase, error):
             sys.stdout.write(phrase + '\n')
             sys.stderr.write(error)
             self.phrase = phrase
-            
-    demo    = Test()
-    phrase  = 'hello world'
-    send.test_write(phrase,error='(No error.)')
-    assert demo.phrase  == phrase 
-            
+
+    demo = Test()
+    phrase = 'hello world'
+    send.test_write(phrase, error='(No error.)')
+    assert demo.phrase == phrase
+
 if __name__ == '__main__':
-    example()
\ No newline at end of file
+    example()

=== modified file 'phatch/lib/gps.py'
--- phatch/lib/gps.py	2010-02-24 21:00:07 +0000
+++ phatch/lib/gps.py	2010-03-02 17:48:22 +0000
@@ -16,6 +16,8 @@
 # All rights donated to the open source project Phatch. This code may
 # be published using a license acceptable to project Phatch.
 
+# Follows PEP8
+
 import os
 import time
 import datetime
@@ -29,31 +31,36 @@
     pyexiv2 = None
 
 # Rational number support
+
+
 def r(f):
     """r(float) - get a Rational number for a float"""
     s = surd.surd(float(f))
-    return pyexiv2.Rational(s.num,s.denom)
+    return pyexiv2.Rational(s.num, s.denom)
+
 
 def d(angle):
     """d(any) - get degrees from a number :eg d(33.41) -> 33"""
     return int(angle)
 
+
 def m(angle):
     """m(any) - get minutes from a number :eg d(33.41) -> 24"""
-    return int( angle*60 - d(angle) * 60)
+    return int(angle * 60 - d(angle) * 60)
+
 
 def s(angle):
     """s(any) - get seconds from a number :eg s(33.41) -> 36"""
-    return int( angle*3600 - d(angle) * 3600 - m(angle) * 60 )
+    return int(angle * 3600 - d(angle) * 3600 - m(angle) * 60)
 
 
 # dictionary search (closest match)
-def search(dict,target):
+def search(dict, target):
     """search(dict,taget) - search for closest match"""
-    s    = sorted(dict.keys())
-    N    = len(s)
-    low  = 0
-    high = N-1
+    s = sorted(dict.keys())
+    N = len(s)
+    low = 0
+    high = N - 1
 
     while low < high:
         mid = (low + high) / 2
@@ -63,17 +70,19 @@
             high = mid
     return s[low]
 
+
 # XML functions
-def get_xml_timez(phototime,timeshift):
+def get_xml_timez(phototime, timeshift):
     """getXMLtimez - convert a datetime to an XML formatted date"""
     #
     # phototime = timedate.timedate("2008-03-16 08:52:15")
     # timeshift = seconds
     # -----------------------
 
-    timedelta = datetime.timedelta(0,timeshift,0)
+    timedelta = datetime.timedelta(0, timeshift, 0)
     newtime = phototime + timedelta
-    return newtime.strftime('%Y-%m-%dT%H:%M:%SZ') ;
+    return newtime.strftime('%Y-%m-%dT%H:%M:%SZ')
+
 
 def get_text(nodelist,):
     """get_text(nodeList) - return the text in nodelist"""
@@ -83,19 +92,21 @@
             rc = rc + node.data
     return rc
 
+
 def get_node_value(node):
     """get_node_value((node) - return the value of a node"""
     return get_text(node.childNodes)
 
-def handle_trkpt(trkpt,timedict,ns):
+
+def handle_trkpt(trkpt, timedict, ns):
     """handle_trkpt"""
     if ns:
-        ele     = get_node_value(
-                    trkpt.getElementsByTagNameNS(ns,"ele")[0])
-        time    = get_node_value(
-                    trkpt.getElementsByTagNameNS(ns,"time")[0])
-        lat     = trkpt.getAttributeNS(ns,"lat")
-        lon     = trkpt.getAttributeNS(ns,"lon")
+        ele = get_node_value(
+                    trkpt.getElementsByTagNameNS(ns, "ele")[0])
+        time = get_node_value(
+                    trkpt.getElementsByTagNameNS(ns, "time")[0])
+        lat = trkpt.getAttributeNS(ns, "lat")
+        lon = trkpt.getAttributeNS(ns, "lon")
         # Garmin .gpx doesn't use a ns on the lat and lon attributes!
         # Garmin bug?
         if not lat:
@@ -103,58 +114,62 @@
         if not lon:
             lon = trkpt.getAttribute("lon")
     else:
-        ele     = get_node_value(trkpt.getElementsByTagName("ele" )[0])
-        time    = get_node_value(trkpt.getElementsByTagName("time")[0])
-        lat     = trkpt.getAttribute("lat")
-        lon     = trkpt.getAttribute("lon")
+        ele = get_node_value(trkpt.getElementsByTagName("ele")[0])
+        time = get_node_value(trkpt.getElementsByTagName("time")[0])
+        lat = trkpt.getAttribute("lat")
+        lon = trkpt.getAttribute("lon")
     # print "lat, lon = %s %s ele,time = %s %s" % ( lat,lon  , ele,time)
-    timedict[time] = [ ele,lat,lon ]
-
-def handle_trkseg(trkseg,timedict,ns):
+    timedict[time] = [ele, lat, lon]
+
+
+def handle_trkseg(trkseg, timedict, ns):
     """handle_trkseg"""
     if ns:
-        trkpts = trkseg.getElementsByTagNameNS(ns,"trkpt")
+        trkpts = trkseg.getElementsByTagNameNS(ns, "trkpt")
     else:
         trkpts = trkseg.getElementsByTagName("trkpt")
     for trkpt in trkpts:
-        handle_trkpt(trkpt,timedict,ns)
-
-def handle_trk(trk,timedict,ns):
+        handle_trkpt(trkpt, timedict, ns)
+
+
+def handle_trk(trk, timedict, ns):
     """handle_trk"""
     if ns:
-        trksegs = trk.getElementsByTagNameNS(ns,"trkseg")
+        trksegs = trk.getElementsByTagNameNS(ns, "trkseg")
     else:
         trksegs = trk.getElementsByTagName("trkseg")
     for trkseg in trksegs:
-        handle_trkseg(trkseg,timedict,ns)
-
-def handle_gpx(gpx,timedict,ns):
+        handle_trkseg(trkseg, timedict, ns)
+
+
+def handle_gpx(gpx, timedict, ns):
     """handle_gpx"""
     if ns:
-        trks = gpx.getElementsByTagNameNS(ns,"trk")
+        trks = gpx.getElementsByTagNameNS(ns, "trk")
     else:
-        trks =  gpx.getElementsByTagName("trk")
+        trks = gpx.getElementsByTagName("trk")
     for trk in trks:
-        handle_trk(trk,timedict,ns)
+        handle_trk(trk, timedict, ns)
 
 # GPS module API
 
+
 # this code is heading for module core.lib.gps
 def read_gpx(gpx_file):
     """read_gpx(string) -
     get a dictionary of time/position information"""
     timedict = {}
     #print "read_gpx = " + gpx_file
-    file     = open(gpx_file,"r")
-    data     = file.read(os.path.getsize(gpx_file))
+    file = open(gpx_file, "r")
+    data = file.read(os.path.getsize(gpx_file))
     #print "reading ",gpx_file
     file.close()
     dom = xml.dom.minidom.parseString(data)
 
     # read the XML with and without the namepace
-    handle_gpx(dom,timedict,False)
+    handle_gpx(dom, timedict, False)
     ns = 'http://www.topografix.com/GPX/1/1'
-    handle_gpx(dom,timedict,ns)
+    handle_gpx(dom, timedict, ns)
 
     return timedict
 
@@ -168,7 +183,7 @@
 
 # returns the metadata dictionary for given exif date
 # eg 'Exif_Image_DateTime'
-def get_metadata(dateString,timedict,timeshift,path,report=None):
+def get_metadata(dateString, timedict, timeshift, path, report=None):
     """get_metadata(float) - get a dictionary of changes to the metadata
        dateString - EXIF date format string /* in */
        timeshift  - delta between GMT and local time (seconds.
@@ -178,54 +193,53 @@
     """
     if not pyexiv2:
         raise ImportError('pyexiv2 is not installed')
-    stamp       = str(get_xml_timez(dateString,timeshift))
-
-    timestamp   = search(timedict,stamp)
-    data        = timedict[timestamp]
-    ele         = float(data[0])
-    lat         = float(data[1])
-    lon         = float(data[2])
-
-    latR    = 'N'
-    lonR    = 'E'
-    eleR    =  0
-    if lat  < 0:
+    stamp = str(get_xml_timez(dateString, timeshift))
+
+    timestamp = search(timedict, stamp)
+    data = timedict[timestamp]
+    ele = float(data[0])
+    lat = float(data[1])
+    lon = float(data[2])
+
+    latR = 'N'
+    lonR = 'E'
+    eleR = 0
+    if lat < 0:
         lat = -lat
-        latR= 'S'
-    if lon  < 0:
+        latR = 'S'
+    if lon < 0:
         lon = -lon
-        lonR= 'W'
+        lonR = 'W'
     sele = "%6.1f" % (ele)
-    if ele  < 0:
+    if ele < 0:
         ele = -ele
-        eleR= 1
+        eleR = 1
 
-    slat = "%02d.%02d'" '%02d"%s' % (d(lat),m(lat),s(lat),latR )
-    slon = "%02d.%02d'" '%02d"%s' % (d(lon),m(lon),s(lon),lonR )
+    slat = "%02d.%02d'" '%02d"%s' % (d(lat), m(lat), s(lat), latR)
+    slon = "%02d.%02d'" '%02d"%s' % (d(lon), m(lon), s(lon), lonR)
     if report:
-        report.write(",".join([stamp,timestamp,slat,slon,sele,path])\
-            +"\n")
+        report.write(",".join([stamp, timestamp, slat, slon, sele, path])\
+            + "\n")
     # get Rational number for ele
     # don't know why r(ele) is causing trouble!
     # it might be that the denominator is overflowing 32 bits!
     # and this would also import lat and lon
-    rele = pyexiv2.Rational(int(ele*10.0),10)
+    rele = pyexiv2.Rational(int(ele * 10.0), 10)
     # create and return the dictionary of tags to be added to the image
     metadata = {}
-    metadata['Exif_GPSInfo_GPSAltitude'            ] = rele
-    metadata['Exif_GPSInfo_GPSAltitudeRef'         ] = eleR
-    metadata['Exif_GPSInfo_GPSDateStamp'           ] = stamp
-    metadata['Exif_GPSInfo_GPSLatitude'            ] = \
-        [r(d(lat)),r(m(lat)),r(s(lat))]
-    metadata['Exif_GPSInfo_GPSLatitudeRef'         ] = latR
-    metadata['Exif_GPSInfo_GPSLongitude'           ] = \
-        [r(d(lon)),r(m(lon)),r(s(lon))]
-    metadata['Exif_GPSInfo_GPSLongitudeRef'        ] = lonR
-    metadata['Exif_GPSInfo_GPSMapDatum'            ] = 'WGS-84'
-    metadata['Exif_GPSInfo_GPSProcessingMethod'    ] = \
+    metadata['Exif_GPSInfo_GPSAltitude'] = rele
+    metadata['Exif_GPSInfo_GPSAltitudeRef'] = eleR
+    metadata['Exif_GPSInfo_GPSDateStamp'] = stamp
+    metadata['Exif_GPSInfo_GPSLatitude'] = \
+        [r(d(lat)), r(m(lat)), r(s(lat))]
+    metadata['Exif_GPSInfo_GPSLatitudeRef'] = latR
+    metadata['Exif_GPSInfo_GPSLongitude'] = \
+        [r(d(lon)), r(m(lon)), r(s(lon))]
+    metadata['Exif_GPSInfo_GPSLongitudeRef'] = lonR
+    metadata['Exif_GPSInfo_GPSMapDatum'] = 'WGS-84'
+    metadata['Exif_GPSInfo_GPSProcessingMethod'] = \
         '65 83 67 73 73 0 0 0 72 89 66 82 73 68 45 70 73 88 '
-    metadata['Exif_GPSInfo_GPSTimeStamp'           ] = \
-        [r(10),r(20),r(30)]
-    metadata['Exif_GPSInfo.GPSVersionID'           ] = '2 2 0 0'
+    metadata['Exif_GPSInfo_GPSTimeStamp'] = \
+        [r(10), r(20), r(30)]
+    metadata['Exif_GPSInfo.GPSVersionID'] = '2 2 0 0'
     return metadata
-


References