Skip to content

Commit 5ca6dec

Browse files
committed
flake8 fixes.
1 parent 973d947 commit 5ca6dec

File tree

1 file changed

+71
-47
lines changed

1 file changed

+71
-47
lines changed

roundup/admin.py

Lines changed: 71 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@
2323

2424
__docformat__ = 'restructuredtext'
2525

26-
import csv, getopt, getpass, operator, os, re, shutil, sys
26+
import csv
27+
import getopt
28+
import getpass
29+
import operator
30+
import os
31+
import re
32+
import shutil
33+
import sys
2734

2835
from roundup import date, hyperdb, init, password, token
2936
from roundup import __version__ as roundup_version
@@ -157,10 +164,12 @@ def help_commands(self):
157164
commands.sort()
158165
commands.append(_(
159166
"""Commands may be abbreviated as long as the abbreviation
160-
matches only one command, e.g. l == li == lis == list."""))
167+
matches only one command, e.g. l == li == lis == list.""")) # noqa: E122
161168
sys.stdout.write('\n'.join(commands) + '\n\n')
162169

163-
def help_commands_html(self, indent_re=re.compile(r'^(\s+)\S+')):
170+
indent_re = re.compile(r'^(\s+)\S+')
171+
172+
def help_commands_html(self, indent_re=indent_re):
164173
""" Produce an HTML command list.
165174
"""
166175
commands = sorted(iter(self.commands.values()),
@@ -174,7 +183,7 @@ def help_commands_html(self, indent_re=re.compile(r'^(\s+)\S+')):
174183
<td><tt>%(usage)s</tt><p>
175184
<pre>""" % locals())
176185
indent = indent_re.match(h[3])
177-
if indent: indent = len(indent.group(1))
186+
if indent: indent = len(indent.group(1)) # noqa: E701
178187
for line in h[3:]:
179188
if indent:
180189
print(line[indent:])
@@ -249,8 +258,10 @@ def help_all(self):
249258
print(_('%s:') % name)
250259
print(' ', _(command.__doc__))
251260

252-
def do_help(self, args, nl_re=re.compile('[\r\n]'),
253-
indent_re=re.compile(r'^(\s+)\S+')):
261+
nl_re = re.compile('[\r\n]')
262+
# indent_re defined above
263+
264+
def do_help(self, args, nl_re=nl_re, indent_re=indent_re):
254265
''"""Usage: help topic
255266
Give help about topic.
256267
@@ -281,7 +292,7 @@ def do_help(self, args, nl_re=re.compile('[\r\n]'),
281292
lines = nl_re.split(_(help.__doc__))
282293
print(lines[0])
283294
indent = indent_re.match(lines[1])
284-
if indent: indent = len(indent.group(1))
295+
if indent: indent = len(indent.group(1)) # noqa: E701
285296
for line in lines[1:]:
286297
if indent:
287298
print(line[indent:])
@@ -320,17 +331,17 @@ def listTemplates(self, trace_search=False):
320331
# we're interested in where the directory containing "share" is
321332
debug = False
322333
templates = {}
323-
if debug: print(__file__)
334+
if debug: print(__file__) # noqa: E701
324335
for N in 2, 4, 5, 6:
325336
path = __file__
326337
# move up N elements in the path
327338
for _i in range(N):
328339
path = os.path.dirname(path)
329340
tdir = os.path.join(path, 'share', 'roundup', 'templates')
330-
if debug or trace_search: print(tdir)
341+
if debug or trace_search: print(tdir) # noqa: E701
331342
if os.path.isdir(tdir):
332343
templates = init.listTemplates(tdir)
333-
if debug: print(" Found templates breaking loop")
344+
if debug: print(" Found templates breaking loop") # noqa: E701
334345
break
335346

336347
# search for data files parallel to the roundup
@@ -349,7 +360,7 @@ def listTemplates(self, trace_search=False):
349360
# path is /usr/local/lib/python3.10/site-packages
350361
tdir = os.path.join(path, sys.prefix[1:], 'share',
351362
'roundup', 'templates')
352-
if debug or trace_search: print(tdir)
363+
if debug or trace_search: print(tdir) # noqa: E701
353364
if os.path.isdir(tdir):
354365
templates.update(init.listTemplates(tdir))
355366

@@ -359,29 +370,29 @@ def listTemplates(self, trace_search=False):
359370
# path is /usr/local/lib/python3.10/site-packages
360371
tdir = os.path.join(path, sys.base_prefix[1:], 'local', 'share',
361372
'roundup', 'templates')
362-
if debug or trace_search: print(tdir)
373+
if debug or trace_search: print(tdir) # noqa: E701
363374
if os.path.isdir(tdir):
364375
templates.update(init.listTemplates(tdir))
365-
# path is /usr/local/lib/python3.10/site-packages
366-
376+
# path is /usr/local/lib/python3.10/site-packages
367377

368378
tdir = os.path.join(path, sys.base_prefix[1:], 'share',
369379
'roundup', 'templates')
370-
if debug or trace_search: print(tdir)
380+
if debug or trace_search: print(tdir) # noqa: E701
371381
if os.path.isdir(tdir):
372382
templates.update(init.listTemplates(tdir))
373383
except AttributeError:
374384
pass # sys.base_prefix doesn't work under python2
375385

376386
# Try subdirs of the current dir
377387
templates.update(init.listTemplates(os.getcwd()))
378-
if debug or trace_search: print(os.getcwd() + '/*')
379-
388+
if debug or trace_search: print(os.getcwd() + '/*') # noqa: E701
389+
380390
# Finally, try the current directory as a template
381391
template = init.loadTemplateInfo(os.getcwd())
382-
if debug or trace_search: print(os.getcwd())
392+
if debug or trace_search: print(os.getcwd()) # noqa: E701
383393
if template:
384-
if debug: print(" Found template %s"%template['name'])
394+
if debug: print(" Found template %s" % # noqa: E701
395+
template['name'])
385396
templates[template['name']] = template
386397

387398
return templates
@@ -434,7 +445,7 @@ def do_install(self, tracker_home, args):
434445
ok = my_input(_(
435446
"""WARNING: There appears to be a tracker in "%(tracker_home)s"!
436447
If you re-install it, you will lose all the data!
437-
Erase it? Y/N: """) % locals())
448+
Erase it? Y/N: """) % locals()) # noqa: E122
438449
if ok.strip().lower() != 'y':
439450
return 0
440451

