Skip to content

Commit

Permalink
Clean up lint
Browse files Browse the repository at this point in the history
- Use `with` for file handles.
- Use `dict.items()` for command-line arguments.
- Disable the f-strings pylint linter. f-strings aren't supported in
  Python 2, and since we're still supporting Python 2, we can't use
  them.
  • Loading branch information
aag committed Jan 17, 2022
1 parent d330418 commit 746eee1
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions download_trailers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# We still support Python 2, so we can't use f-strings, even though pylint
# in recent versions of Python 3 wants us to.
# pylint: disable=consider-using-f-string

import argparse
import io
import json
Expand Down Expand Up @@ -161,19 +165,17 @@ def get_downloaded_files(dl_list_path):
"""Get the list of downloaded files from the text file"""
file_list = []
if os.path.exists(dl_list_path):
utf8_file = io.open(dl_list_path, mode='r', encoding='utf-8')
for line in utf8_file:
file_list.append(line.strip())
utf8_file.close()
with io.open(dl_list_path, mode='r', encoding='utf-8') as utf8_file:
for line in utf8_file:
file_list.append(line.strip())
return file_list


def write_downloaded_files(file_list, dl_list_path):
"""Write the list of downloaded files to the text file"""
new_list = [filename + u'\n' for filename in file_list]
downloads_file = io.open(dl_list_path, mode='w', encoding='utf-8')
downloads_file.writelines(new_list)
downloads_file.close()
with io.open(dl_list_path, mode='w', encoding='utf-8') as downloads_file:
downloads_file.writelines(new_list)


def record_downloaded_file(filename, dl_list_path):
Expand Down Expand Up @@ -518,9 +520,9 @@ def get_command_line_arguments():

# Remove all pairs that were not set on the command line.
set_args = {}
for name in args:
if args[name] is not None:
set_args[name] = args[name]
for name, arg_val in args.items():
if arg_val is not None:
set_args[name] = arg_val

return set_args

Expand Down

0 comments on commit 746eee1

Please sign in to comment.