From 4feaf8fd54cd4927b8c6e24772cd8e310a90949a Mon Sep 17 00:00:00 2001 From: Colm O'Connor Date: Fri, 3 Nov 2023 22:47:39 +0000 Subject: [PATCH] FEATURE : Started using orgmunge instead of orgparse. --- hitch/story/errors.story | 2 +- hitch/story/latex-letter.story | 8 ++------ hitch/story/script.story | 11 +++++------ orji/cat.py | 8 +++++++- orji/note.py | 22 +++++++++++++--------- orji/run.py | 11 +++++++++-- pyproject.toml | 1 + 7 files changed, 38 insertions(+), 25 deletions(-) diff --git a/hitch/story/errors.story b/hitch/story/errors.story index 7249001..2910174 100644 --- a/hitch/story/errors.story +++ b/hitch/story/errors.story @@ -10,7 +10,7 @@ At nonexistent node: cmd: cat example.org example.jinja2 error: yes output: | - Failure on line 1 of example.jinja2: No notes found in with name nonexistent + Failure on line 1 of example.jinja2: No notes found in ROOT with name nonexistent Template syntax error: given: diff --git a/hitch/story/latex-letter.story b/hitch/story/latex-letter.story index e95b052..a4279cf 100644 --- a/hitch/story/latex-letter.story +++ b/hitch/story/latex-letter.story @@ -217,12 +217,10 @@ Example of Generated LaTeX A4 Letter: } % Your name for the signature at the bottom \address{ - \\ 1234 NW Bobcat Lane,\\ Bobcat City,\\ MO\\ - 65584-5678.\\ - \\ + 65584-5678. \\ +1-541-754-3010 \\ johndoe@gmail.com } % Your address and phone number @@ -236,11 +234,9 @@ Example of Generated LaTeX A4 Letter: %---------------------------------------------------------------------------------------- \begin{letter}{ - \\ 123 Elf Road,\\ North Pole,\\ - 88888\\ - + 88888 } % Name/title of the addressee %---------------------------------------------------------------------------------------- diff --git a/hitch/story/script.story b/hitch/story/script.story index 07cd2b4..9f2a66e 100644 --- a/hitch/story/script.story +++ b/hitch/story/script.story @@ -30,15 +30,16 @@ Run templated script to send email: orun/email.sh: | echo {{ note.at("body").body.oneline }} cat {{ note.at("email").body.tempfile() }} - cat {{ tmp / "tempfile.tmp" }} - cat {{ out / "outfile.out" }} + + echo {{ tmp }} + echo {{ out }} steps: - orji: cmd: run org orun output: | Windows sucks. - - billg@microsoft.com + billg@microsoft.com/gen/working/11111.tmp + /gen/working @@ -58,10 +59,8 @@ Run templated failing script: error: yes output: | Windows sucks. - billg@microsoft.com - ERROR running email.sh in /gen/working/11111.tmp diff --git a/orji/cat.py b/orji/cat.py index 958f1ce..63b90e9 100644 --- a/orji/cat.py +++ b/orji/cat.py @@ -5,6 +5,7 @@ from .template import Template from .utils import random_5_digit_number import shutil +import orgmunge @click.command() @@ -33,8 +34,13 @@ def cat(orgfile, jinjafile, indexlookup, latexmode, pymodule): temp_dir = Path(".") working_dir = temp_dir / f"{random_5_digit_number()}.tmp" working_dir.mkdir() + munge_parsed = orgmunge.Org( + org_text, + from_file=False, + todos={"todo_states": {"todo": "TODO"}, "done_states": {"done": "DONE"}}, + ) parsed = loads(org_text) - notes = Note(parsed, working_dir=working_dir) + notes = Note(munge_parsed.root, working_dir=working_dir) if indexlookup is not None: notes = notes.from_indexlookup(indexlookup) diff --git a/orji/note.py b/orji/note.py index cfab579..0740100 100644 --- a/orji/note.py +++ b/orji/note.py @@ -10,7 +10,7 @@ class OrjiError(Exception): class TextChunk: def __init__(self, text): - self.text = text + self.text = str(text) if text is not None else "" @property def markdown(self): @@ -44,7 +44,8 @@ def __str__(self): class Body(TextChunk): def __init__(self, text, working_dir): - self.text = text + # import web_pdb; web_pdb.set_trace() + self.text = str(text) if text is not None else "" self._working_dir = working_dir @property @@ -55,6 +56,7 @@ def oneline(self): raise OrjiError(f"{self.text} is not one line") def tempfile(self): + # import web_pdb;web_pdb.set_trace() filepath = Path(f"{self._working_dir}/{random_5_digit_number()}.txt") filepath.write_text(self.text) return filepath.absolute() @@ -73,16 +75,17 @@ def __init__(self, node, working_dir): @property def name(self): - return self._node.heading + return self._node.headline.title @property def indexlookup(self): indices = [] node = self._node while True: + # import web_pdb; web_pdb.set_trace() index = [i for i, n in enumerate(node.parent.children) if n == node][0] indices.append(str(index)) - if node.parent.is_root(): + if node.parent.parent is None: break else: node = node.parent @@ -91,7 +94,7 @@ def indexlookup(self): @property def slug(self): - return slugify(self._node.heading) + return slugify(self._node.headline.title) @property def state(self): @@ -99,11 +102,12 @@ def state(self): @property def tags(self): - return sorted(self._node.tags) + unsorted = self._node.tags + return sorted(unsorted) if unsorted is not None else [] @property def body(self): - return Body(self._node.get_body(format="raw"), self._working_dir) + return Body(self._node.body, self._working_dir) @property def prop(self): @@ -119,7 +123,7 @@ def from_indexlookup(self, indexlookup): return Note(node, self._working_dir) def has(self, lookup): - matching_notes = [n for n in self._node.children if n.heading == lookup] + matching_notes = [n for n in self._node.children if n.headline.title == lookup] if len(matching_notes) == 0: return False elif len(matching_notes) > 1: @@ -130,7 +134,7 @@ def has(self, lookup): return True def at(self, lookup): - matching_notes = [n for n in self._node.children if n.heading == lookup] + matching_notes = [n for n in self._node.children if n.headline.title == lookup] if len(matching_notes) == 0: raise OrjiError(f"No notes found in {self.name} with name {lookup}") elif len(matching_notes) > 1: diff --git a/orji/run.py b/orji/run.py index 19cb29f..fc710f4 100644 --- a/orji/run.py +++ b/orji/run.py @@ -9,6 +9,7 @@ from .utils import random_5_digit_number import shutil from .template import Template +import orgmunge @click.command() @@ -50,14 +51,20 @@ def run(orgdir, rundir, tmp, out): script_run = False for orgfile in orgdir.glob("*.org"): - for note in Note(loads(Path(orgfile).read_text()), working_dir=working_dir): + parsed_munge = orgmunge.Org( + Path(orgfile).read_text(), + from_file=False, + todos={"todo_states": {"todo": "TODO"}, "done_states": {"done": "DONE"}}, + ) + + for note in Note(parsed_munge.root, working_dir=working_dir): if note.state == "TODO": for tag in note.tags: if tag in scripts.keys(): script_run = True notebody_path = working_dir.joinpath("notebody.txt") - notebody_path.write_text(note.body.text) + notebody_path.write_text(str(note.body)) tmp_script = working_dir.joinpath("{}.sh".format(tag)) rendered_script = Template(scripts[tag], f"{tag}.sh").render( diff --git a/pyproject.toml b/pyproject.toml index ab2820b..cf409ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,7 @@ classifiers = [ "Natural Language :: English", ] dependencies = [ + "git+https://github.com/durableOne/orgmunge.git@dev", "orgparse>=0.3.1", "jinja2>=3.1.2", "click>=8.1.3",