@@ -523,10 +534,9 @@ def do_install(self, tracker_home, args):
523534
You MUST run the "roundup-admin initialise" command once you've performed
524535
the above steps.
525536
---------------------------------------------------------------------------
526-
""") % {
527-
'database_config_file': os.path.join(tracker_home, 'schema.py'),
528-
'database_init_file': os.path.join(tracker_home, 'initial_data.py'),
529-
})
537+
""") % {'database_config_file': os.path.join(tracker_home, 'schema.py'),
538+
'database_init_file': os.path.join(tracker_home, 'initial_data.py')}) \
539+
# noqa: E122
530540
return 0
531541

532542
def _get_choice(self, list_name, prompt, options, argument, default=None):
@@ -598,7 +608,7 @@ def do_initialise(self, tracker_home, args):
598608
ok = my_input(_(
599609
"""WARNING: The database is already initialised!
600610
If you re-initialise it, you will lose all the data!
601-
Erase it? Y/N: """))
611+
Erase it? Y/N: """)) # noqa: E122
602612
if ok.strip().lower() != 'y':
603613
return 0
604614

@@ -655,7 +665,8 @@ def do_get(self, args):
655665
property = properties[propname]
656666
if not (isinstance(property, hyperdb.Multilink) or
657667
isinstance(property, hyperdb.Link)):
658-
raise UsageError(_('property %s is not of type'
668+
raise UsageError(_(
669+
'property %s is not of type'
659670
' Multilink or Link so -d flag does not '
660671
'apply.') % propname)
661672
propclassname = self.db.getclass(property.classname).classname
@@ -672,7 +683,8 @@ def do_get(self, args):
672683
property = properties[propname]
673684
if not (isinstance(property, hyperdb.Multilink) or
674685
isinstance(property, hyperdb.Link)):
675-
raise UsageError(_('property %s is not of type'
686+
raise UsageError(_(
687+
'property %s is not of type'
676688
' Multilink or Link so -d flag does not '
677689
'apply.') % propname)
678690
propclassname = self.db.getclass(property.classname).classname
@@ -803,8 +815,10 @@ def do_filter(self, args):
803815
try:
804816
curclassname = curclass.getprops()[pn].classname
805817
except KeyError:
806-
raise UsageError(_("Class %(curclassname)s has "
807-
"no property %(pn)s in %(propname)s." % locals()))
818+
raise UsageError(_(
819+
"Class %(curclassname)s has "
820+
"no property %(pn)s in %(propname)s." %
821+
locals()))
808822
# get class object
809823
curclass = self.get_class(curclassname)
810824
except AttributeError:
@@ -982,7 +996,7 @@ def do_create(self, args):
982996
if len(args) == 1:
983997
# ask for the properties
984998
for key in properties:
985-
if key == 'id': continue
999+
if key == 'id': continue # noqa: E701
9861000
value = properties[key]
9871001
name = value.__class__.__name__
9881002
if isinstance(value, hyperdb.Password):
@@ -994,7 +1008,8 @@ def do_create(self, args):
9941008
again = getpass.getpass(_(' %(propname)s (Again): ')
9951009
%
9961010
{'propname': key.capitalize()})
997-
if value != again: print(_('Sorry, try again...'))
1011+
if value != again:
1012+
print(_('Sorry, try again...'))
9981013
if value:
9991014
props[key] = value
10001015
else:
@@ -1009,7 +1024,8 @@ def do_create(self, args):
10091024
for propname in props:
10101025
try:
10111026
props[propname] = hyperdb.rawToHyperdb(self.db, cl, None,
1012-
propname, props[propname])
1027+
propname,
1028+
props[propname])
10131029
except hyperdb.HyperdbValueError as message:
10141030
raise UsageError(message)
10151031

@@ -1097,16 +1113,16 @@ def do_templates(self, args):
10971113

10981114
for name in sorted(list(templates.keys())):
10991115
templates[name]['description'] = textwrap.fill(
1100-
"\n".join([ line.lstrip() for line in
1101-
templates[name]['description'].split("\n")]),
1116+
"\n".join([line.lstrip() for line in
1117+
templates[name]['description'].split("\n")]),
11021118
70,
11031119
subsequent_indent=" "
11041120
)
11051121
print("""
11061122
Name: %(name)s
11071123
Path: %(path)s
11081124
Desc: %(description)s
1109-
"""%templates[name])
1125+
""" % templates[name])
11101126

