Skip to content

Commit 95619c8

Browse files
committed
Code quality
1 parent 9bdae27 commit 95619c8

12 files changed

Lines changed: 77 additions & 72 deletions

setup.cfg

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ ignore = bitmessagekivy
2424
[pylint.messages_control]
2525
disable =
2626
invalid-name,bare-except,broad-except,relative-import,
27-
superfluous-parens,bad-option-value,fixme
27+
superfluous-parens,bad-option-value,fixme,missing-docstring,
28+
too-many-locals,too-few-public-methods,too-many-statements,
29+
too-many-instance-attributes,too-many-public-methods
2830
# invalid-name: needs fixing during a large, project-wide refactor
2931
# bare-except,broad-except: Need fixing once thorough testing is easier
3032
# bad-option-value is for backward compatibility between python 2 and 3
@@ -42,7 +44,9 @@ ignore = bitmessagekivy
4244
[MESSAGES CONTROL]
4345
disable =
4446
invalid-name,bare-except,broad-except,relative-import,
45-
superfluous-parens,bad-option-value,fixme
47+
superfluous-parens,bad-option-value,fixme,missing-docstring,
48+
too-many-locals,too-few-public-methods,too-many-statements,
49+
too-many-instance-attributes,too-many-public-methods
4650

4751
[DESIGN]
4852
max-args = 8

src/bitmessagecli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ def apiInit(apiEnabled):
188188
def apiData():
189189
"""TBC"""
190190

191-
global keysName
192191
global keysPath
193192
global usrPrompt
194193

