From f60dcbc2ffea57f9730187279d5f2c7eabe724e1 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 20 Mar 2021 16:08:30 +0200 Subject: chore: update vendored Subplot libraries --- subplot/vendored/daemon.py | 12 +++++++++--- subplot/vendored/files.py | 36 ++++++++++++++++++++++++++++++++++++ subplot/vendored/files.yaml | 21 +++++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/subplot/vendored/daemon.py b/subplot/vendored/daemon.py index d436b4f..11f65bf 100644 --- a/subplot/vendored/daemon.py +++ b/subplot/vendored/daemon.py @@ -140,13 +140,17 @@ def daemon_wait_for_port(host, port, timeout=5.0): s.close() return except socket.timeout: - logging.error(f"daemon did not respond at port {port} within {timeout} seconds") + logging.error( + f"daemon did not respond at port {port} within {timeout} seconds" + ) raise except socket.error as e: logging.info(f"could not connect to daemon at {port}: {e}") pass if time.time() >= until: - logging.error(f"could not connect to daemon at {port} within {timeout} seconds") + logging.error( + f"could not connect to daemon at {port} within {timeout} seconds" + ) raise ConnectionRefusedError() # Sleep a bit to avoid consuming too much CPU while busy-waiting. time.sleep(0.1) @@ -198,7 +202,9 @@ def daemon_process_exists(ctx, args=None): def _daemon_pgrep(pattern): logging.info(f"checking if process exists: pattern={pattern}") - exit = subprocess.call(["pgrep", "-laf", pattern], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + exit = subprocess.call( + ["pgrep", "-laf", pattern], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL + ) logging.info(f"exit code: {exit}") return exit == 0 diff --git a/subplot/vendored/files.py b/subplot/vendored/files.py index ec37b9d..dd5b9f8 100644 --- a/subplot/vendored/files.py +++ b/subplot/vendored/files.py @@ -1,10 +1,12 @@ import logging import os import re +import shutil import time def files_create_from_embedded(ctx, filename=None): + files_make_directory(ctx, path=os.path.dirname(filename) or ".") files_create_from_embedded_with_other_name( ctx, filename_on_disk=filename, embedded_filename=filename ) @@ -14,15 +16,29 @@ def files_create_from_embedded_with_other_name( ctx, filename_on_disk=None, embedded_filename=None ): get_file = globals()["get_file"] + + files_make_directory(ctx, path=os.path.dirname(filename_on_disk) or ".") with open(filename_on_disk, "wb") as f: f.write(get_file(embedded_filename)) def files_create_from_text(ctx, filename=None, text=None): + files_make_directory(ctx, path=os.path.dirname(filename) or ".") with open(filename, "w") as f: f.write(text) +def files_make_directory(ctx, path=None): + path = "./" + path + if not os.path.exists(path): + os.makedirs(path) + + +def files_remove_directory(ctx, path=None): + path = "./" + path + shutil.rmtree(path) + + def files_file_exists(ctx, filename=None): assert_eq = globals()["assert_eq"] assert_eq(os.path.exists(filename), True) @@ -33,6 +49,26 @@ def files_file_does_not_exist(ctx, filename=None): assert_eq(os.path.exists(filename), False) +def files_directory_exists(ctx, path=None): + assert_eq = globals()["assert_eq"] + assert_eq(os.path.isdir(path), True) + + +def files_directory_does_not_exist(ctx, path=None): + assert_eq = globals()["assert_eq"] + assert_eq(os.path.isdir(path), False) + + +def files_directory_is_empty(ctx, path=None): + assert_eq = globals()["assert_eq"] + assert_eq(os.listdir(path), []) + + +def files_directory_is_not_empty(ctx, path=None): + assert_ne = globals()["assert_ne"] + assert_ne(os.listdir(path), False) + + def files_only_these_exist(ctx, filenames=None): assert_eq = globals()["assert_eq"] filenames = filenames.replace(",", "").split() diff --git a/subplot/vendored/files.yaml b/subplot/vendored/files.yaml index be69920..f18b8cd 100644 --- a/subplot/vendored/files.yaml +++ b/subplot/vendored/files.yaml @@ -60,3 +60,24 @@ - then: file {filename} has a very old modification time function: files_mtime_is_ancient + +- given: a directory {path} + function: files_make_directory + +- when: I create directory {path} + function: files_make_directory + +- when: I remove directory {path} + function: files_remove_directory + +- then: directory {path} exists + function: files_directory_exists + +- then: directory {path} does not exist + function: files_directory_does_not_exist + +- then: directory {path} is empty + function: files_directory_is_empty + +- then: directory {path} is not empty + function: files_directory_is_not_empty -- cgit v1.2.1