Skip to content

Commit e5e4e9f

Browse files
committed
PPE8 all the things
PEP8 makefile target didn't get the Python files in submodules. Fix it, then fix the PEP8 problems. Signed-off-by: David Gibson <[email protected]>
1 parent 51be972 commit e5e4e9f

File tree

6 files changed

+60
-46
lines changed

6 files changed

+60
-46
lines changed

Makefile

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@ NOSEFLAGS = --with-coverage --cover-package=smadata2
66

77
SCRIPTS = sma2-explore sma2mon \
88
sma2-upload-to-pvoutputorg sma2-push-daily-to-pvoutput
9-
PYFILES = $(SCRIPTS) $(wildcard smadata2/*.py)
9+
10+
SMADATA2_PYFILES = check.py config.py datetimeutil.py download.py \
11+
__init__.py pvoutputorg.py pvoutputuploader.py sma2mon.py \
12+
upload.py \
13+
test_config.py test_datetimeutil.py test_upload.py
14+
15+
DB_PYFILES = base.py __init__.py mock.py sqlite.py tests.py
16+
INVERTER_PYFILES = base.py __init__.py mock.py smabluetooth.py
17+
18+
PYFILES = $(SCRIPTS) $(SMADATA2_PYFILES:%=smadata2/%) \
19+
$(DB_PYFILES:%=smadata2/db/%) \
20+
$(INVERTER_PYFILES:%=smadata2/inverter/%)
1021

1122
all: check
1223

smadata2/db/mock.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from base import BaseDatabase
2323

24+
2425
class MockDatabase(BaseDatabase):
2526
def __init__(self):
2627
super(MockDatabase, self).__init__()

smadata2/db/sqlite.py

+36-31
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
_whitespace = re.compile('\s+')
3333

34+
3435
def squash_schema(sqls):
3536
l = []
3637
for sql in sqls:
@@ -47,12 +48,13 @@ def sqlite_schema(conn):
4748

4849
class SQLiteDatabase(BaseDatabase):
4950
DDL = [
50-
"""CREATE TABLE generation (inverter_serial INTEGER,
51-
timestamp INTEGER,
52-
total_yield INTEGER,
53-
PRIMARY KEY (inverter_serial, timestamp))""",
54-
"""CREATE TABLE pvoutput (sid STRING,
55-
last_datetime_uploaded INTEGER)""",
51+
"""CREATE TABLE generation (inverter_serial INTEGER,
52+
timestamp INTEGER,
53+
total_yield INTEGER,
54+
PRIMARY KEY (inverter_serial,
55+
timestamp))""",
56+
"""CREATE TABLE pvoutput (sid STRING,
57+
last_datetime_uploaded INTEGER)""",
5658
]
5759

5860
def __init__(self, filename):
@@ -69,9 +71,9 @@ def commit(self):
6971

7072
def add_historic(self, serial, timestamp, total_yield):
7173
c = self.conn.cursor()
72-
c.execute("INSERT INTO generation"
73-
+ " (inverter_serial, timestamp, total_yield)"
74-
+ " VALUES (?, ?, ?);",
74+
c.execute("INSERT INTO generation" +
75+
" (inverter_serial, timestamp, total_yield)" +
76+
" VALUES (?, ?, ?);",
7577
(serial, timestamp, total_yield))
7678

7779
def get_one_historic(self, serial, timestamp):
@@ -104,11 +106,12 @@ def get_aggregate_one_historic(self, ts, ids):
104106

105107
def get_aggregate_historic(self, from_ts, to_ts, ids):
106108
c = self.conn.cursor()
107-
c.execute("SELECT timestamp, sum(total_yield) FROM generation"
108-
" WHERE inverter_serial IN (" + ",".join("?" * len(ids)) + ")"
109-
+ " AND timestamp >= ? AND timestamp < ?"
110-
+ " GROUP BY timestamp ORDER BY timestamp ASC",
111-
tuple(ids) + (from_ts, to_ts))
109+
template = ("SELECT timestamp, sum(total_yield) FROM generation" +
110+
" WHERE inverter_serial IN (" +
111+
",".join("?" * len(ids)) +
112+
") AND timestamp >= ? AND timestamp < ?" +
113+
" GROUP BY timestamp ORDER BY timestamp ASC")
114+
c.execute(template, tuple(ids) + (from_ts, to_ts))
112115
return c.fetchall()
113116

114117
# return midnights for each day in the database
@@ -117,11 +120,12 @@ def get_aggregate_historic(self, from_ts, to_ts, ids):
117120
def midnights(self, inverters):
118121
c = self.conn.cursor()
119122
serials = ','.join(x.serial for x in inverters)
120-
c.execute("SELECT distinct(timestamp) "
121-
"FROM generation "
122-
"WHERE inverter_serial in ( ? ) "
123-
"AND timestamp % 86400 = 0 "
124-
"ORDER BY timestamp ASC", (serials,))
123+
template = """SELECT distinct(timestamp)
124+
FROM generation
125+
WHERE inverter_serial in ( ? )
126+
AND timestamp % 86400 = 0
127+
ORDER BY timestamp ASC"""
128+
c.execute(template, (serials,))
125129
r = c.fetchall()
126130
r = map(lambda x: datetime.datetime.utcfromtimestamp(x[0]), r)
127131
return r
@@ -221,11 +225,11 @@ def create_from_empty(conn):
221225

222226

223227
SCHEMA_NOPVO = squash_schema((
224-
"""CREATE TABLE generation (inverter_serial INTEGER,
225-
timestamp INTEGER,
226-
total_yield INTEGER,
227-
PRIMARY KEY (inverter_serial, timestamp))""",
228-
"""CREATE TABLE schema (magic INTEGER, version INTEGER)"""))
228+
"""CREATE TABLE generation (inverter_serial INTEGER,
229+
timestamp INTEGER,
230+
total_yield INTEGER,
231+
PRIMARY KEY (inverter_serial, timestamp))""",
232+
"""CREATE TABLE schema (magic INTEGER, version INTEGER)"""))
229233

230234

231235
def update_nopvo(conn):
@@ -236,13 +240,13 @@ def update_nopvo(conn):
236240

237241

238242
SCHEMA_V0 = squash_schema((
239-
"""CREATE TABLE generation (inverter_serial INTEGER,
240-
timestamp INTEGER,
241-
total_yield INTEGER,
242-
PRIMARY KEY (inverter_serial, timestamp))""",
243-
"""CREATE TABLE schema (magic INTEGER, version INTEGER)""",
244-
"""CREATE TABLE pvoutput (sid STRING,
245-
last_datetime_uploaded INTEGER)"""))
243+
"""CREATE TABLE generation (inverter_serial INTEGER,
244+
timestamp INTEGER,
245+
total_yield INTEGER,
246+
PRIMARY KEY (inverter_serial, timestamp))""",
247+
"""CREATE TABLE schema (magic INTEGER, version INTEGER)""",
248+
"""CREATE TABLE pvoutput (sid STRING,
249+
last_datetime_uploaded INTEGER)"""))
246250

247251

248252
def update_v0(conn):
@@ -258,6 +262,7 @@ def update_v0(conn):
258262
SCHEMA_NOPVO: update_nopvo,
259263
}
260264

265+
261266
def try_open(filename):
262267
try:
263268
db = SQLiteDatabase(filename)

smadata2/db/tests.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import smadata2.db.mock
1515
from smadata2 import check
1616

17+
1718
def removef(filename):
1819
try:
1920
os.remove(filename)
@@ -229,7 +230,6 @@ def prepopulate(self):
229230
(DB_MAGIC, DB_VERSION))
230231
conn.commit()
231232

232-
233233
conn.execute("""INSERT INTO generation (inverter_serial, timestamp,
234234
total_yield)
235235
VALUES (?, ?, ?)""", self.PRESERVE_RECORD)
@@ -256,7 +256,6 @@ def prepopulate(self):
256256
(DB_MAGIC, DB_VERSION))
257257
conn.commit()
258258

259-
260259
conn.execute("""INSERT INTO generation (inverter_serial, timestamp,
261260
total_yield)
262261
VALUES (?, ?, ?)""", self.PRESERVE_RECORD)

smadata2/inverter/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@
2020
from __future__ import print_function
2121

2222
from base import *
23-

smadata2/inverter/smabluetooth.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ def rx_raw(self, pkt):
202202
self.rx_outer(from_, to_, type_, payload)
203203

204204
def rxfilter_outer(self, to_):
205-
return ((to_ == self.local_addr)
206-
or (to_ == self.BROADCAST)
207-
or (to_ == "00:00:00:00:00:00"))
205+
return ((to_ == self.local_addr) or
206+
(to_ == self.BROADCAST) or
207+
(to_ == "00:00:00:00:00:00"))
208208

209209
@waiter
210210
def rx_outer(self, from_, to_, type_, payload):
@@ -284,8 +284,8 @@ def rx_ppp(self, from_, protocol, payload):
284284
response, error, pktcount, first)
285285

286286
def rxfilter_6560(self, to2):
287-
return ((to2 == self.local_addr2)
288-
or (to2 == self.BROADCAST2))
287+
return ((to2 == self.local_addr2) or
288+
(to2 == self.BROADCAST2))
289289

290290
@waiter
291291
def rx_6560(self, from2, to2, a2, b1, b2, c1, c2, tag,
@@ -338,8 +338,8 @@ def tx_6560(self, from2, to2, a2, b1, b2, c1, c2, tag,
338338
type_, subtype, arg1, arg2, extra=bytearray(),
339339
response=False, error=0, pktcount=0, first=True):
340340
if len(extra) % 4 != 0:
341-
raise Error("Inner protocol payloads must"
342-
+ "have multiple of 4 bytes length")
341+
raise Error("Inner protocol payloads must" +
342+
" have multiple of 4 bytes length")
343343
innerlen = (len(extra) + INNER_HLEN) // 4
344344
payload = bytearray()
345345
payload.append(innerlen)
@@ -429,8 +429,7 @@ def wait(self, class_, cond=None):
429429

430430
def wait_outer(self, wtype, wpl=bytearray()):
431431
def wfn(from_, to_, type_, payload):
432-
if ((type_ == wtype)
433-
and payload.startswith(wpl)):
432+
if ((type_ == wtype) and payload.startswith(wpl)):
434433
return payload
435434
return self.wait('outer', wfn)
436435

@@ -479,8 +478,8 @@ def multiwait_6560(from2, to2, a2, b1, b2, c1, c2, tag,
479478

480479
def hello(self):
481480
hellopkt = self.wait_outer(OTYPE_HELLO)
482-
if hellopkt != bytearray('\x00\x04\x70\x00\x01\x00\x00\x00'
483-
+ '\x00\x01\x00\x00\x00'):
481+
if hellopkt != bytearray('\x00\x04\x70\x00\x01\x00\x00\x00' +
482+
'\x00\x01\x00\x00\x00'):
484483
raise Error("Unexpected HELLO %r" % hellopkt)
485484
self.tx_outer("00:00:00:00:00:00", self.remote_addr,
486485
OTYPE_HELLO, hellopkt)

0 commit comments

Comments
 (0)