src/bitmessageqt/__init__.py

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
PyQt based UI for bitmessage, the main module
33
"""
44
# pylint: disable=import-error,too-many-lines,no-member
5+
# pylint: disable=too-many-branches
56
import hashlib
67
import locale
78
import os
@@ -760,6 +761,11 @@ def __init__(self, parent=None):
760761

761762
self.unreadCount = 0
762763

764+
self.currentTrayIconFileName = ""
765+
self.actionQuiet = None
766+
self.actionShow = None
767+
self.tray = None
768+
763769
# Set the icon sizes for the identicons
764770
identicon_size = 3 * 7
765771
self.ui.tableWidgetInbox.setIconSize(QtCore.QSize(identicon_size, identicon_size))
@@ -843,7 +849,7 @@ def __init__(self, parent=None):
843849

844850
self.initSettings()
845851
self.resetNamecoinConnection()
846-
self.sqlInit()
852+
MyForm.sqlInit()
847853
self.indicatorInit()
848854
self.notifierInit()
849855
self.updateStartOnLogon()
@@ -1107,7 +1113,8 @@ def propagateUnreadCount(self, folder=None, widget=None):
11071113
if newCount != folderItem.unreadCount:
11081114
folderItem.setUnreadCount(newCount)
11091115

1110-
def addMessageListItem(self, tableWidget, items):
1116+
@staticmethod
1117+
def addMessageListItem(tableWidget, items):
11111118
sortingEnabled = tableWidget.isSortingEnabled()
11121119
if sortingEnabled:
11131120
tableWidget.setSortingEnabled(False)
@@ -1117,8 +1124,9 @@ def addMessageListItem(self, tableWidget, items):
11171124
if sortingEnabled:
11181125
tableWidget.setSortingEnabled(True)
11191126

1127+
@staticmethod
11201128
def addMessageListItemSent(
1121-
self, tableWidget, toAddress, fromAddress, subject,
1129+
tableWidget, toAddress, fromAddress, subject,
11221130
status, ackdata, lastactiontime
11231131
):
11241132
acct = accountClass(fromAddress) or BMAccount(fromAddress)
@@ -1191,12 +1199,13 @@ def addMessageListItemSent(
11911199
str(subject), text_type(acct.subject, 'utf-8', 'replace')),
11921200
MessageList_TimeWidget(
11931201
statusText, False, lastactiontime, ackdata)]
1194-
self.addMessageListItem(tableWidget, items)
1202+
MyForm.addMessageListItem(tableWidget, items)
11951203

11961204
return acct
11971205

1206+
@staticmethod
11981207
def addMessageListItemInbox(
1199-
self, tableWidget, toAddress, fromAddress, subject,
1208+
tableWidget, toAddress, fromAddress, subject,
12001209
msgid, received, read
12011210
):
12021211
if toAddress == str_broadcast_subscribers:
@@ -1218,12 +1227,13 @@ def addMessageListItemInbox(
12181227
MessageList_TimeWidget(
12191228
l10n.formatTimestamp(received), not read, received, msgid)
12201229
]
1221-
self.addMessageListItem(tableWidget, items)
1230+
MyForm.addMessageListItem(tableWidget, items)
12221231

12231232
return acct
12241233

1225-
# Load Sent items from database
1226-
def loadSent(self, tableWidget, account, where="", what=""):
1234+
@staticmethod
1235+
def loadSent(tableWidget, account, where="", what=""):
1236+
"""Load Sent items from database"""
12271237
if tableWidget == self.ui.tableWidgetInboxSubscriptions:
12281238
tableWidget.setColumnHidden(0, True)
12291239
tableWidget.setColumnHidden(1, False)
@@ -1241,7 +1251,7 @@ def loadSent(self, tableWidget, account, where="", what=""):
12411251
xAddress, account, "sent", where, what, False)
12421252

12431253
for row in queryreturn:
1244-
self.addMessageListItemSent(tableWidget, *row)
1254+
MyForm.addMessageListItemSent(tableWidget, *row)
12451255

12461256
tableWidget.horizontalHeader().setSortIndicator(
12471257
3, QtCore.Qt.DescendingOrder)
@@ -1250,17 +1260,17 @@ def loadSent(self, tableWidget, account, where="", what=""):
12501260
_translate("MainWindow", "Sent"))
12511261
tableWidget.setUpdatesEnabled(True)
12521262

1253-
# Load messages from database file
12541263
def loadMessagelist(
12551264
self, tableWidget, account, folder="inbox", where="", what="",
12561265
unreadOnly=False
12571266
):
1267+
"""Load messages from database file"""
12581268
tableWidget.setUpdatesEnabled(False)
12591269
tableWidget.setSortingEnabled(False)
12601270
tableWidget.setRowCount(0)
12611271

12621272
if folder == 'sent':
1263-
self.loadSent(tableWidget, account, where, what)
1273+
MyForm.loadSent(tableWidget, account, where, what)
12641274
return
12651275

12661276
if tableWidget == self.ui.tableWidgetInboxSubscriptions:
@@ -1282,7 +1292,7 @@ def loadMessagelist(
12821292

12831293
for row in queryreturn:
12841294
toAddress, fromAddress, subject, _, msgid, received, read = row
1285-
self.addMessageListItemInbox(
1295+
MyForm.addMessageListItemInbox(
12861296
tableWidget, toAddress, fromAddress, subject,
12871297
msgid, received, read)
12881298

@@ -1359,8 +1369,9 @@ def appIndicatorInit(self, _app):
13591369
self.tray.setContextMenu(m)
13601370
self.tray.show()
13611371

1362-
# returns the number of unread messages and subscriptions
1363-
def getUnread(self):
1372+
@staticmethod
1373+
def getUnread():
1374+
"""returns the number of unread messages and subscriptions"""
13641375
counters = [0, 0]
13651376

13661377
queryreturn = sqlQuery('''
@@ -1443,8 +1454,9 @@ def _choose_ext(basename):
14431454

14441455
self._player(soundFilename)
14451456

1446-
# Adapters and converters for QT <-> sqlite
1457+
@staticmethod
14471458
def sqlInit(self):
1459+
"""Adapters and converters for QT <-> sqlite"""
14481460
register_adapter(QtCore.QByteArray, str)
14491461

14501462
def indicatorInit(self):
@@ -1813,15 +1825,16 @@ def setStatusIcon(self, color):
18131825
def initTrayIcon(self, iconFileName, _app):
18141826
self.currentTrayIconFileName = iconFileName
18151827
self.tray = QtGui.QSystemTrayIcon(
1816-
self.calcTrayIcon(iconFileName,
1817-
self.findInboxUnreadCount()),
1828+
MyForm.calcTrayIcon(iconFileName,
1829+
self.findInboxUnreadCount()),
18181830
_app)
18191831

18201832
def setTrayIconFile(self, iconFileName):
18211833
self.currentTrayIconFileName = iconFileName
18221834
self.drawTrayIcon(iconFileName, self.findInboxUnreadCount())
18231835

1824-
def calcTrayIcon(self, iconFileName, inboxUnreadCount):
1836+
@staticmethod
1837+
def calcTrayIcon(iconFileName, inboxUnreadCount):
18251838
pixmap = QtGui.QPixmap(":/newPrefix/images/" + iconFileName)
18261839
if inboxUnreadCount > 0:
18271840
# choose font and calculate font parameters
@@ -1854,7 +1867,8 @@ def calcTrayIcon(self, iconFileName, inboxUnreadCount):
18541867
return QtGui.QIcon(pixmap)
18551868

18561869
def drawTrayIcon(self, iconFileName, inboxUnreadCount):
1857-
self.tray.setIcon(self.calcTrayIcon(iconFileName, inboxUnreadCount))
1870+
self.tray.setIcon(MyForm.calcTrayIcon(iconFileName,
1871+
inboxUnreadCount))
18581872

18591873
def changedInboxUnread(self, row=None):
18601874
self.drawTrayIcon(
@@ -3978,12 +3992,12 @@ def on_context_menuInbox(self, point):
39783992
popMenuInbox.addAction(self.actionReply)
39793993
popMenuInbox.addAction(self.actionAddSenderToAddressBook)
39803994
# pylint: disable=no-member
3981-
self.actionClipboardMessagelist = self.ui.inboxContextMenuToolbar.addAction(
3995+
actionClipboardMessagelist = self.ui.inboxContextMenuToolbar.addAction(
39823996
_translate("MainWindow", "Copy subject to clipboard")
39833997
if tableWidget.currentColumn() == 2 else
39843998
_translate("MainWindow", "Copy address to clipboard"),
39853999
self.on_action_ClipboardMessagelist)
3986-
popMenuInbox.addAction(self.actionClipboardMessagelist)
4000+
popMenuInbox.addAction(actionClipboardMessagelist)
39874001
# pylint: disable=no-member
39884002
self._contact_selected = tableWidget.item(currentRow, 1)
39894003
# preloaded gui.menu plugins with prefix 'address'
@@ -4229,7 +4243,7 @@ class BitmessageQtApplication(QtGui.QApplication):
42294243
"""
42304244

