summaryrefslogtreecommitdiff
path: root/subplot/jt.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-04-02 08:53:21 +0300
committerLars Wirzenius <liw@liw.fi>2021-04-02 11:56:56 +0300
commit743d3c65cc69deb9fc4429190288dc8846bcd250 (patch)
tree7a643a7f530cef6b222d3d39a725d64970e4e65a /subplot/jt.py
parent5aee9bd2ae4eb9c09e27c002f80d3edf071ebdcb (diff)
downloadjt2-743d3c65cc69deb9fc4429190288dc8846bcd250.tar.gz
feat! support multiple drafts
This changes the command line syntax: subcommands edit and finish now require the draft id. We can change this later so that if there is only one draft, the program picks that one automatically. Also, new entries are 0.md, 1.md, etc, which is not going to be acceptable for real use, but this works minimally.
Diffstat (limited to 'subplot/jt.py')
-rw-r--r--subplot/jt.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/subplot/jt.py b/subplot/jt.py
index 31bceb7..312a22a 100644
--- a/subplot/jt.py
+++ b/subplot/jt.py
@@ -65,17 +65,22 @@ def output_contains(ctx, pattern=None):
def journal_has_no_drafts(ctx, dirname=None):
- assert_eq = globals()["assert_eq"]
- logging.debug(f"checking {dirname} has no drafts")
- drafts = os.path.join(dirname, "drafts")
- assert_eq(_find_files(drafts), [])
+ _journal_has_n_drafts(ctx, 0, dirname=dirname)
def journal_has_one_draft(ctx, dirname=None):
+ _journal_has_n_drafts(ctx, 1, dirname=dirname)
+
+
+def journal_has_two_drafts(ctx, dirname=None):
+ _journal_has_n_drafts(ctx, 2, dirname=dirname)
+
+
+def _journal_has_n_drafts(ctx, n, dirname=None):
assert_eq = globals()["assert_eq"]
- logging.debug(f"checking {dirname} has one draft")
+ logging.debug(f"checking {dirname} has {n} drafts")
drafts = os.path.join(dirname, "drafts")
- assert_eq(len(_find_files(drafts)), 1)
+ assert_eq(len(_find_files(drafts)), n)
def journal_has_no_entries(ctx, dirname=None):
@@ -98,6 +103,18 @@ def journal_has_one_entry(ctx, dirname=None, variable=None):
ctx["variables"] = variables
+def journal_has_two_entries(ctx, dirname=None, variable1=None, variable2=None):
+ assert_eq = globals()["assert_eq"]
+ logging.debug(f"checking {dirname} has two entries")
+ entries = os.path.join(dirname, "entries")
+ files = list(sorted(_find_files(entries)))
+ assert_eq(len(files), 2)
+ variables = ctx.get("variables", {})
+ variables[variable1] = files[0]
+ variables[variable2] = files[1]
+ ctx["variables"] = variables
+
+
def _find_files(root):
if not os.path.exists(root):
return []