flake8 for paths and bitmessageqt.dialogs modules

This commit is contained in:
Dmitri Bogomolov 2018-08-15 16:44:22 +03:00
parent b0446ab4ab
commit ba846be6c1
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
2 changed files with 74 additions and 55 deletions

View File

@ -1,15 +1,13 @@
from PyQt4 import QtGui import paths
from tr import _translate
from retranslateui import RetranslateMixin
import widgets import widgets
from newchandialog import NewChanDialog
from address_dialogs import ( from address_dialogs import (
AddAddressDialog, NewAddressDialog, NewSubscriptionDialog, AddAddressDialog, NewAddressDialog, NewSubscriptionDialog,
RegenerateAddressesDialog, SpecialAddressBehaviorDialog, EmailGatewayDialog RegenerateAddressesDialog, SpecialAddressBehaviorDialog, EmailGatewayDialog
) )
from newchandialog import NewChanDialog
import paths from PyQt4 import QtGui
from retranslateui import RetranslateMixin
from tr import _translate
from version import softwareVersion from version import softwareVersion
@ -32,7 +30,7 @@ class AboutDialog(QtGui.QDialog, RetranslateMixin):
self.labelVersion.setText( self.labelVersion.setText(
self.labelVersion.text().replace( self.labelVersion.text().replace(
':version:', version ':version:', version
).replace(':branch:', commit or 'v%s' % version) ).replace(':branch:', commit or 'v%s' % version)
) )
self.labelVersion.setOpenExternalLinks(True) self.labelVersion.setOpenExternalLinks(True)
@ -58,7 +56,7 @@ class IconGlossaryDialog(QtGui.QDialog, RetranslateMixin):
self.labelPortNumber.setText(_translate( self.labelPortNumber.setText(_translate(
"iconGlossaryDialog", "iconGlossaryDialog",
"You are using TCP port %1. (This can be changed in the settings)." "You are using TCP port %1. (This can be changed in the settings)."
).arg(config.getint('bitmessagesettings', 'port'))) ).arg(config.getint('bitmessagesettings', 'port')))
self.setFixedSize(QtGui.QWidget.sizeHint(self)) self.setFixedSize(QtGui.QWidget.sizeHint(self))

View File

