Skip to content

Commit

Permalink
Fixed up flake8 errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
esitarski committed Jul 25, 2024
1 parent 776c062 commit 02907ec
Show file tree
Hide file tree
Showing 108 changed files with 587 additions and 1,422 deletions.
4 changes: 1 addition & 3 deletions CallupSeedingMgr/CallupResultsToExcel.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import wx
import sys
import datetime
import xlsxwriter
import Utils

import Model
from FitSheetWrapper import FitSheetWrapper
from GetCallups import make_title
Expand Down
2 changes: 1 addition & 1 deletion CallupSeedingMgr/CallupResultsToGrid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import wx
import wx.grid as gridlib
import sys

import Utils
import Model
from GetCallups import make_title
Expand Down
3 changes: 1 addition & 2 deletions CallupSeedingMgr/CallupSeedingMgrSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'pyinstaller',

'CallupSeedingMgr.pyw',
'--icon=CallupSeedingMgrImages\CallupSeedingMgr.ico',
'--icon=CallupSeedingMgrImages/CallupSeedingMgr.ico',
'--clean',
'--windowed',
'--noconfirm',
Expand Down Expand Up @@ -71,7 +71,6 @@ def copyDir( d ):
inno = innoTest
break

from Version import AppVerName
def make_inno_version():
setup = {
'AppName': AppVerName.split()[0],
Expand Down
2 changes: 1 addition & 1 deletion CallupSeedingMgr/CopyMedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def NeedsUpdating( srcFName, destFName ):
try:
srcStat = os.stat( srcFName )
destStat = os.stat( destFName )
except:
except Exception:
return True

return srcStat.st_mtime > destStat.st_mtime or srcStat.st_size != destStat.st_size
Expand Down
4 changes: 2 additions & 2 deletions CallupSeedingMgr/CountryIOC.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# -*- coding: utf-8 -*-

import os
import io
import json

from Utils import imageFolder, removeDiacritic

# from https://github.com/mledoze/countries
fname = os.path.join( imageFolder, 'countries.json' )
with io.open(fname, mode='r', encoding='utf8') as fp:
with open(fname, mode='r', encoding='utf8') as fp:
country_info = json.loads( fp.read() )

uci_country_codes = {}
Expand All @@ -23,6 +22,7 @@

for c in country_info:
names = set()

def scan( d ):
for k, v in d.items():
if isinstance(v, dict):
Expand Down
1 change: 0 additions & 1 deletion CallupSeedingMgr/FitSheetWrapper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import Utils
import math

class FitSheetWrapper(object):
"""Try to fit columns to max size of any entry.
Expand Down
8 changes: 3 additions & 5 deletions CallupSeedingMgr/GetCallups.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
import sys
import datetime
import Utils

import random
from Model import Source
from Excel import GetExcelReader
Expand Down Expand Up @@ -121,7 +119,7 @@ def GetCallups( fname, soundalike=True, useUciId=True, useLicense=True, callback
registration_headers = registration.get_ordered_fields()

# Also add the team code if there is one.
if not 'team_code' in registration_headers:
if 'team_code' not in registration_headers:
for iSource, source in enumerate(sources):
if 'team_code' in source.get_ordered_fields():
try:
Expand All @@ -137,7 +135,7 @@ def GetCallups( fname, soundalike=True, useUciId=True, useLicense=True, callback
for reg in callup_order:
try:
reg.team_code = reg.result_vector[iSource].matches[0].team_code
except:
except Exception:
pass
break

Expand Down
4 changes: 2 additions & 2 deletions CallupSeedingMgr/HelpIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def addDocument( fname, section, lastTitle, textCur ):
for child in div.contents:
try:
tag = child.name
except:
except Exception:
tag = None

if tag not in titleTags:
try:
textCur.append( child.get_text() )
except:
except Exception:
pass
continue

Expand Down
81 changes: 39 additions & 42 deletions CallupSeedingMgr/MainWin.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import wx
import wx.adv
from wx.lib.wordwrap import wordwrap
import wx.lib.filebrowsebutton as filebrowse
import sys
import os
import re
import datetime
import traceback
import webbrowser
from optparse import OptionParser
from roundbutton import RoundButton

import wx
import wx.adv
import wx.lib.filebrowsebutton as filebrowse

import Utils
from ReorderableGrid import ReorderableGrid
import Model
import Version
from GetCallups import GetCallups, make_title
from CallupResultsToGrid import CallupResultsToGrid
from CallupResultsToExcel import CallupResultsToExcel
Expand All @@ -25,7 +21,7 @@
def ShowSplashScreen():
bitmap = wx.Bitmap( os.path.join(Utils.getImageFolder(), 'CallupSeedingMgr.png'), wx.BITMAP_TYPE_PNG )
showSeconds = 2.5
frame = wx.adv.SplashScreen(bitmap, wx.adv.SPLASH_CENTRE_ON_SCREEN|wx.adv.SPLASH_TIMEOUT, int(showSeconds*1000), None)
wx.adv.SplashScreen(bitmap, wx.adv.SPLASH_CENTRE_ON_SCREEN|wx.adv.SPLASH_TIMEOUT, int(showSeconds*1000), None)

class ErrorDialog( wx.Dialog ):
def __init__( self, parent, errors, id=wx.ID_ANY, title='Errors', size=(800,600) ):
Expand Down Expand Up @@ -452,7 +448,7 @@ def getCycleLast( self ):
def doUpdate( self, event=None, fnameNew=None ):
try:
self.fname = fnameNew or (event and event.GetString()) or self.fileBrowse.GetValue()
except:
except Exception:
self.fname = ''

if not self.fname:
Expand All @@ -464,7 +460,7 @@ def doUpdate( self, event=None, fnameNew=None ):
return

try:
with open(self.fname, 'rb') as f:
with open(self.fname, 'rb'):
pass
except Exception as e:
Utils.MessageOK( self, '{}:\n\n {}\n\n{}'.format( _('Cannot Open Excel file'), self.fname, e), _('Cannot Open Excel File') )
Expand All @@ -473,37 +469,38 @@ def doUpdate( self, event=None, fnameNew=None ):

self.filehistory.AddFileToHistory( self.fname )
self.filehistory.Save( self.config )

with wx.BusyCursor():
labelSave, backgroundColourSave = self.updateButton.GetLabel(), self.updateButton.GetForegroundColour()

try:
self.registration_headers, self.callup_headers, self.callup_results, self.sources, self.errors = GetCallups(
self.fname,
soundalike = self.getIsSoundalike(),
useUciId = self.getUseUciId(),
useLicense = self.getUseLicense(),
callbackfunc = self.updateSourceList,
callbackupdate = self.callbackUpdate,
cycleLast = self.getCycleLast(),
)
except Exception as e:
traceback.print_exc()
Utils.MessageOK( self, '{}:\n\n {}\n\n{}'.format( _('Excel File Error'), self.fname, e), _('Excel File Error') )
self.setUpdated( False )
return

wait = wx.BusyCursor()
labelSave, backgroundColourSave = self.updateButton.GetLabel(), self.updateButton.GetForegroundColour()

try:
self.registration_headers, self.callup_headers, self.callup_results, self.sources, self.errors = GetCallups(
self.fname,
soundalike = self.getIsSoundalike(),
useUciId = self.getUseUciId(),
useLicense = self.getUseLicense(),
callbackfunc = self.updateSourceList,
callbackupdate = self.callbackUpdate,
cycleLast = self.getCycleLast(),
self.setUpdated( True )

self.updateSourceList()

CallupResultsToGrid(
self.grid,
self.registration_headers, self.callup_headers, self.callup_results,
is_callup=(self.callupSeedingRB.GetSelection() == 0),
top_riders=self.getTopRiders(),
exclude_unranked=self.excludeUnrankedCB.GetValue(),
)
except Exception as e:
traceback.print_exc()
Utils.MessageOK( self, '{}:\n\n {}\n\n{}'.format( _('Excel File Error'), self.fname, e), _('Excel File Error') )
self.setUpdated( False )
return

self.setUpdated( True )

self.updateSourceList()

CallupResultsToGrid(
self.grid,
self.registration_headers, self.callup_headers, self.callup_results,
is_callup=(self.callupSeedingRB.GetSelection() == 0),
top_riders=self.getTopRiders(),
exclude_unranked=self.excludeUnrankedCB.GetValue(),
)
self.GetSizer().Layout()
self.lastUpdateTime = datetime.datetime.now()

Expand Down Expand Up @@ -580,12 +577,12 @@ def MainLoop():
logSize = os.path.getsize( redirectFileName )
if logSize > 1000000:
os.remove( redirectFileName )
except:
except Exception:
pass

try:
app.RedirectStdio( redirectFileName )
except:
except Exception:
pass

mainWin = MainWin( None, title=AppVerName, size=(800,600) )
Expand All @@ -596,7 +593,7 @@ def MainLoop():
try:
icon = wx.Icon( os.path.join(Utils.getImageFolder(), 'CallupSeedingMgr.ico'), wx.BITMAP_TYPE_ICO )
mainWin.SetIcon( icon )
except:
except Exception:
pass

mainWin.Show()
Expand Down
12 changes: 5 additions & 7 deletions CallupSeedingMgr/Model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import re
import sys
import datetime
Expand All @@ -7,8 +6,7 @@
from metaphone import doublemetaphone

import Utils
from Excel import GetExcelReader
from CountryIOC import uci_country_codes, uci_country_codes_set, ioc_from_country, country_from_ioc
from CountryIOC import uci_country_codes, ioc_from_country, country_from_ioc

countryTranslations = {
'England': 'United Kingdom',
Expand Down Expand Up @@ -431,7 +429,7 @@ def get_sort_key( self ):
key = self.get_key()
try:
row = self.matches[0].row
except:
except Exception:
row = 999999
# Add the row as a sort criteria.
return key + tuple([row]) if isinstance(key, tuple) else (key, row)
Expand Down Expand Up @@ -507,6 +505,7 @@ class Source:
'by_mp_last_name', 'by_mp_first_name',
'by_nation_code', 'by_date_of_birth', 'by_age',
)

def __init__( self, fname, sheet_name, soundalike=True, useUciId=True, useLicense=True ):
self.fname = fname
self.sheet_name = sheet_name
Expand Down Expand Up @@ -541,7 +540,6 @@ def get_cmp_policy_name( self ):

def read( self, reader ):
header_fields = ['name'] + list(Result.Fields)
dCur = datetime.date.today()
header_map = {}
errors = []
for row_number, row in enumerate(reader.iter_list(self.sheet_name)):
Expand Down Expand Up @@ -660,7 +658,7 @@ def add( self, result ):
assert idx_name != 'by_license' or v not in idx, 'Duplicate license: {}'.format(v)
try:
key = normalize_name_lookup(v)
except:
except Exception:
key = v
try:
idx[key].append( result )
Expand Down Expand Up @@ -701,7 +699,7 @@ def match_indices( self, search, indices ):

try:
v = normalize_name_lookup( v )
except:
except Exception:
pass

if self.debug: print( 'match_indices: value=', v )
Expand Down
14 changes: 4 additions & 10 deletions CallupSeedingMgr/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@ def initTranslation():
if not initTranslationCalled:
try:
gettext.install(AppVerName.split(None, 1), './locale', unicode=True)
except:
except Exception:
gettext.install(AppVerName.split(None, 1), './locale')

initTranslationCalled = True

initTranslation()

try:
from win32com.shell import shell, shellcon
except ImportError:
pass

import os
import re
import sys
import platform
import datetime
Expand All @@ -40,7 +34,7 @@ def removeDiacritic( s ):
'''
try:
return unicodedata.normalize('NFKD', '{}'.format(s)).encode('ASCII', 'ignore').decode()
except:
except Exception:
return s

'''
Expand Down Expand Up @@ -95,7 +89,7 @@ def AdjustGridSize( grid, rowsRequired = None, colsRequired = None ):
if 'WXMAC' in wx.Platform:
try:
topdirName = os.environ['RESOURCEPATH']
except:
except Exception:
topdirName = os.path.dirname(os.path.realpath(__file__))
if os.path.isdir( os.path.join(topdirName, 'CallupSeedingMgrImages') ):
dirName = topdirName
Expand All @@ -109,7 +103,7 @@ def AdjustGridSize( grid, rowsRequired = None, colsRequired = None ):
else:
try:
dirName = os.path.dirname(os.path.abspath(__file__))
except:
except Exception:
dirName = os.path.dirname(os.path.abspath(sys.argv[0]))

if os.path.basename(dirName) in ['library.zip', 'MainWin.exe', 'CrossMgrCallUpSeedingMgr.exe']:
Expand Down
2 changes: 1 addition & 1 deletion CallupSeedingMgr/Version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
AppVerName="CallupSeedingMgr 4.0.0-private"
AppVerName="CallupSeedingMgr 4.0.1-private"
Loading

0 comments on commit 02907ec

Please sign in to comment.