1
0
mirror of https://github.com/certbot/certbot.git synced 2026-01-26 07:41:33 +03:00

Address review comments

This commit is contained in:
Joona Hoikkala
2019-03-04 15:52:38 +02:00
parent 8bda10541a
commit d8a3fa3904
3 changed files with 34 additions and 26 deletions

View File

@@ -55,21 +55,24 @@ def main(*paths):
"""Merges multiple requirements files together and prints the result.
Requirement files specified later in the list take precedence over earlier
files.
files. Files are read from file paths passed from the command line arguments.
:param tuple paths: paths to requirements files
If no command line arguments are defined, data is read from stdin instead.
:param tuple paths: paths to requirements files provided on command line
"""
data = {}
for path in paths:
data.update(process_entries(read_file(path)))
# Need to check if interactive to avoid blocking if nothing is piped
if not sys.stdin.isatty():
stdin_data = []
for line in sys.stdin:
stdin_data.append(line)
data.update(process_entries(stdin_data))
if paths:
for path in paths:
data.update(process_entries(read_file(path)))
else:
# Need to check if interactive to avoid blocking if nothing is piped
if not sys.stdin.isatty():
stdin_data = []
for line in sys.stdin:
stdin_data.append(line)
data.update(process_entries(stdin_data))
return output_requirements(data)

View File

@@ -48,7 +48,7 @@ def certbot_normal_processing(tools_path, test_constraints):
with open(certbot_requirements, 'r') as fd:
data = fd.readlines()
with open(test_constraints, 'w') as fd:
data = os.linesep.join(strip_hashes.process_entries(data))
data = "\n".join(strip_hashes.process_entries(data))
fd.write(data)

View File

@@ -2,7 +2,6 @@
"""Removes hash information from requirement files passed to it as file path
arguments or simply piped to stdin."""
import os
import re
import sys
@@ -24,22 +23,28 @@ def process_entries(entries):
return out_lines
def main(*paths):
"""Reads dependency definitions from a (list of) file(s) or stdin and
removes hashes from returned entries"""
"""
Reads dependency definitions from a (list of) file(s) provided on the
command line. If no command line arguments are present, data is read from
stdin instead.
Hashes are removed from returned entries.
"""
deps = []
for path in paths:
with open(path) as file_h:
deps += process_entries(file_h.readlines())
if paths:
for path in paths:
with open(path) as file_h:
deps += process_entries(file_h.readlines())
else:
# Need to check if interactive to avoid blocking if nothing is piped
if not sys.stdin.isatty():
stdin_data = []
for line in sys.stdin:
stdin_data.append(line)
deps += process_entries(stdin_data)
# Need to check if interactive to avoid blocking if nothing is piped
if not sys.stdin.isatty():
stdin_data = []
for line in sys.stdin:
stdin_data.append(line)
deps += process_entries(stdin_data)
return os.linesep.join(deps)
return "\n".join(deps)
if __name__ == '__main__':
print(main(*sys.argv[1:])) # pylint: disable=star-args