11111127
def do_table(self, args):
11121128
''"""Usage: table classname [property[,property]*]
@@ -1399,7 +1415,7 @@ class colon_separated(csv.excel):
13991415

14001416
classkey = cl.getkey()
14011417
if classkey: # False sorts before True, so negate is_retired
1402-
keysort = lambda i: (cl.get(i, classkey),
1418+
keysort = lambda i: (cl.get(i, classkey), # noqa: E731
14031419
not cl.is_retired(i))
14041420
all_nodes.sort(key=keysort)
14051421
# if there is no classkey no need to sort
@@ -1580,7 +1596,9 @@ def do_pack(self, args):
15801596
self.db_uncommitted = True
15811597
return 0
15821598

1583-
def do_reindex(self, args, desre=re.compile('([A-Za-z]+)([0-9]+)')):
1599+
designator_re = re.compile('([A-Za-z]+)([0-9]+)')
1600+
1601+
def do_reindex(self, args, desre=designator_re):
15841602
''"""Usage: reindex [classname|designator]*
15851603
Re-generate a tracker's search indexes.
15861604
@@ -1637,8 +1655,9 @@ def do_security(self, args):
16371655
d = permission.__dict__
16381656
if permission.klass:
16391657
if permission.properties:
1640-
sys.stdout.write(_(' %(description)s (%(name)s for "%(klass)s"' +
1641-
': %(properties)s only)\n') % d)
1658+
sys.stdout.write(_(
1659+
' %(description)s (%(name)s for "%(klass)s"' +
1660+
': %(properties)s only)\n') % d)
16421661
# verify that properties exist; report bad props
16431662
bad_props = []
16441663
cl = self.db.getclass(permission.klass)
@@ -1649,7 +1668,11 @@ def do_security(self, args):
16491668
else:
16501669
bad_props.append(p)
16511670
if bad_props:
1652-
sys.stdout.write(_('\n **Invalid properties for %(class)s: %(props)s\n\n') % {"class": permission.klass, "props": bad_props})
1671+
sys.stdout.write(_(
1672+
'\n **Invalid properties for %(class)s: '
1673+
'%(props)s\n\n') % {
1674+
"class": permission.klass,
1675+
"props": bad_props})
16531676
return 1
16541677
else:
16551678
sys.stdout.write(_(' %(description)s (%(name)s for '
@@ -1679,7 +1702,7 @@ def do_migrate(self, args):
16791702
It's safe to run this even if it's not required, so just get
16801703
into the habit.
16811704
"""
1682-
if getattr(self.db, 'db_version_updated'):
1705+
if self.db.db_version_updated:
16831706
print(_('Tracker updated'))
16841707
self.db_uncommitted = True
16851708
else:
@@ -1755,7 +1778,8 @@ def run_command(self, args):
17551778
self.tracker_home = ''
17561779
print(_("Error: Couldn't open tracker: %(message)s") % locals())
17571780
return 1
1758-
except ParsingOptionError as message: # message used via locals
1781+
# message used via locals
1782+
except ParsingOptionError as message: # noqa: F841
17591783
print("%(message)s" % locals())
17601784
return 1
17611785

@@ -1766,7 +1790,7 @@ def run_command(self, args):
17661790
# cli operator likely wants to have i18n as set in the
17671791
# environment.
17681792
# This is needed to fetch the locale's of the tracker's home dir.
1769-
self.db.i18n = get_translation (tracker_home = tracker.tracker_home)
1793+
self.db.i18n = get_translation(tracker_home=tracker.tracker_home)
17701794

17711795
self.db.tx_Source = 'cli'
17721796

@@ -1801,13 +1825,13 @@ def interactive(self):
18011825
except EOFError:
18021826
print(_('exit...'))
18031827
break
1804-
if not command: continue
1828+
if not command: continue # noqa: E701
18051829
try:
18061830
args = token.token_split(command)
18071831
except ValueError:
18081832
continue # Ignore invalid quoted token
1809-
if not args: continue
1810-
if args[0] in ('quit', 'exit'): break
1833+
if not args: continue # noqa: E701
1834+
if args[0] in ('quit', 'exit'): break # noqa: E701
18111835
self.run_command(args)
18121836

18131837
# exit.. check for transactions
@@ -1879,7 +1903,7 @@ def main(self):
18791903
self.interactive()
18801904
else:
18811905
ret = self.run_command(args)
1882-
if self.db: self.db.commit()
1906+
if self.db: self.db.commit() # noqa: E701
18831907
return ret
18841908
finally:
18851909
if self.db:

0 commit comments

Comments
 (0)