42314245
# Unique identifier for this application
4232-
uuid = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c'
4246+
UUID = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c'
42334247

42344248
@staticmethod
42354249
def get_windowstyle():
@@ -4241,7 +4255,6 @@ def get_windowstyle():
42414255

42424256
def __init__(self, *argv):
42434257
super(BitmessageQtApplication, self).__init__(*argv)
4244-
id = BitmessageQtApplication.uuid
42454258

42464259
QtCore.QCoreApplication.setOrganizationName("PyBitmessage")
42474260
QtCore.QCoreApplication.setOrganizationDomain("bitmessage.org")
@@ -4259,14 +4272,14 @@ def __init__(self, *argv):
42594272
self.is_running = False
42604273

42614274
socket = QLocalSocket()
4262-
socket.connectToServer(id)
4275+
socket.connectToServer(self.UUID)
42634276
self.is_running = socket.waitForConnected()
42644277

42654278
# Cleanup past crashed servers
42664279
if not self.is_running:
42674280
if socket.error() == QLocalSocket.ConnectionRefusedError:
42684281
socket.disconnectFromServer()
4269-
QLocalServer.removeServer(id)
4282+
QLocalServer.removeServer(self.UUID)
42704283

42714284
socket.abort()
42724285

@@ -4278,7 +4291,7 @@ def __init__(self, *argv):
42784291
# Nope, create a local server with this id and assign on_new_connection
42794292
# for whenever a second instance tries to run focus the application.
42804293
self.server = QLocalServer()
4281-
self.server.listen(id)
4294+
self.server.listen(self.UUID)
42824295
self.server.newConnection.connect(self.on_new_connection)
42834296

