Skip to content

Commit

Permalink
python files: avoid single-letter variable names
Browse files Browse the repository at this point in the history
Replace a bunch of cases of the variable "l" with more meaningful names.
In almost every case, this is "line", but in one case it was "license".
  • Loading branch information
allisonkarlitskaya authored and thomasvandenbosch13 committed Apr 12, 2021
1 parent e0009cf commit 6d3c2bd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions test/verify/check-pages
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,8 @@ OnCalendar=daily

def read_mem_info(machine):
info = {}
for l in machine.execute("cat /proc/meminfo").splitlines():
(name, value) = l.strip().split(":")
for line in machine.execute("cat /proc/meminfo").splitlines():
(name, value) = line.strip().split(":")
if value.endswith("kB"):
info[name] = int(value[:-2]) * 1024
else:
Expand Down
4 changes: 2 additions & 2 deletions test/verify/check-system-realms
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ ExecStart=/bin/true
with open("src/tls/ca/alice.pem") as f:
alice_cert = f.read().strip()
# IPA does not like the ---BEGIN/END lines
alice_cert = '\n'.join([l for l in alice_cert.splitlines() if not l.startswith("----")])
alice_cert = '\n'.join([line for line in alice_cert.splitlines() if not line.startswith("----")])
# set up an IPA user with a TLS certificate; can't use "admin" due to https://pagure.io/freeipa/issue/6683
ipa_machine.execute(r"""podman exec -i freeipa sh -exc '
ipa user-add --first=Alice --last="Developer" alice
Expand Down Expand Up @@ -689,7 +689,7 @@ class TestAD(TestRealms, CommonTests):
with open("src/tls/ca/alice.pem") as f:
alice_cert = f.read().strip()
# mangle into form palatable for LDAP
alice_cert = ''.join([l for l in alice_cert.splitlines() if not l.startswith("----")])
alice_cert = ''.join([line for line in alice_cert.splitlines() if not line.startswith("----")])
# set up an AD user and import their TLS certificate; avoid using the common "userCertificate;binary",
# as that does not work with Samba
services_machine.execute(r"""podman exec -i samba sh -exc '
Expand Down
46 changes: 23 additions & 23 deletions tools/build-debian-copyright
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def template_licenses(template):
'''Return set of existing License: short names'''

ids = set()
for l in template.splitlines():
if l.startswith('License:'):
ids.add(l.split(None, 1)[1].lower())
for line in template.splitlines():
if line.startswith('License:'):
ids.add(line.split(None, 1)[1].lower())
return ids


Expand All @@ -40,10 +40,10 @@ def module_license(moddir):
# First check if package.json has a "license" field
try:
with open(os.path.join(moddir, 'package.json'), encoding='UTF-8') as f:
l = json.load(f)['license']
if l.startswith('(MIT OR'):
license = json.load(f)['license']
if license.startswith('(MIT OR'):
return 'MIT'
return l
return license
except (IOError, KeyError):
pass

Expand All @@ -70,7 +70,7 @@ def module_copyright(moddir):
try:
out = subprocess.check_output(['env', '-u', 'LANGUAGE', 'LC_ALL=C.UTF-8', 'grep', '-hri', 'copyright.*\([1-9][0-9]\+\|(c)\)'],
cwd=moddir).decode('UTF-8')
for l in out.splitlines():
for line in out.splitlines():
# weed out some noise
reject_substr = ['Binary file',
'{"version":',
Expand All @@ -87,27 +87,27 @@ def module_copyright(moddir):
'glyph-name=',
'copyright holder',
'WIPO copyright treaty']
if any(substr in l for substr in reject_substr):
if any(substr in line for substr in reject_substr):
continue

l = l.replace('<copyright>', '').replace('</copyright>', '')
l = l.replace('&copy;', '(c)').replace('copyright = ', '')
l = re.sub('@license.*Copyright', '', l)
l = l.strip(' \t*/\'|,#')
if not l.endswith('Inc.'):
line = line.replace('<copyright>', '').replace('</copyright>', '')
line = line.replace('&copy;', '(c)').replace('copyright = ', '')
line = re.sub('@license.*Copyright', '', line)
line = line.strip(' \t*/\'|,#')
if not line.endswith('Inc.'):
# avoids some duplicated lines which only differ in trailing dot
l = l.strip('.')
if l.startswith("u'") or l.startswith('u"'): # Python unicode prefix
l = l[2:]
if 'Fixes #' in l:
line = line.strip('.')
if line.startswith("u'") or line.startswith('u"'): # Python unicode prefix
line = line[2:]
if 'Fixes #' in line:
continue # this is from a changelog
# some noise fine-tuning for specific packages
if mod == 'bootstrap' and ('https://github.com' in l or l == 'Copyright 2015'):
if mod == 'bootstrap' and ('https://github.com' in line or line == 'Copyright 2015'):
continue
if mod == 'patternfly':
l = re.sub(' and licensed.*', '', l)
line = re.sub(' and licensed.*', '', line)

copyrights.add(' ' + l) # space prefix for debian/copyright RFC822 format
copyrights.add(' ' + line) # space prefix for debian/copyright RFC822 format
except subprocess.CalledProcessError:
pass

Expand Down Expand Up @@ -176,9 +176,9 @@ for paragraph in sorted(paragraphs):
output.append(f'Files: {files}\n{paragraph}')

# force UTF-8 output, even when running in C locale
for l in template.splitlines():
if '#NPM' in l:
for line in template.splitlines():
if '#NPM' in line:
sys.stdout.buffer.write('\n\n'.join(output).encode('UTF-8'))
else:
sys.stdout.buffer.write(l.encode('UTF-8'))
sys.stdout.buffer.write(line.encode('UTF-8'))
sys.stdout.buffer.write(b'\n')

0 comments on commit 6d3c2bd

Please sign in to comment.