Skip to content

Commit

Permalink
FEATURE : Started using orgmunge instead of orgparse.
Browse files Browse the repository at this point in the history
  • Loading branch information
crdoconnor committed Nov 3, 2023
1 parent be9019b commit 4feaf8f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion hitch/story/errors.story
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 2 additions & 6 deletions hitch/story/latex-letter.story
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -236,11 +234,9 @@ Example of Generated LaTeX A4 Letter:
%----------------------------------------------------------------------------------------

\begin{letter}{
\\
123 Elf Road,\\
North Pole,\\
88888\\

88888
} % Name/title of the addressee

%----------------------------------------------------------------------------------------
Expand Down
11 changes: 5 additions & 6 deletions hitch/story/script.story
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand All @@ -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


8 changes: 7 additions & 1 deletion orji/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .template import Template
from .utils import random_5_digit_number
import shutil
import orgmunge


@click.command()
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 13 additions & 9 deletions orji/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -91,19 +94,20 @@ def indexlookup(self):

@property
def slug(self):
return slugify(self._node.heading)
return slugify(self._node.headline.title)

@property
def state(self):
return self._node.todo

@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):
Expand All @@ -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:
Expand All @@ -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:
Expand Down
11 changes: 9 additions & 2 deletions orji/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .utils import random_5_digit_number
import shutil
from .template import Template
import orgmunge


@click.command()
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4feaf8f

Please sign in to comment.