42844297
self.setStyleSheet("QStatusBar::item { border: 0px solid black }")
@@ -4293,20 +4306,20 @@ def on_new_connection(self):
42934306

42944307

42954308
def init():
4296-
global app
4309+
global app # pylint: disable=global-statement
42974310
if not app:
42984311
app = BitmessageQtApplication(sys.argv)
42994312
return app
43004313

43014314

43024315
def run():
4303-
global myapp
4304-
app = init()
4305-
myapp = MyForm()
4316+
global myapp # pylint: disable=global-statement
4317+
_app = init()
4318+
myapp = MyForm() # pylint: disable=redefined-outer-name
43064319

43074320
myapp.appIndicatorInit(app)
43084321

4309-
if myapp._firstrun:
4322+
if myapp._firstrun: # pylint: disable=protected-access
43104323
myapp.showConnectDialog() # ask the user if we may connect
43114324

43124325
# only show after wizards and connect dialogs have completed
@@ -4315,4 +4328,4 @@ def run():
43154328
QtCore.QTimer.singleShot(
43164329
30000, lambda: myapp.setStatusIcon(state.statusIconColor))
43174330

4318-
app.exec_()
4331+
_app.exec_()

src/bitmessageqt/account.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def accountClass(address):
6868
if subscription.type != AccountMixin.BROADCAST:
6969
return None
7070
else:
71+
# pylint: disable=redefined-variable-type
7172
subscription = SubscriptionAccount(address)
7273
if subscription.type != AccountMixin.SUBSCRIPTION:
7374
# e.g. deleted chan

src/bitmessageqt/bitmessage_icons_rc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#
88
# WARNING! All changes made in this file will be lost!
99

10+
# pylint: disable=too-many-lines
1011
from PyQt4 import QtCore # pylint: disable=import-error
1112

1213
qt_resource_data = "\

src/bitmessageqt/foldertree.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ def setLabel(self, label=None):
410410
AccountMixin.NORMAL,
411411
AccountMixin.CHAN, AccountMixin.MAILINGLIST):
412412
try:
413+
# pylint: disable=redefined-variable-type
413414
newLabel = unicode(
414415
config.get(self.address, 'label'),
415416
'utf-8', 'ignore')

src/bitmessageqt/migrationwizard.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __init__(self):
6666

6767

6868
class Ui_MigrationWizard(QtGui.QWizard):
69+
# pylint: disable=redefined-variable-type
6970
def __init__(self, addresses):
7071
super(QtGui.QWizard, self).__init__()
7172

src/bitmessageqt/uisignaler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def get(cls):
1717
cls._instance = UISignaler()
1818
return cls._instance
1919

20+
# pylint: disable=too-many-branches
2021
def run(self):
2122
while True:
2223
command, data = queues.UISignalQueue.get()

src/class_singleWorker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ def requestPubKey(self, toAddress):
13991399
TTL = 2.5 * 24 * 60 * 60
14001400
TTL *= 2 ** retryNumber
14011401
if TTL > 28 * 24 * 60 * 60:
1402-
TTL = 28 * 24 * 60 * 60
1402+
TTL = float(28 * 24 * 60 * 60)
14031403
# add some randomness to the TTL
14041404
TTL = TTL + helper_random.randomrandrange(-300, 300)
14051405
embeddedTime = int(time.time() + TTL)

0 commit comments

Comments
 (0)