@ -1,75 +1,95 @@
from os import environ, path import os
import sys
import re import re
import sys
from datetime import datetime from datetime import datetime
# When using py2exe or py2app, the variable frozen is added to the sys # When using py2exe or py2app, the variable frozen is added to the sys
# namespace. This can be used to setup a different code path for # namespace. This can be used to setup a different code path for
# binary distributions vs source distributions. # binary distributions vs source distributions.
frozen = getattr(sys,'frozen', None) frozen = getattr(sys, 'frozen', None)
def lookupExeFolder(): def lookupExeFolder():
if frozen: if frozen:
if frozen == "macosx_app": if frozen == "macosx_app":
# targetdir/Bitmessage.app/Contents/MacOS/Bitmessage # targetdir/Bitmessage.app/Contents/MacOS/Bitmessage
exeFolder = path.dirname(path.dirname(path.dirname(path.dirname(sys.executable)))) + path.sep exeFolder = os.path.dirname(os.path.dirname(os.path.dirname(
os.path.dirname(sys.executable)
)))
else: else:
exeFolder = path.dirname(sys.executable) + path.sep exeFolder = os.path.dirname(sys.executable)
elif __file__: elif __file__:
exeFolder = path.dirname(__file__) + path.sep exeFolder = os.path.dirname(__file__)
else: else:
exeFolder = '' return ''
return exeFolder return exeFolder + os.path.sep
def lookupAppdataFolder(): def lookupAppdataFolder():
APPNAME = "PyBitmessage" APPNAME = "PyBitmessage"
if "BITMESSAGE_HOME" in environ: try: # for daemon
dataFolder = environ["BITMESSAGE_HOME"] dataFolder = os.environ["BITMESSAGE_HOME"]
if dataFolder[-1] not in [path.sep, path.altsep]: if dataFolder[-1] not in (os.path.sep, os.path.altsep):
dataFolder += path.sep dataFolder += os.path.sep
elif sys.platform == 'darwin': except KeyError:
if "HOME" in environ: pass
dataFolder = path.join(environ["HOME"], "Library/Application Support/", APPNAME) + '/' else:
else: return dataFolder
stringToLog = 'Could not find home folder, please report this message and your OS X version to the BitMessage Github.'
if 'logger' in globals(): if sys.platform == 'darwin':
logger.critical(stringToLog) try:
else: dataFolder = os.path.join(
print stringToLog os.environ["HOME"], "Library/Application Support/", APPNAME)
sys.exit() except KeyError:
log_msg = (
'Could not find home folder, please report this message'
' and your OS X version to the BitMessage Github.'
)
try:
logger.critical(log_msg)
except NameError:
print(log_msg)
sys.exit(1)
elif 'win32' in sys.platform or 'win64' in sys.platform: elif 'win32' in sys.platform or 'win64' in sys.platform:
dataFolder = path.join(environ['APPDATA'].decode(sys.getfilesystemencoding(), 'ignore'), APPNAME) + path.sep dataFolder = os.path.join(os.environ['APPDATA'].decode(
sys.getfilesystemencoding(), 'ignore'), APPNAME)
else: else:
from shutil import move from shutil import move
try: try:
dataFolder = path.join(environ["XDG_CONFIG_HOME"], APPNAME) config_dir = os.environ["XDG_CONFIG_HOME"]
except KeyError: except KeyError:
dataFolder = path.join(environ["HOME"], ".config", APPNAME) config_dir = os.path.join(os.environ["HOME"], ".config")
# Migrate existing data to the proper location if this is an existing install dataFolder = os.path.join(config_dir, APPNAME)
# Migrate existing data to the proper location
# if this is an existing install
try: try:
move(path.join(environ["HOME"], ".%s" % APPNAME), dataFolder) move(
stringToLog = "Moving data folder to %s" % (dataFolder) os.path.join(os.environ["HOME"], ".%s" % APPNAME), dataFolder)
if 'logger' in globals(): log_msg = "Moving data folder to %s" % dataFolder
logger.info(stringToLog) try:
else: logger.info(log_msg)
print stringToLog except NameError:
print(log_msg)
except IOError: except IOError:
# Old directory may not exist. # Old directory may not exist.
pass pass
dataFolder = dataFolder + '/'
return dataFolder return dataFolder + os.path.sep
def codePath(): def codePath():
if frozen == "macosx_app": if frozen == "macosx_app":
codePath = environ.get("RESOURCEPATH") codePath = os.environ.get("RESOURCEPATH")
elif frozen: # windows elif frozen: # windows
codePath = sys._MEIPASS codePath = sys._MEIPASS
else: else:
codePath = path.dirname(__file__) codePath = os.path.dirname(__file__)
return codePath return codePath
def tail(f, lines=20): def tail(f, lines=20):
total_lines_wanted = lines total_lines_wanted = lines
@ -78,16 +98,17 @@ def tail(f, lines=20):
block_end_byte = f.tell() block_end_byte = f.tell()
lines_to_go = total_lines_wanted lines_to_go = total_lines_wanted
block_number = -1 block_number = -1
blocks = [] # blocks of size BLOCK_SIZE, in reverse order starting # blocks of size BLOCK_SIZE, in reverse order starting
# from the end of the file # from the end of the file
blocks = []
while lines_to_go > 0 and block_end_byte > 0: while lines_to_go > 0 and block_end_byte > 0:
if (block_end_byte - BLOCK_SIZE > 0): if (block_end_byte - BLOCK_SIZE > 0):
# read the last block we haven't yet read # read the last block we haven't yet read
f.seek(block_number*BLOCK_SIZE, 2) f.seek(block_number * BLOCK_SIZE, 2)
blocks.append(f.read(BLOCK_SIZE)) blocks.append(f.read(BLOCK_SIZE))
else: else:
# file too small, start from begining # file too small, start from begining
f.seek(0,0) f.seek(0, 0)
# only read what was not read # only read what was not read
blocks.append(f.read(block_end_byte)) blocks.append(f.read(block_end_byte))
lines_found = blocks[-1].count('\n') lines_found = blocks[-1].count('\n')
@ -99,9 +120,9 @@ def tail(f, lines=20):
def lastCommit(): def lastCommit():
githeadfile = path.join(codePath(), '..', '.git', 'logs', 'HEAD') githeadfile = os.path.join(codePath(), '..', '.git', 'logs', 'HEAD')
result = {} result = {}
if path.isfile(githeadfile): if os.path.isfile(githeadfile):
try: try:
with open(githeadfile, 'rt') as githead: with open(githeadfile, 'rt') as githead:
line = tail(githead, 1) line = tail(githead, 1)