Skip to content

Commit 92049a0

Browse files
committed
Code quality
1 parent 9bdae27 commit 92049a0

14 files changed

Lines changed: 79 additions & 75 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: 43 additions & 31 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,12 @@ 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
12261234
def loadSent(self, tableWidget, account, where="", what=""):
1235+
"""Load Sent items from database"""
12271236
if tableWidget == self.ui.tableWidgetInboxSubscriptions:
12281237
tableWidget.setColumnHidden(0, True)
12291238
tableWidget.setColumnHidden(1, False)
@@ -1241,7 +1250,7 @@ def loadSent(self, tableWidget, account, where="", what=""):
12411250
xAddress, account, "sent", where, what, False)
12421251

12431252
for row in queryreturn:
1244-
self.addMessageListItemSent(tableWidget, *row)
1253+
MyForm.addMessageListItemSent(tableWidget, *row)
12451254

12461255
tableWidget.horizontalHeader().setSortIndicator(
12471256
3, QtCore.Qt.DescendingOrder)
@@ -1250,11 +1259,11 @@ def loadSent(self, tableWidget, account, where="", what=""):
12501259
_translate("MainWindow", "Sent"))
12511260
tableWidget.setUpdatesEnabled(True)
12521261

1253-
# Load messages from database file
12541262
def loadMessagelist(
12551263
self, tableWidget, account, folder="inbox", where="", what="",
12561264
unreadOnly=False
12571265
):
1266+
"""Load messages from database file"""
12581267
tableWidget.setUpdatesEnabled(False)
12591268
tableWidget.setSortingEnabled(False)
12601269
tableWidget.setRowCount(0)
@@ -1282,7 +1291,7 @@ def loadMessagelist(
12821291

12831292
for row in queryreturn:
12841293
toAddress, fromAddress, subject, _, msgid, received, read = row
1285-
self.addMessageListItemInbox(
1294+
MyForm.addMessageListItemInbox(
12861295
tableWidget, toAddress, fromAddress, subject,
12871296
msgid, received, read)
12881297

@@ -1359,8 +1368,9 @@ def appIndicatorInit(self, _app):
13591368
self.tray.setContextMenu(m)
13601369
self.tray.show()
13611370

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

13661376
queryreturn = sqlQuery('''
@@ -1443,8 +1453,9 @@ def _choose_ext(basename):
14431453

14441454
self._player(soundFilename)
14451455

1446-
# Adapters and converters for QT <-> sqlite
1447-
def sqlInit(self):
1456+
@staticmethod
1457+
def sqlInit():
1458+
"""Adapters and converters for QT <-> sqlite"""
14481459
register_adapter(QtCore.QByteArray, str)
14491460

14501461
def indicatorInit(self):
@@ -1813,15 +1824,16 @@ def setStatusIcon(self, color):
18131824
def initTrayIcon(self, iconFileName, _app):
18141825
self.currentTrayIconFileName = iconFileName
18151826
self.tray = QtGui.QSystemTrayIcon(
1816-
self.calcTrayIcon(iconFileName,
1817-
self.findInboxUnreadCount()),
1827+
MyForm.calcTrayIcon(iconFileName,
1828+
self.findInboxUnreadCount()),
18181829
_app)
18191830

18201831
def setTrayIconFile(self, iconFileName):
18211832
self.currentTrayIconFileName = iconFileName
18221833
self.drawTrayIcon(iconFileName, self.findInboxUnreadCount())
18231834

1824-
def calcTrayIcon(self, iconFileName, inboxUnreadCount):
1835+
@staticmethod
1836+
def calcTrayIcon(iconFileName, inboxUnreadCount):
18251837
pixmap = QtGui.QPixmap(":/newPrefix/images/" + iconFileName)
18261838
if inboxUnreadCount > 0:
18271839
# choose font and calculate font parameters
@@ -1854,7 +1866,8 @@ def calcTrayIcon(self, iconFileName, inboxUnreadCount):
18541866
return QtGui.QIcon(pixmap)
18551867

18561868
def drawTrayIcon(self, iconFileName, inboxUnreadCount):
1857-
self.tray.setIcon(self.calcTrayIcon(iconFileName, inboxUnreadCount))
1869+
self.tray.setIcon(MyForm.calcTrayIcon(iconFileName,
1870+
inboxUnreadCount))
18581871

18591872
def changedInboxUnread(self, row=None):
18601873
self.drawTrayIcon(
@@ -3978,12 +3991,12 @@ def on_context_menuInbox(self, point):
39783991
popMenuInbox.addAction(self.actionReply)
39793992
popMenuInbox.addAction(self.actionAddSenderToAddressBook)
39803993
# pylint: disable=no-member
3981-
self.actionClipboardMessagelist = self.ui.inboxContextMenuToolbar.addAction(
3994+
actionClipboardMessagelist = self.ui.inboxContextMenuToolbar.addAction(
39823995
_translate("MainWindow", "Copy subject to clipboard")
39833996
if tableWidget.currentColumn() == 2 else
39843997
_translate("MainWindow", "Copy address to clipboard"),
39853998
self.on_action_ClipboardMessagelist)
3986-
popMenuInbox.addAction(self.actionClipboardMessagelist)
3999+
popMenuInbox.addAction(actionClipboardMessagelist)
39874000
# pylint: disable=no-member
39884001
self._contact_selected = tableWidget.item(currentRow, 1)
39894002
# preloaded gui.menu plugins with prefix 'address'
@@ -4229,7 +4242,7 @@ class BitmessageQtApplication(QtGui.QApplication):
42294242
"""
42304243

42314244
# Unique identifier for this application
4232-
uuid = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c'
4245+
UUID = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c'
42334246

42344247
@staticmethod
42354248
def get_windowstyle():
@@ -4241,7 +4254,6 @@ def get_windowstyle():
42414254

42424255
def __init__(self, *argv):
42434256
super(BitmessageQtApplication, self).__init__(*argv)
4244-
id = BitmessageQtApplication.uuid
42454257

42464258
QtCore.QCoreApplication.setOrganizationName("PyBitmessage")
42474259
QtCore.QCoreApplication.setOrganizationDomain("bitmessage.org")
@@ -4259,14 +4271,14 @@ def __init__(self, *argv):
42594271
self.is_running = False
42604272

42614273
socket = QLocalSocket()
4262-
socket.connectToServer(id)
4274+
socket.connectToServer(self.UUID)
42634275
self.is_running = socket.waitForConnected()
42644276

42654277
# Cleanup past crashed servers
42664278
if not self.is_running:
42674279
if socket.error() == QLocalSocket.ConnectionRefusedError:
42684280
socket.disconnectFromServer()
4269-
QLocalServer.removeServer(id)
4281+
QLocalServer.removeServer(self.UUID)
42704282

42714283
socket.abort()
42724284

@@ -4278,7 +4290,7 @@ def __init__(self, *argv):
42784290
# Nope, create a local server with this id and assign on_new_connection
42794291
# for whenever a second instance tries to run focus the application.
42804292
self.server = QLocalServer()
4281-
self.server.listen(id)
4293+
self.server.listen(self.UUID)
42824294
self.server.newConnection.connect(self.on_new_connection)
42834295

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

42944306

42954307
def init():
4296-
global app
4308+
global app # pylint: disable=global-statement
42974309
if not app:
42984310
app = BitmessageQtApplication(sys.argv)
42994311
return app
43004312

43014313

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

43074319
myapp.appIndicatorInit(app)
43084320

4309-
if myapp._firstrun:
4321+
if myapp._firstrun: # pylint: disable=protected-access
43104322
myapp.showConnectDialog() # ask the user if we may connect
43114323

43124324
# only show after wizards and connect dialogs have completed
@@ -4315,4 +4327,4 @@ def run():
43154327
QtCore.QTimer.singleShot(
43164328
30000, lambda: myapp.setStatusIcon(state.statusIconColor))
43174329

4318-
app.exec_()
4330+
_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)