summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-20 14:12:32 +0000
committerLars Wirzenius <liw@liw.fi>2021-03-20 14:12:32 +0000
commit1efa96bcf2ac4de6b978c13ff265fc0c11662b43 (patch)
tree1ef53e2a930bf27e5321ad41be1870d630030cce
parent2a44947d1581b80b1ba3dda87f35d727b9b39af5 (diff)
parentee43b9db3375b4a528cd4b1609340c472a2cfd13 (diff)
downloadewww-1efa96bcf2ac4de6b978c13ff265fc0c11662b43.tar.gz
Merge branch 'chore' into 'main'
fix: add missing filename keyword argument to stop_server See merge request larswirzenius/ewww!17
-rw-r--r--subplot/ewww.py2
-rw-r--r--subplot/vendored/daemon.py12
-rw-r--r--subplot/vendored/files.py36
-rw-r--r--subplot/vendored/files.yaml21
4 files changed, 67 insertions, 4 deletions
diff --git a/subplot/ewww.py b/subplot/ewww.py
index f1e02e3..e30c219 100644
--- a/subplot/ewww.py
+++ b/subplot/ewww.py
@@ -76,7 +76,7 @@ def start_server(ctx, filename=None):
# Stop previously started server.
-def stop_server(ctx):
+def stop_server(ctx, filename=None):
daemon_stop = globals()["daemon_stop"]
logging.debug("Stopping ewww")
daemon_stop(ctx, name="ewww")
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