From 3ec9989f258616fa5523d13c01b6e4dddd8da29b Mon Sep 17 00:00:00 2001 From: Eric Torres Date: Wed, 6 Mar 2019 23:34:48 -0800 Subject: [PATCH] Use black linting utility on all python scripts --- ddusb.py | 21 +++++++------ dlaudio.py | 34 ++++++++++----------- drivetemp.py | 18 ++++++----- fedit.py | 85 ++++++++++++++++++++++++++------------------------- getweather.py | 4 +-- 5 files changed, 84 insertions(+), 78 deletions(-) diff --git a/ddusb.py b/ddusb.py index 66c01fb..b97e870 100644 --- a/ddusb.py +++ b/ddusb.py @@ -7,10 +7,7 @@ import subprocess # ========== Main Script ========== parser = argparse.ArgumentParser() -parser.add_argument("-b", "--bs", - default=512, - help="block size", - metavar="bs") +parser.add_argument("-b", "--bs", default=512, help="block size", metavar="bs") parser.add_argument("input_file", help="input file to write") parser.add_argument("output_file", help="output block device") args = parser.parse_args() @@ -28,11 +25,17 @@ print(f"Block device: {block_device}") print(f"Block size: {block_size}") try: - subprocess.run(["dd", f"if={input_file}", - f"of={block_device}", - f"bs={block_size}", - "status=progress"], check=True) + subprocess.run( + [ + "dd", + f"if={input_file}", + f"of={block_device}", + f"bs={block_size}", + "status=progress", + ], + check=True, + ) except subprocess.CalledProcessError: exit(1) else: - subprocess.run(['sync']) + subprocess.run(["sync"]) diff --git a/dlaudio.py b/dlaudio.py index 00a2568..a15f659 100644 --- a/dlaudio.py +++ b/dlaudio.py @@ -12,7 +12,7 @@ import shutil import subprocess # =========== Constants ========== -YOUTUBE_DL_BIN = shutil.which('youtube-dl') +YOUTUBE_DL_BIN = shutil.which("youtube-dl") DEFAULT_FILENAME = f"{pathlib.Path.home()}/Music/%(title)s.%(ext)s" # ========== Error Codes ========== @@ -20,25 +20,23 @@ E_NOURLS = 2 # ========== Main Script ========== parser = argparse.ArgumentParser() -parser.add_argument('-b', '--batchfile', - help='provide the links from a text file') -parser.add_argument('-f', '--format', - type=str, - default='opus', - help='the format to use') -parser.add_argument('-n', '--filename', - type=str, - help='downloaded filename (without extension)') -parser.add_argument('urls', - nargs='*', - help='video URLs') +parser.add_argument("-b", "--batchfile", help="provide the links from a text file") +parser.add_argument( + "-f", "--format", type=str, default="opus", help="the format to use" +) +parser.add_argument( + "-n", "--filename", type=str, help="downloaded filename (without extension)" +) +parser.add_argument("urls", nargs="*", help="video URLs") args = parser.parse_args() -dl_opts = [YOUTUBE_DL_BIN, - '--no-part', - '--no-continue', - '--extract-audio', - f"--audio-format={args.format}"] +dl_opts = [ + YOUTUBE_DL_BIN, + "--no-part", + "--no-continue", + "--extract-audio", + f"--audio-format={args.format}", +] # filename handling # if -b is used, DEFAULT_FILENAME must take precedence diff --git a/drivetemp.py b/drivetemp.py index 6105fa7..6080bed 100644 --- a/drivetemp.py +++ b/drivetemp.py @@ -14,7 +14,7 @@ import pathlib import subprocess # ========== Constants ========== -DUMP_CMD = ['skdump', '--temperature'] +DUMP_CMD = ["skdump", "--temperature"] # ========== Functions ========== @@ -35,9 +35,9 @@ def retrieve_smart_temp(device_node): :returns: output of skdump in mKelvin :rtype: float """ - temp = subprocess.run(DUMP_CMD + [device_node], - capture_output=True, - text=True).stdout + temp = subprocess.run( + DUMP_CMD + [device_node], capture_output=True, text=True + ).stdout return float(temp) @@ -48,13 +48,17 @@ def convert_to_celsius(mkel_temp): :returns: temperature converted into degrees celsius :rtype: str """ - return (mkel_temp/1000) - 273.15 + return (mkel_temp / 1000) - 273.15 # ========== Main Script ========== parser = argparse.ArgumentParser() -parser.add_argument('device', help='device node to retrieve\ - the temperature for', metavar='dev') +parser.add_argument( + "device", + help="device node to retrieve\ + the temperature for", + metavar="dev", +) args = parser.parse_args() dev = args.device diff --git a/fedit.py b/fedit.py index c87400e..27c52e0 100644 --- a/fedit.py +++ b/fedit.py @@ -15,22 +15,22 @@ import subprocess # ========== Constants ========== # Paths -BOOT_DIR = '/boot' -ETC_DIR = '/etc' +BOOT_DIR = "/boot" +ETC_DIR = "/etc" # Exit Codes E_NOEDITORFOUND = 2 E_NOFILESELECTED = 3 # Commands -FIND_CMD = '/usr/bin/fd' -FIND_OPTS = ['--hidden', '--print0', '--type', 'f', '--no-ignore-vcs'] -FZF_CMD = '/usr/bin/fzf' -FZF_OPTS = ['--read0', '--select-1', '--exit-0', '--print0'] -LOCATE_CMD = '/usr/bin/locate' -LOCATE_OPTS = ['--all', '--ignore-case', '--null'] +FIND_CMD = "/usr/bin/fd" +FIND_OPTS = ["--hidden", "--print0", "--type", "f", "--no-ignore-vcs"] +FZF_CMD = "/usr/bin/fzf" +FZF_OPTS = ["--read0", "--select-1", "--exit-0", "--print0"] +LOCATE_CMD = "/usr/bin/locate" +LOCATE_OPTS = ["--all", "--ignore-case", "--null"] -LOCALE = 'utf-8' +LOCALE = "utf-8" # ========== Functions ========== @@ -54,13 +54,13 @@ def select_editor(editor_override=None): if editor_override is not None: editor = shutil.which(editor_override) - elif 'EDITOR' in os.environ: - editor = shutil.which(os.environ.get('EDITOR')) - elif shutil.which('vim') is not None: - editor = shutil.which('vim') + elif "EDITOR" in os.environ: + editor = shutil.which(os.environ.get("EDITOR")) + elif shutil.which("vim") is not None: + editor = shutil.which("vim") if editor is None: - raise FileNotFoundError('An editor could not be resolved') + raise FileNotFoundError("An editor could not be resolved") return editor @@ -78,7 +78,7 @@ def gen_editor_cmd(filename): if os.access(filename, os.W_OK): return [editor, filename] else: - return ['sudo', '--edit', filename] + return ["sudo", "--edit", filename] def run_fzf(files): @@ -89,11 +89,11 @@ def run_fzf(files): :returns: selected file :rtype: str """ - selected_file = subprocess.run([FZF_CMD] + FZF_OPTS, - input=files, - stdout=subprocess.PIPE).stdout + selected_file = subprocess.run( + [FZF_CMD] + FZF_OPTS, input=files, stdout=subprocess.PIPE + ).stdout - return selected_file.decode(LOCALE).strip('\x00') + return selected_file.decode(LOCALE).strip("\x00") def find_files(directory=None): @@ -106,7 +106,7 @@ def find_files(directory=None): """ cmd = [FIND_CMD] + FIND_OPTS if directory is not None: - cmd.extend(['--', '.', directory]) + cmd.extend(["--", ".", directory]) return subprocess.run(cmd, capture_output=True).stdout @@ -127,31 +127,32 @@ def locate_files(patterns): # ========== Main Script ========== parser = argparse.ArgumentParser() -parser.add_argument('-b', '--boot', - action='store_const', - const=BOOT_DIR, - dest='dir', - help='edit a file in /boot') -parser.add_argument('-d', '--dir', - dest='dir', - type=str, - help='edit a file in a given directory') -parser.add_argument('-E', '--etc', - action='store_const', - const=ETC_DIR, - dest='dir', - help='edit a file in /etc') -parser.add_argument('-e', '--editor', - help='use a given editor') -parser.add_argument('patterns', - type=str, - nargs='*', - help='patterns to pass to locate') +parser.add_argument( + "-b", + "--boot", + action="store_const", + const=BOOT_DIR, + dest="dir", + help="edit a file in /boot", +) +parser.add_argument( + "-d", "--dir", dest="dir", type=str, help="edit a file in a given directory" +) +parser.add_argument( + "-E", + "--etc", + action="store_const", + const=ETC_DIR, + dest="dir", + help="edit a file in /etc", +) +parser.add_argument("-e", "--editor", help="use a given editor") +parser.add_argument("patterns", type=str, nargs="*", help="patterns to pass to locate") args = parser.parse_args() final_find_cmd = [FIND_CMD] + FIND_OPTS -editor = '' +editor = "" try: editor = select_editor(args.editor) @@ -168,7 +169,7 @@ else: selected_file = run_fzf(files) -if not selected_file == '': +if not selected_file == "": cmd = gen_editor_cmd(selected_file) subprocess.run(cmd) else: diff --git a/getweather.py b/getweather.py index db6a978..8d2c0e1 100644 --- a/getweather.py +++ b/getweather.py @@ -5,11 +5,11 @@ import argparse import requests # ========== Constants ========== -WTTR_URI = 'http://wttr.in' +WTTR_URI = "http://wttr.in" # ========== Main Script ========== parser = argparse.ArgumentParser() -parser.add_argument('location') +parser.add_argument("location") args = parser.parse_args() location = args.location