Skip to content

Commit a8dadbc

Browse files
committed
flake 8 improvements
Renamed some variables from l to something (I hope) more descriptive. Left a number of long lines and unindented quoted ''' string blocks. The blocks are often inside a _() translation function call. Adding white space to indent them would mess up the translation tables and require reformatting as they are output. I might be able to reformat: _( ''' message for the user here on multiple lines''' ) as separate concatenated lines and preserve the translation key but...
1 parent d6d02ca commit a8dadbc

File tree

1 file changed

+51
-47
lines changed

1 file changed

+51
-47
lines changed

roundup/admin.py

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

2424
__docformat__ = 'restructuredtext'
2525

26-
import csv, getopt, getpass, os, re, shutil, sys, operator
26+
import csv, getopt, getpass, operator, os, re, shutil, sys
2727

2828
from roundup import date, hyperdb, init, password, token
2929
from roundup import __version__ as roundup_version
@@ -52,13 +52,16 @@ def get(self, key, default=_marker):
5252
if key in self.data:
5353
return [(key, self.data[key])]
5454
keylist = sorted(self.data)
55-
l = []
55+
matching_keys = []
5656
for ki in keylist:
5757
if ki.startswith(key):
58-
l.append((ki, self.data[ki]))
59-
if not l and default is self._marker:
58+
matching_keys.append((ki, self.data[ki]))
59+
if not matching_keys and default is self._marker:
6060
raise KeyError(key)
61-
return l
61+
# FIXME: what happens if default is not self._marker but
62+
# there are no matching keys? Should (default, self.data[default])
63+
# be returned???
64+
return matching_keys
6265

6366

6467
class AdminTool:
@@ -102,12 +105,12 @@ def props_from_args(self, args):
102105
"""
103106
props = {}
104107
for arg in args:
105-
l = arg.split('=', 1)
108+
key_val = arg.split('=', 1)
106109
# if = not in string, will return one element
107-
if len(l) < 2:
110+
if len(key_val) < 2:
108111
raise UsageError(_('argument "%(arg)s" not propname=value') %
109112
locals())
110-
key, value = l
113+
key, value = key_val
111114
if value:
112115
props[key] = value
113116
else:
@@ -118,7 +121,7 @@ def usage(self, message=''):
118121
""" Display a simple usage message.
119122
"""
120123
if message:
121-
message = _('Problem: %(message)s\n\n')% locals()
124+
message = _('Problem: %(message)s\n\n') % locals()
122125
sys.stdout.write(_("""%(message)sUsage: roundup-admin [options] [<command> <arguments>]
123126
124127
Options:
@@ -268,13 +271,13 @@ def do_help(self, args, nl_re=re.compile('[\r\n]'),
268271

269272
# try command docstrings
270273
try:
271-
l = self.commands.get(topic)
274+
cmd_docs = self.commands.get(topic)
272275
except KeyError:
273276
print(_('Sorry, no help for "%(topic)s"') % locals())
274277
return 1
275278

276279
# display the help for each match, removing the docstring indent
277-
for _name, help in l:
280+
for _name, help in cmd_docs:
278281
lines = nl_re.split(_(help.__doc__))
279282
print(lines[0])
280283
indent = indent_re.match(lines[1])
@@ -339,14 +342,14 @@ def listTemplates(self):
339342
# os.prefix should be /usr, /usr/local or root of virtualenv
340343
# strip leading / to make os.path.join work right.
341344
path = __file__
342-
for N in 1, 2:
345+
for _N in 1, 2:
343346
path = os.path.dirname(path)
344347
# path is /usr/local/lib/python3.10/site-packages
345348
tdir = os.path.join(path, sys.prefix[1:], 'share',
346349
'roundup', 'templates')
347350
if os.path.isdir(tdir):
348351
templates.update(init.listTemplates(tdir))
349-
352+
350353
# OK, now try as if we're in the roundup source distribution
351354
# directory, so this module will be in .../roundup-*/roundup/admin.py
352355
# and we're interested in the .../roundup-*/ part.
@@ -458,7 +461,7 @@ def do_install(self, tracker_home, args):
458461
# it sets parameters like template_engine that are
459462
# template specific.
460463
template_config = UserConfig(templates[template]['path'] +
461-
"/config_ini.ini")
464+
"/config_ini.ini")
462465
for k in template_config.keys():
463466
if k == 'HOME': # ignore home. It is a default param.
464467
continue
@@ -606,7 +609,7 @@ def do_get(self, args):
606609
raise UsageError(_('Not enough arguments supplied'))
607610
propname = args[0]
608611
designators = args[1].split(',')
609-
l = []
612+
linked_props = []
610613
for designator in designators:
611614
# decode the node designator
612615
try:
@@ -642,11 +645,11 @@ def do_get(self, args):
642645
propclassname = self.db.getclass(property.classname).classname
643646
id = cl.get(nodeid, propname)
644647
for i in id:
645-
l.append(propclassname + i)
648+
linked_props.append(propclassname + i)
646649
else:
647650
id = cl.get(nodeid, propname)
648651
for i in id:
649-
l.append(i)
652+
linked_props.append(i)
650653
else:
651654
if self.print_designator:
652655
properties = cl.getprops()
@@ -669,7 +672,7 @@ def do_get(self, args):
669672
raise UsageError(_('no such %(classname)s property '
670673
'"%(propname)s"') % locals())
671674
if self.separator:
672-
print(self.separator.join(l))
675+
print(self.separator.join(linked_props))
673676

674677
return 0
675678

@@ -766,20 +769,20 @@ def do_filter(self, args):
766769
if ',' in value:
767770
values = value.split(',')
768771
else:
769-
values = [ value ]
772+
values = [value]
770773

771774
props[propname] = []
772775
# start handling transitive props
773776
# given filter issue assignedto.roles=Admin
774777
# start at issue
775778
curclass = cl
776-
lastprop = propname # handle case 'issue assignedto=admin'
779+
lastprop = propname # handle case 'issue assignedto=admin'
777780
if '.' in propname:
778781
# start splitting transitive prop into components
779782
# we end when we have no more links
780783
for pn in propname.split('.'):
781784
try:
782-
lastprop=pn # get current component
785+
lastprop = pn # get current component
783786
# get classname for this link
784787
try:
785788
curclassname = curclass.getprops()[pn].classname
@@ -802,7 +805,7 @@ def do_filter(self, args):
802805
try:
803806
id = []
804807
designator = []
805-
props = { "filterspec": props }
808+
props = {"filterspec": props}
806809

807810
if self.separator:
808811
if self.print_designator:
@@ -990,15 +993,15 @@ def do_create(self, args):
990993
for propname in props:
991994
try:
992995
props[propname] = hyperdb.rawToHyperdb(self.db, cl, None,
993-
propname, props[propname])
996+
propname, props[propname])
994997
except hyperdb.HyperdbValueError as message:
995998
raise UsageError(message)
996999

9971000
# check for the key property
9981001
propname = cl.getkey()
9991002
if propname and propname not in props:
10001003
raise UsageError(_('you must provide the "%(propname)s" '
1001-
'property.') % locals())
1004+
'property.') % locals())
10021005

10031006
# do the actual create
10041007
try:
@@ -1122,7 +1125,7 @@ def do_table(self, args):
11221125
if ':' in spec:
11231126
name, width = spec.split(':')
11241127
if width == '':
1125-
# spec includes trailing :, use label/name width
1128+
# spec includes trailing :, use label/name width
11261129
props.append((name, len(name)))
11271130
else:
11281131
try:
@@ -1146,7 +1149,7 @@ def do_table(self, args):
11461149

11471150
# and the table data
11481151
for nodeid in cl.list():
1149-
l = []
1152+
table_columns = []
11501153
for name, width in props:
11511154
if name != 'id':
11521155
try:
@@ -1159,8 +1162,8 @@ def do_table(self, args):
11591162
else:
11601163
value = str(nodeid)
11611164
f = '%%-%ds' % width
1162-
l.append(f % value[:width])
1163-
print(' '.join(l))
1165+
table_columns.append(f % value[:width])
1166+
print(' '.join(table_columns))
11641167
return 0
11651168

11661169
def do_history(self, args):
@@ -1282,7 +1285,7 @@ def do_restore(self, args):
12821285
raise UsageError(e.args[0])
12831286
except IndexError:
12841287
raise UsageError(_('no such %(classname)s node '
1285-
'" % (nodeid)s"')%locals())
1288+
'" % (nodeid)s"') % locals())
12861289
self.db_uncommitted = True
12871290
return 0
12881291

@@ -1309,7 +1312,7 @@ def do_export(self, args, export_files=True):
13091312
if len(args) == 2:
13101313
if args[0].startswith('-'):
13111314
classes = [c for c in self.db.classes
1312-
if c not in args[0][1:].split(',')]
1315+
if c not in args[0][1:].split(',')]
13131316
else:
13141317
classes = args[0].split(',')
13151318
else:
@@ -1331,12 +1334,11 @@ class colon_separated(csv.excel):
13311334

13321335
if not export_files and hasattr(cl, 'export_files'):
13331336
sys.stdout.write('Exporting %s WITHOUT the files\r\n' %
1334-
classname)
1337+
classname)
13351338

13361339
with open(os.path.join(dir, classname+'.csv'), 'w') as f:
13371340
writer = csv.writer(f, colon_separated)
13381341

1339-
properties = cl.getprops()
13401342
propnames = cl.export_propnames()
13411343
fields = propnames[:]
13421344
fields.append('is retired')
@@ -1352,20 +1354,21 @@ class colon_separated(csv.excel):
13521354
all_nodes = cl.getnodeids()
13531355

13541356
classkey = cl.getkey()
1355-
if classkey: # False sorts before True, so negate is_retired
1357+
if classkey: # False sorts before True, so negate is_retired
13561358
keysort = lambda i: (cl.get(i, classkey),
13571359
not cl.is_retired(i))
13581360
all_nodes.sort(key=keysort)
13591361
# if there is no classkey no need to sort
13601362

13611363
for nodeid in all_nodes:
13621364
if self.verbose:
1363-
sys.stdout.write('\rExporting %s - %s' %
1365+
sys.stdout.write('\rExporting %s - %s' %
13641366
(classname, nodeid))
13651367
sys.stdout.flush()
13661368
node = cl.getnode(nodeid)
13671369
exp = cl.export_list(propnames, nodeid)
1368-
lensum = sum([len(repr_export(node[p])) for p in propnames])
1370+
lensum = sum([len(repr_export(node[p])) for
1371+
p in propnames])
13691372
# for a safe upper bound of field length we add
13701373
# difference between CSV len and sum of all field lengths
13711374
d = sum([len(x) for x in exp]) - lensum
@@ -1382,7 +1385,8 @@ class colon_separated(csv.excel):
13821385
# export the journals
13831386
with open(os.path.join(dir, classname+'-journals.csv'), 'w') as jf:
13841387
if self.verbose:
1385-
sys.stdout.write("\nExporting Journal for %s\n" % classname)
1388+
sys.stdout.write("\nExporting Journal for %s\n" %
1389+
classname)
13861390
sys.stdout.flush()
13871391
journals = csv.writer(jf, colon_separated)
13881392
for row in cl.export_journals():
@@ -1665,12 +1669,12 @@ def run_command(self, args):
16651669
except KeyError:
16661670
# not a valid command
16671671
print(_('Unknown command "%(command)s" ("help commands" for a '
1668-
'list)') % locals())
1672+
'list)') % locals())
16691673
return 1
16701674

16711675
# check for multiple matches
16721676
if len(functions) > 1:
1673-
print(_('Multiple commands match "%(command)s": %(list)s') % \
1677+
print(_('Multiple commands match "%(command)s": %(list)s') %
16741678
{'command': command,
16751679
'list': ', '.join([i[0] for i in functions])})
16761680
return 1
@@ -1708,7 +1712,7 @@ def run_command(self, args):
17081712
self.tracker_home = ''
17091713
print(_("Error: Couldn't open tracker: %(message)s") % locals())
17101714
return 1
1711-
except ParsingOptionError as message:
1715+
except ParsingOptionError as message: # message used via locals
17121716
print("%(message)s" % locals())
17131717
return 1
17141718

@@ -1777,10 +1781,10 @@ def main(self):
17771781
self.name = 'admin'
17781782
self.password = '' # unused
17791783
if 'ROUNDUP_LOGIN' in os.environ:
1780-
l = os.environ['ROUNDUP_LOGIN'].split(':')
1781-
self.name = l[0]
1782-
if len(l) > 1:
1783-
self.password = l[1]
1784+
login_env = os.environ['ROUNDUP_LOGIN'].split(':')
1785+
self.name = login_env[0]
1786+
if len(login_env) > 1:
1787+
self.password = login_env[1]
17841788
self.separator = None
17851789
self.print_designator = 0
17861790
self.verbose = 0
@@ -1814,10 +1818,10 @@ def main(self):
18141818
elif opt == '-d':
18151819
self.print_designator = 1
18161820
elif opt == '-u':
1817-
l = arg.split(':')
1818-
self.name = l[0]
1819-
if len(l) > 1:
1820-
self.password = l[1]
1821+
login_opt = arg.split(':')
1822+
self.name = login_opt[0]
1823+
if len(login_opt) > 1:
1824+
self.password = login_opt[1]
18211825

18221826
# if no command - go interactive
18231827
# wrap in a try/finally so we always close off the db

0 commit comments

Comments
 (0)