Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~bryant-ohara/phatch/pep8check |
Merge into: | lp:phatch |
Diff against target: |
458 lines (+149/-123) 3 files modified
phatch/lib/__init__.py (+4/-2) phatch/lib/events.py (+53/-43) phatch/lib/gps.py (+92/-78) |
To merge this branch: | bzr merge lp:~bryant-ohara/phatch/pep8check |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Stani | Approve | ||
Review via email: mp+20462@code.launchpad.net |
Commit message
Description of the change
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'phatch/lib/__init__.py' |
2 | --- phatch/lib/__init__.py 2009-08-20 17:03:51 +0000 |
3 | +++ phatch/lib/__init__.py 2010-03-02 17:48:22 +0000 |
4 | @@ -9,6 +9,8 @@ |
5 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
6 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7 | # GNU General Public License for more details. |
8 | -# |
9 | +# |
10 | # You should have received a copy of the GNU General Public License |
11 | -# along with this program. If not, see http://www.gnu.org/licenses/ |
12 | \ No newline at end of file |
13 | +# along with this program. If not, see http://www.gnu.org/licenses/ |
14 | + |
15 | +# Follows PEP8 |
16 | |
17 | === modified file 'phatch/lib/events.py' |
18 | --- phatch/lib/events.py 2010-02-24 21:00:07 +0000 |
19 | +++ phatch/lib/events.py 2010-03-02 17:48:22 +0000 |
20 | @@ -9,10 +9,12 @@ |
21 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | # GNU General Public License for more details. |
24 | -# |
25 | +# |
26 | # You should have received a copy of the GNU General Public License |
27 | # along with this program. If not, see http://www.gnu.org/licenses/ |
28 | |
29 | +# Follows PEP8 |
30 | + |
31 | """The aim of this library is to abstract pubsub.""" |
32 | #check this for the console version (wx should dissappear) |
33 | try: |
34 | @@ -20,78 +22,86 @@ |
35 | except ImportError: |
36 | from wx.lib.pubsub import ALL_TOPICS, Publisher |
37 | |
38 | + |
39 | #---Send |
40 | class SendListener: |
41 | - def __init__(self,topic=ALL_TOPICS): |
42 | - self.topic = topic |
43 | - |
44 | + def __init__(self, topic=ALL_TOPICS): |
45 | + self.topic = topic |
46 | + |
47 | def __call__(self, *args, **keyw): |
48 | - data = (args,keyw) #pack (see ReceiveListener.__call__) |
49 | - return Publisher().sendMessage(self.topic,data) |
50 | - |
51 | + data = (args, keyw) # pack (see ReceiveListener.__call__) |
52 | + return Publisher().sendMessage(self.topic, data) |
53 | + |
54 | + |
55 | class Sender: |
56 | - def __getattr__(self,topic): |
57 | + def __getattr__(self, topic): |
58 | return SendListener(topic) |
59 | - |
60 | -send = Sender() |
61 | + |
62 | +send = Sender() |
63 | |
64 | #---Receive |
65 | -def subscribe(method,obj): |
66 | - Publisher().subscribe(method,getattr(obj,method)) |
67 | - |
68 | + |
69 | + |
70 | +def subscribe(method, obj): |
71 | + Publisher().subscribe(method, getattr(obj, method)) |
72 | + |
73 | + |
74 | class ReceiveListener: |
75 | - def __init__(self,obj,method): |
76 | - self.method = getattr(obj,method) |
77 | - |
78 | - def __call__(self,message): |
79 | - args, keyw = message.data #unpack (see SendListener.__call__) |
80 | + def __init__(self, obj, method): |
81 | + self.method = getattr(obj, method) |
82 | + |
83 | + def __call__(self, message): |
84 | + args, keyw = message.data # unpack (see SendListener.__call__) |
85 | return self.method(*args, **keyw) |
86 | - |
87 | + |
88 | + |
89 | class Receiver: |
90 | - def __init__(self,name): |
91 | - self._pubsub_name = name |
92 | - self._listeners = [] |
93 | - |
94 | - def subscribe(self,method): |
95 | + def __init__(self, name): |
96 | + self._pubsub_name = name |
97 | + self._listeners = [] |
98 | + |
99 | + def subscribe(self, method): |
100 | """Subscribe with some class magic. |
101 | Example: self.subscribe('error') -> subscribe('frame.error') |
102 | Afterwars you can call it with send.frame_error()""" |
103 | - listener = ReceiveListener(self,method) |
104 | + listener = ReceiveListener(self, method) |
105 | self._listeners.append(listener) |
106 | - Publisher().subscribe(listener,'%s_%s' % (self._pubsub_name,method)) |
107 | - |
108 | - def unsubscribe(self,method): |
109 | + Publisher().subscribe(listener, '%s_%s' % (self._pubsub_name, method)) |
110 | + |
111 | + def unsubscribe(self, method): |
112 | """Subscribe with some class magic. |
113 | Example: self.subscribe('error') -> subscribe('frame.error')""" |
114 | - listener = ReceiveListener(self,method) |
115 | + listener = ReceiveListener(self, method) |
116 | self._listeners.remove(listener) |
117 | - Publisher().unsubscribe(listener,'%s_%s' % (self._pubsub_name,method)) |
118 | - |
119 | + Publisher().unsubscribe(listener, |
120 | + '%s_%s' % (self._pubsub_name, method)) |
121 | + |
122 | def unsubscribe_all(self): |
123 | for listener in self._listeners: |
124 | Publisher().unsubscribe(listener) |
125 | self._listeners = [] |
126 | - |
127 | + |
128 | + |
129 | def example(): |
130 | import sys |
131 | - |
132 | + |
133 | class Test(Receiver): |
134 | def __init__(self): |
135 | #register an instance |
136 | - Receiver.__init__(self,'test') |
137 | + Receiver.__init__(self, 'test') |
138 | #register the method send.test_write -> self.write |
139 | self.subscribe('write') |
140 | self.phrase = 'planet' |
141 | - |
142 | - def write(self,phrase,error): |
143 | + |
144 | + def write(self, phrase, error): |
145 | sys.stdout.write(phrase + '\n') |
146 | sys.stderr.write(error) |
147 | self.phrase = phrase |
148 | - |
149 | - demo = Test() |
150 | - phrase = 'hello world' |
151 | - send.test_write(phrase,error='(No error.)') |
152 | - assert demo.phrase == phrase |
153 | - |
154 | + |
155 | + demo = Test() |
156 | + phrase = 'hello world' |
157 | + send.test_write(phrase, error='(No error.)') |
158 | + assert demo.phrase == phrase |
159 | + |
160 | if __name__ == '__main__': |
161 | - example() |
162 | \ No newline at end of file |
163 | + example() |
164 | |
165 | === modified file 'phatch/lib/gps.py' |
166 | --- phatch/lib/gps.py 2010-02-24 21:00:07 +0000 |
167 | +++ phatch/lib/gps.py 2010-03-02 17:48:22 +0000 |
168 | @@ -16,6 +16,8 @@ |
169 | # All rights donated to the open source project Phatch. This code may |
170 | # be published using a license acceptable to project Phatch. |
171 | |
172 | +# Follows PEP8 |
173 | + |
174 | import os |
175 | import time |
176 | import datetime |
177 | @@ -29,31 +31,36 @@ |
178 | pyexiv2 = None |
179 | |
180 | # Rational number support |
181 | + |
182 | + |
183 | def r(f): |
184 | """r(float) - get a Rational number for a float""" |
185 | s = surd.surd(float(f)) |
186 | - return pyexiv2.Rational(s.num,s.denom) |
187 | + return pyexiv2.Rational(s.num, s.denom) |
188 | + |
189 | |
190 | def d(angle): |
191 | """d(any) - get degrees from a number :eg d(33.41) -> 33""" |
192 | return int(angle) |
193 | |
194 | + |
195 | def m(angle): |
196 | """m(any) - get minutes from a number :eg d(33.41) -> 24""" |
197 | - return int( angle*60 - d(angle) * 60) |
198 | + return int(angle * 60 - d(angle) * 60) |
199 | + |
200 | |
201 | def s(angle): |
202 | """s(any) - get seconds from a number :eg s(33.41) -> 36""" |
203 | - return int( angle*3600 - d(angle) * 3600 - m(angle) * 60 ) |
204 | + return int(angle * 3600 - d(angle) * 3600 - m(angle) * 60) |
205 | |
206 | |
207 | # dictionary search (closest match) |
208 | -def search(dict,target): |
209 | +def search(dict, target): |
210 | """search(dict,taget) - search for closest match""" |
211 | - s = sorted(dict.keys()) |
212 | - N = len(s) |
213 | - low = 0 |
214 | - high = N-1 |
215 | + s = sorted(dict.keys()) |
216 | + N = len(s) |
217 | + low = 0 |
218 | + high = N - 1 |
219 | |
220 | while low < high: |
221 | mid = (low + high) / 2 |
222 | @@ -63,17 +70,19 @@ |
223 | high = mid |
224 | return s[low] |
225 | |
226 | + |
227 | # XML functions |
228 | -def get_xml_timez(phototime,timeshift): |
229 | +def get_xml_timez(phototime, timeshift): |
230 | """getXMLtimez - convert a datetime to an XML formatted date""" |
231 | # |
232 | # phototime = timedate.timedate("2008-03-16 08:52:15") |
233 | # timeshift = seconds |
234 | # ----------------------- |
235 | |
236 | - timedelta = datetime.timedelta(0,timeshift,0) |
237 | + timedelta = datetime.timedelta(0, timeshift, 0) |
238 | newtime = phototime + timedelta |
239 | - return newtime.strftime('%Y-%m-%dT%H:%M:%SZ') ; |
240 | + return newtime.strftime('%Y-%m-%dT%H:%M:%SZ') |
241 | + |
242 | |
243 | def get_text(nodelist,): |
244 | """get_text(nodeList) - return the text in nodelist""" |
245 | @@ -83,19 +92,21 @@ |
246 | rc = rc + node.data |
247 | return rc |
248 | |
249 | + |
250 | def get_node_value(node): |
251 | """get_node_value((node) - return the value of a node""" |
252 | return get_text(node.childNodes) |
253 | |
254 | -def handle_trkpt(trkpt,timedict,ns): |
255 | + |
256 | +def handle_trkpt(trkpt, timedict, ns): |
257 | """handle_trkpt""" |
258 | if ns: |
259 | - ele = get_node_value( |
260 | - trkpt.getElementsByTagNameNS(ns,"ele")[0]) |
261 | - time = get_node_value( |
262 | - trkpt.getElementsByTagNameNS(ns,"time")[0]) |
263 | - lat = trkpt.getAttributeNS(ns,"lat") |
264 | - lon = trkpt.getAttributeNS(ns,"lon") |
265 | + ele = get_node_value( |
266 | + trkpt.getElementsByTagNameNS(ns, "ele")[0]) |
267 | + time = get_node_value( |
268 | + trkpt.getElementsByTagNameNS(ns, "time")[0]) |
269 | + lat = trkpt.getAttributeNS(ns, "lat") |
270 | + lon = trkpt.getAttributeNS(ns, "lon") |
271 | # Garmin .gpx doesn't use a ns on the lat and lon attributes! |
272 | # Garmin bug? |
273 | if not lat: |
274 | @@ -103,58 +114,62 @@ |
275 | if not lon: |
276 | lon = trkpt.getAttribute("lon") |
277 | else: |
278 | - ele = get_node_value(trkpt.getElementsByTagName("ele" )[0]) |
279 | - time = get_node_value(trkpt.getElementsByTagName("time")[0]) |
280 | - lat = trkpt.getAttribute("lat") |
281 | - lon = trkpt.getAttribute("lon") |
282 | + ele = get_node_value(trkpt.getElementsByTagName("ele")[0]) |
283 | + time = get_node_value(trkpt.getElementsByTagName("time")[0]) |
284 | + lat = trkpt.getAttribute("lat") |
285 | + lon = trkpt.getAttribute("lon") |
286 | # print "lat, lon = %s %s ele,time = %s %s" % ( lat,lon , ele,time) |
287 | - timedict[time] = [ ele,lat,lon ] |
288 | - |
289 | -def handle_trkseg(trkseg,timedict,ns): |
290 | + timedict[time] = [ele, lat, lon] |
291 | + |
292 | + |
293 | +def handle_trkseg(trkseg, timedict, ns): |
294 | """handle_trkseg""" |
295 | if ns: |
296 | - trkpts = trkseg.getElementsByTagNameNS(ns,"trkpt") |
297 | + trkpts = trkseg.getElementsByTagNameNS(ns, "trkpt") |
298 | else: |
299 | trkpts = trkseg.getElementsByTagName("trkpt") |
300 | for trkpt in trkpts: |
301 | - handle_trkpt(trkpt,timedict,ns) |
302 | - |
303 | -def handle_trk(trk,timedict,ns): |
304 | + handle_trkpt(trkpt, timedict, ns) |
305 | + |
306 | + |
307 | +def handle_trk(trk, timedict, ns): |
308 | """handle_trk""" |
309 | if ns: |
310 | - trksegs = trk.getElementsByTagNameNS(ns,"trkseg") |
311 | + trksegs = trk.getElementsByTagNameNS(ns, "trkseg") |
312 | else: |
313 | trksegs = trk.getElementsByTagName("trkseg") |
314 | for trkseg in trksegs: |
315 | - handle_trkseg(trkseg,timedict,ns) |
316 | - |
317 | -def handle_gpx(gpx,timedict,ns): |
318 | + handle_trkseg(trkseg, timedict, ns) |
319 | + |
320 | + |
321 | +def handle_gpx(gpx, timedict, ns): |
322 | """handle_gpx""" |
323 | if ns: |
324 | - trks = gpx.getElementsByTagNameNS(ns,"trk") |
325 | + trks = gpx.getElementsByTagNameNS(ns, "trk") |
326 | else: |
327 | - trks = gpx.getElementsByTagName("trk") |
328 | + trks = gpx.getElementsByTagName("trk") |
329 | for trk in trks: |
330 | - handle_trk(trk,timedict,ns) |
331 | + handle_trk(trk, timedict, ns) |
332 | |
333 | # GPS module API |
334 | |
335 | + |
336 | # this code is heading for module core.lib.gps |
337 | def read_gpx(gpx_file): |
338 | """read_gpx(string) - |
339 | get a dictionary of time/position information""" |
340 | timedict = {} |
341 | #print "read_gpx = " + gpx_file |
342 | - file = open(gpx_file,"r") |
343 | - data = file.read(os.path.getsize(gpx_file)) |
344 | + file = open(gpx_file, "r") |
345 | + data = file.read(os.path.getsize(gpx_file)) |
346 | #print "reading ",gpx_file |
347 | file.close() |
348 | dom = xml.dom.minidom.parseString(data) |
349 | |
350 | # read the XML with and without the namepace |
351 | - handle_gpx(dom,timedict,False) |
352 | + handle_gpx(dom, timedict, False) |
353 | ns = 'http://www.topografix.com/GPX/1/1' |
354 | - handle_gpx(dom,timedict,ns) |
355 | + handle_gpx(dom, timedict, ns) |
356 | |
357 | return timedict |
358 | |
359 | @@ -168,7 +183,7 @@ |
360 | |
361 | # returns the metadata dictionary for given exif date |
362 | # eg 'Exif_Image_DateTime' |
363 | -def get_metadata(dateString,timedict,timeshift,path,report=None): |
364 | +def get_metadata(dateString, timedict, timeshift, path, report=None): |
365 | """get_metadata(float) - get a dictionary of changes to the metadata |
366 | dateString - EXIF date format string /* in */ |
367 | timeshift - delta between GMT and local time (seconds. |
368 | @@ -178,54 +193,53 @@ |
369 | """ |
370 | if not pyexiv2: |
371 | raise ImportError('pyexiv2 is not installed') |
372 | - stamp = str(get_xml_timez(dateString,timeshift)) |
373 | - |
374 | - timestamp = search(timedict,stamp) |
375 | - data = timedict[timestamp] |
376 | - ele = float(data[0]) |
377 | - lat = float(data[1]) |
378 | - lon = float(data[2]) |
379 | - |
380 | - latR = 'N' |
381 | - lonR = 'E' |
382 | - eleR = 0 |
383 | - if lat < 0: |
384 | + stamp = str(get_xml_timez(dateString, timeshift)) |
385 | + |
386 | + timestamp = search(timedict, stamp) |
387 | + data = timedict[timestamp] |
388 | + ele = float(data[0]) |
389 | + lat = float(data[1]) |
390 | + lon = float(data[2]) |
391 | + |
392 | + latR = 'N' |
393 | + lonR = 'E' |
394 | + eleR = 0 |
395 | + if lat < 0: |
396 | lat = -lat |
397 | - latR= 'S' |
398 | - if lon < 0: |
399 | + latR = 'S' |
400 | + if lon < 0: |
401 | lon = -lon |
402 | - lonR= 'W' |
403 | + lonR = 'W' |
404 | sele = "%6.1f" % (ele) |
405 | - if ele < 0: |
406 | + if ele < 0: |
407 | ele = -ele |
408 | - eleR= 1 |
409 | + eleR = 1 |
410 | |
411 | - slat = "%02d.%02d'" '%02d"%s' % (d(lat),m(lat),s(lat),latR ) |
412 | - slon = "%02d.%02d'" '%02d"%s' % (d(lon),m(lon),s(lon),lonR ) |
413 | + slat = "%02d.%02d'" '%02d"%s' % (d(lat), m(lat), s(lat), latR) |
414 | + slon = "%02d.%02d'" '%02d"%s' % (d(lon), m(lon), s(lon), lonR) |
415 | if report: |
416 | - report.write(",".join([stamp,timestamp,slat,slon,sele,path])\ |
417 | - +"\n") |
418 | + report.write(",".join([stamp, timestamp, slat, slon, sele, path])\ |
419 | + + "\n") |
420 | # get Rational number for ele |
421 | # don't know why r(ele) is causing trouble! |
422 | # it might be that the denominator is overflowing 32 bits! |
423 | # and this would also import lat and lon |
424 | - rele = pyexiv2.Rational(int(ele*10.0),10) |
425 | + rele = pyexiv2.Rational(int(ele * 10.0), 10) |
426 | # create and return the dictionary of tags to be added to the image |
427 | metadata = {} |
428 | - metadata['Exif_GPSInfo_GPSAltitude' ] = rele |
429 | - metadata['Exif_GPSInfo_GPSAltitudeRef' ] = eleR |
430 | - metadata['Exif_GPSInfo_GPSDateStamp' ] = stamp |
431 | - metadata['Exif_GPSInfo_GPSLatitude' ] = \ |
432 | - [r(d(lat)),r(m(lat)),r(s(lat))] |
433 | - metadata['Exif_GPSInfo_GPSLatitudeRef' ] = latR |
434 | - metadata['Exif_GPSInfo_GPSLongitude' ] = \ |
435 | - [r(d(lon)),r(m(lon)),r(s(lon))] |
436 | - metadata['Exif_GPSInfo_GPSLongitudeRef' ] = lonR |
437 | - metadata['Exif_GPSInfo_GPSMapDatum' ] = 'WGS-84' |
438 | - metadata['Exif_GPSInfo_GPSProcessingMethod' ] = \ |
439 | + metadata['Exif_GPSInfo_GPSAltitude'] = rele |
440 | + metadata['Exif_GPSInfo_GPSAltitudeRef'] = eleR |
441 | + metadata['Exif_GPSInfo_GPSDateStamp'] = stamp |
442 | + metadata['Exif_GPSInfo_GPSLatitude'] = \ |
443 | + [r(d(lat)), r(m(lat)), r(s(lat))] |
444 | + metadata['Exif_GPSInfo_GPSLatitudeRef'] = latR |
445 | + metadata['Exif_GPSInfo_GPSLongitude'] = \ |
446 | + [r(d(lon)), r(m(lon)), r(s(lon))] |
447 | + metadata['Exif_GPSInfo_GPSLongitudeRef'] = lonR |
448 | + metadata['Exif_GPSInfo_GPSMapDatum'] = 'WGS-84' |
449 | + metadata['Exif_GPSInfo_GPSProcessingMethod'] = \ |
450 | '65 83 67 73 73 0 0 0 72 89 66 82 73 68 45 70 73 88 ' |
451 | - metadata['Exif_GPSInfo_GPSTimeStamp' ] = \ |
452 | - [r(10),r(20),r(30)] |
453 | - metadata['Exif_GPSInfo.GPSVersionID' ] = '2 2 0 0' |
454 | + metadata['Exif_GPSInfo_GPSTimeStamp'] = \ |
455 | + [r(10), r(20), r(30)] |
456 | + metadata['Exif_GPSInfo.GPSVersionID'] = '2 2 0 0' |
457 | return metadata |
458 | - |
Looks good to me, I'll merge so others are not doing the same files.