forked from kenkeiras/org-rw
Rename to org-rw.
This commit is contained in:
parent
83710a4fc1
commit
bb24f9495e
@ -9,4 +9,4 @@ cd "`dirname $0`"
|
|||||||
git submodule update --init --recursive .
|
git submodule update --init --recursive .
|
||||||
|
|
||||||
# Run all checks
|
# Run all checks
|
||||||
python3 org_dom_check.py .
|
python3 org_rw_check.py .
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import org_dom
|
import org_rw
|
||||||
|
|
||||||
top = sys.argv[1]
|
top = sys.argv[1]
|
||||||
count = 0
|
count = 0
|
||||||
@ -16,7 +16,7 @@ for root, dirs, files in os.walk(top):
|
|||||||
path = os.path.join(root, name)
|
path = os.path.join(root, name)
|
||||||
count += 1
|
count += 1
|
||||||
try:
|
try:
|
||||||
org_dom.load(open(path), extra_cautious=True)
|
org_rw.load(open(path), extra_cautious=True)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
import traceback
|
import traceback
|
||||||
|
|
@ -1,2 +0,0 @@
|
|||||||
from .org_dom import *
|
|
||||||
from .utils import *
|
|
2
org_rw/__init__.py
Normal file
2
org_rw/__init__.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
from .org_rw import *
|
||||||
|
from .utils import *
|
@ -818,7 +818,7 @@ def parse_headline(hl) -> Headline:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class OrgDom:
|
class OrgDoc:
|
||||||
def __init__(self, headlines, keywords, contents):
|
def __init__(self, headlines, keywords, contents):
|
||||||
self.headlines: List[Headline] = list(map(parse_headline, headlines))
|
self.headlines: List[Headline] = list(map(parse_headline, headlines))
|
||||||
self.keywords: List[Property] = keywords
|
self.keywords: List[Property] = keywords
|
||||||
@ -976,16 +976,16 @@ class OrgDom:
|
|||||||
yield from self.dump_headline(headline)
|
yield from self.dump_headline(headline)
|
||||||
|
|
||||||
|
|
||||||
class OrgDomReader:
|
class OrgDocReader:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.headlines: List[Headline] = []
|
self.headlines: List[Headline] = []
|
||||||
self.keywords: List[Property] = []
|
self.keywords: List[Property] = []
|
||||||
self.headline_hierarchy: List[OrgDom] = []
|
self.headline_hierarchy: List[OrgDoc] = []
|
||||||
self.contents: List[RawLine] = []
|
self.contents: List[RawLine] = []
|
||||||
self.delimiters: List[DelimiterLine] = []
|
self.delimiters: List[DelimiterLine] = []
|
||||||
|
|
||||||
def finalize(self):
|
def finalize(self):
|
||||||
return OrgDom(self.headlines, self.keywords, self.contents)
|
return OrgDoc(self.headlines, self.keywords, self.contents)
|
||||||
|
|
||||||
## Construction
|
## Construction
|
||||||
def add_headline(self, linenum: int, match: re.Match) -> int:
|
def add_headline(self, linenum: int, match: re.Match) -> int:
|
||||||
@ -1131,11 +1131,11 @@ class OrgDomReader:
|
|||||||
|
|
||||||
|
|
||||||
def loads(s, environment=BASE_ENVIRONMENT, extra_cautious=True):
|
def loads(s, environment=BASE_ENVIRONMENT, extra_cautious=True):
|
||||||
doc = OrgDomReader()
|
reader = OrgDocReader()
|
||||||
doc.read(s, environment)
|
reader.read(s, environment)
|
||||||
dom = doc.finalize()
|
doc = reader.finalize()
|
||||||
if extra_cautious: # Check that all options can be properly re-serialized
|
if extra_cautious: # Check that all options can be properly re-serialized
|
||||||
after_dump = dumps(dom)
|
after_dump = dumps(doc)
|
||||||
if after_dump != s:
|
if after_dump != s:
|
||||||
diff = list(
|
diff = list(
|
||||||
difflib.Differ().compare(
|
difflib.Differ().compare(
|
||||||
@ -1147,7 +1147,7 @@ def loads(s, environment=BASE_ENVIRONMENT, extra_cautious=True):
|
|||||||
# print("---\n" + after_dump + "\n---")
|
# print("---\n" + after_dump + "\n---")
|
||||||
|
|
||||||
raise Exception("Difference found between existing version and dumped")
|
raise Exception("Difference found between existing version and dumped")
|
||||||
return dom
|
return doc
|
||||||
|
|
||||||
|
|
||||||
def load(f, environment=BASE_ENVIRONMENT, extra_cautious=False):
|
def load(f, environment=BASE_ENVIRONMENT, extra_cautious=False):
|
@ -1,5 +1,5 @@
|
|||||||
from .org_dom import (Bold, Code, Headline, Italic, Line, RawLine, Strike,
|
from .org_rw import (Bold, Code, Headline, Italic, Line, RawLine, Strike, Text,
|
||||||
Text, Underlined, Verbatim)
|
Underlined, Verbatim)
|
||||||
|
|
||||||
|
|
||||||
def get_hl_raw_contents(doc: Headline) -> str:
|
def get_hl_raw_contents(doc: Headline) -> str:
|
6
setup.py
6
setup.py
@ -1,13 +1,13 @@
|
|||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="org-dom",
|
name="org-rw",
|
||||||
version="0.0.1",
|
version="0.0.1",
|
||||||
description="Library to de/serialize org-files and manipulate them in a DOM-like manner.",
|
description="Library to de/serialize org-files and manipulate them.",
|
||||||
author="kenkeiras",
|
author="kenkeiras",
|
||||||
author_email="kenkeiras@codigoparallevar.com",
|
author_email="kenkeiras@codigoparallevar.com",
|
||||||
license="Apache License 2.0",
|
license="Apache License 2.0",
|
||||||
packages=["org_dom"],
|
packages=["org_rw"],
|
||||||
scripts=[],
|
scripts=[],
|
||||||
include_package_data=False,
|
include_package_data=False,
|
||||||
install_requires=[],
|
install_requires=[],
|
||||||
|
@ -3,10 +3,10 @@ import os
|
|||||||
import unittest
|
import unittest
|
||||||
from datetime import datetime as DT
|
from datetime import datetime as DT
|
||||||
|
|
||||||
from org_dom import dumps, load, loads
|
from org_rw import dumps, load, loads
|
||||||
|
|
||||||
from utils.dom_assertions import (BOLD, CODE, HL, ITALIC, SPAN, STRIKE,
|
from utils.assertions import (BOLD, CODE, HL, ITALIC, SPAN, STRIKE, UNDERLINED,
|
||||||
UNDERLINED, VERBATIM, WEB_LINK, Dom, Tokens)
|
VERBATIM, WEB_LINK, Doc, Tokens)
|
||||||
|
|
||||||
DIR = os.path.dirname(os.path.abspath(__file__))
|
DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ class TestSerde(unittest.TestCase):
|
|||||||
with open(os.path.join(DIR, "01-simple.org")) as f:
|
with open(os.path.join(DIR, "01-simple.org")) as f:
|
||||||
doc = load(f)
|
doc = load(f)
|
||||||
|
|
||||||
ex = Dom(
|
ex = Doc(
|
||||||
props=[
|
props=[
|
||||||
("TITLE", "01-Simple"),
|
("TITLE", "01-Simple"),
|
||||||
("DESCRIPTION", "Simple org file"),
|
("DESCRIPTION", "Simple org file"),
|
||||||
@ -70,7 +70,7 @@ class TestSerde(unittest.TestCase):
|
|||||||
with open(os.path.join(DIR, "02-markup.org")) as f:
|
with open(os.path.join(DIR, "02-markup.org")) as f:
|
||||||
doc = load(f)
|
doc = load(f)
|
||||||
|
|
||||||
ex = Dom(
|
ex = Doc(
|
||||||
props=[
|
props=[
|
||||||
("TITLE", "02-Markup"),
|
("TITLE", "02-Markup"),
|
||||||
("DESCRIPTION", "Simple org file to test markup"),
|
("DESCRIPTION", "Simple org file to test markup"),
|
||||||
@ -213,7 +213,7 @@ class TestSerde(unittest.TestCase):
|
|||||||
self.assertEqual(links[3].value, "id:03-markup-first-level-id")
|
self.assertEqual(links[3].value, "id:03-markup-first-level-id")
|
||||||
self.assertEqual(links[3].description, "a link to a section by id")
|
self.assertEqual(links[3].description, "a link to a section by id")
|
||||||
|
|
||||||
ex = Dom(
|
ex = Doc(
|
||||||
props=[
|
props=[
|
||||||
("TITLE", "03-Links"),
|
("TITLE", "03-Links"),
|
||||||
("DESCRIPTION", "Simple org file to test links"),
|
("DESCRIPTION", "Simple org file to test links"),
|
||||||
@ -293,7 +293,7 @@ class TestSerde(unittest.TestCase):
|
|||||||
links[3].value = "id:03-markup-non-existent-level-id"
|
links[3].value = "id:03-markup-non-existent-level-id"
|
||||||
links[3].description = None
|
links[3].description = None
|
||||||
|
|
||||||
ex = Dom(
|
ex = Doc(
|
||||||
props=[
|
props=[
|
||||||
("TITLE", "03-Links"),
|
("TITLE", "03-Links"),
|
||||||
("DESCRIPTION", "Simple org file to test links"),
|
("DESCRIPTION", "Simple org file to test links"),
|
@ -2,8 +2,8 @@ import collections
|
|||||||
import unittest
|
import unittest
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from org_dom import (Bold, Code, Italic, Line, Strike, Text, Underlined,
|
from org_rw import (Bold, Code, Italic, Line, Strike, Text, Underlined,
|
||||||
Verbatim, get_raw_contents)
|
Verbatim, get_raw_contents)
|
||||||
|
|
||||||
|
|
||||||
def timestamp_to_datetime(ts):
|
def timestamp_to_datetime(ts):
|
||||||
@ -19,7 +19,7 @@ def get_raw(doc):
|
|||||||
return doc.get_raw()
|
return doc.get_raw()
|
||||||
|
|
||||||
|
|
||||||
class Dom:
|
class Doc:
|
||||||
def __init__(self, *, props=None, children=None):
|
def __init__(self, *, props=None, children=None):
|
||||||
self.props = props
|
self.props = props
|
||||||
self.children = children
|
self.children = children
|
Loading…
Reference in New Issue
Block a user