Skip to content

Commit 51be972

Browse files
committed
Flake8 cleanups
Many of these look like real bugs Signed-off-by: David Gibson <[email protected]>
1 parent fb084b6 commit 51be972

File tree

12 files changed

+30
-45
lines changed

12 files changed

+30
-45
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
NOSE = nosetests
22
PEP8 = pep8
3+
FLAKE8 = flake8-2
34

45
NOSEFLAGS = --with-coverage --cover-package=smadata2
56

@@ -18,6 +19,9 @@ checkall:
1819
pep8:
1920
$(PEP8) $(PYFILES)
2021

22+
flake8:
23+
$(FLAKE8) $(PYFILES)
24+
2125
clean:
2226
rm -f *~ *.pyc
2327
rm -f smadata2/*~ smadata2/*.pyc

sma2-explore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import signal
2525
import readline
2626
import time
2727

28-
from smadata2.inverter.smabluetooth import *
28+
from smadata2.inverter.smabluetooth import Connection
29+
from smadata2.inverter.smabluetooth import OTYPE_HELLO, OTYPE_ERROR, \
30+
OTYPE_VARVAL, OTYPE_GETVAR, OTYPE_PPP, OTYPE_PPP2, OVAR_SIGNAL
31+
from smadata2.inverter.smabluetooth import bytes2int, int2bytes16
2932

3033

3134
class Quit(Exception):
@@ -250,7 +253,7 @@ class SMAData2CLI(Connection):
250253
self.tx_ppp("ff:ff:ff:ff:ff:ff", protocol, payload)
251254

252255
def cmd_send2(self, *args):
253-
bi = [int(x, 16) for x in args]
256+
bb = [int(x, 16) for x in args]
254257
a2 = bb[0]
255258
b1, b2 = bb[1], bb[2]
256259
c1, c2 = bb[3], bb[4]

sma2-upload-to-pvoutputorg

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ from __future__ import print_function
2121

2222
import argparse
2323
import datetime
24-
from datetime import date
2524
import sys
26-
import time
2725

2826
import smadata2.protocol
2927
import smadata2.config
@@ -119,7 +117,7 @@ class sidType():
119117
self.system = system
120118
break
121119
if self.system is None:
122-
fatal("sid not found")
120+
raise "sid not found"
123121

124122
def __call__(self):
125123
print("__called__ called on datetimeType?!")

smadata2/config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
import sys
2323
import os
24-
import time
25-
import calendar
2624
import dateutil.parser
2725
import dateutil.tz
2826
import json

smadata2/pvoutputuploader.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import time
22
import datetime
33

4-
import upload
5-
import datetimeutil
6-
74

85
class PVOutputUploader(object):
96
def __init__(self, db, system, pvoutput):
@@ -23,7 +20,6 @@ def setVerbose(self, verbose):
2320
# @fixme move this batching into pvoutput
2421
def send_production(self, entries):
2522
batch = []
26-
last_total_production = -1 # unlikely...
2723

2824
too_old_in_days = self.pvoutput.days_ago_accepted_by_api()
2925

@@ -45,8 +41,6 @@ def send_production(self, entries):
4541
dt = datetime.datetime.fromtimestamp(timestamp)
4642
batch.append([dt, total_production])
4743

48-
last_total_production = total_production
49-
5044
if len(batch) == self.pvoutput.batchstatus_count_accepted_by_api():
5145
if havesent:
5246
# if we do *not* wait, other requests can get served
@@ -134,16 +128,17 @@ def upload_unuploaded_statuses(self):
134128
# @param day day to upload for
135129
# @note The day *must be over* for this not to screw you over.
136130
# @note no way to tell if all inverters have reported in....
137-
def upload_statuses_for_day(self, day):
138-
date = day.date()
139-
ts_start, ts_end = datetimeutil.day_timestamps(date,
140-
self.system.timezone())
141-
ids = [i.serial for i in self.system.inverters()]
142-
143-
entries = db.get_aggregate_historic(ts_start, ts_end, ids)
144-
entries = prepare_data_for_date(date, results, sc.timezone())
145-
146-
self.send_production(entries)
131+
# def upload_statuses_for_day(self, day):
132+
# date = day.date()
133+
# ts_start, ts_end = datetimeutil.day_timestamps(date,
134+
# self.system.timezone())
135+
# ids = [i.serial for i in self.system.inverters()]
136+
#
137+
# entries = db.get_aggregate_historic(ts_start, ts_end, ids)
138+
# entries = prepare_data_for_date(date, entries,
139+
# self.system.timezone())
140+
#
141+
# self.send_production(entries)
147142

148143
# print out a message only if we're verbose
149144
def debug(self, message):
@@ -276,7 +271,7 @@ def do_date(self, date, fix):
276271
print(" upload data for a specific date (%s)" % date)
277272
day = self.pvoutput.parse_date_and_time(date, "00:00")
278273
self.upload_statuses_for_day(day)
279-
sleep(20) # so the reconcile works....
274+
time.sleep(20) # so the reconcile works....
280275

281276
if True:
282277
print("reconciling specific date (%s)" % date)

smadata2/sma2mon.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import sys
2323
import argparse
24-
import time
2524
import os.path
2625
import datetime
2726
import dateutil.parser

smadata2/test_config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
import StringIO
44
import os.path
5-
import unittest
65
import time
76
import datetime
87
import dateutil.tz
98

10-
from nose.tools import *
9+
from nose.tools import assert_equals
1110

1211
import smadata2.config
1312

@@ -144,7 +143,6 @@ def test_inv(self):
144143
assert_equals(inv.name, "Test Inverter")
145144
assert_equals(inv.bdaddr, "aa:bb:cc:dd:ee:ff")
146145
assert_equals(inv.serial, "TESTSERIAL")
147-
xtime = time.mktime(datetime.datetime(2000, 1, 1).timetuple())
148146
assert inv.starttime is None
149147
assert isinstance(str(inv), str)
150148

smadata2/test_datetimeutil.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
#! /usr/bin/env python
22

3-
import StringIO
4-
import os.path
5-
import unittest
6-
import time
73
import datetime
84
import dateutil.tz
95

10-
from nose.tools import *
6+
from nose.tools import assert_equals, raises
117

128
import smadata2.datetimeutil
139

@@ -45,7 +41,7 @@ def test_daytimestamps_dstend():
4541
assert_equals(tst, (1396702800, 1396702800 + 25*60*60))
4642

4743

48-
def test_daytimestamps_dstend():
44+
def test_daytimestamps_dstbegin():
4945
d = datetime.date(2014, 10, 5)
5046
tz = dateutil.tz.gettz("Australia/Sydney")
5147
tst = smadata2.datetimeutil.day_timestamps(d, tz)

smadata2/test_pvoutputorg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import time
66
import dateutil
77

8-
from nose.tools import *
8+
from nose.tools import assert_equals
99
from nose.plugins.attrib import attr
1010

1111
import smadata2.config
@@ -125,7 +125,7 @@ def test_addsingle(self):
125125
self.delay()
126126

127127
results = self.api.getstatus(self.date)
128-
assert_equal(results, [(dt0, 0), (dt1, 7)])
128+
assert_equals(results, [(dt0, 0), (dt1, 7)])
129129

130130
def test_addbatch(self):
131131
dt0 = datetime.datetime.combine(self.date, datetime.time(10, 0, 0))

smadata2/test_sma2mon.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import argparse
44

5-
from nose.tools import *
6-
75
import smadata2.sma2mon
86

97

0 commit comments

Comments
 (0)