Changeset - 385f5a20da20
[Not reviewed]
0 3 0
Brett Smith - 4 years ago 2020-08-10 15:36:51
brettcsmith@brettcsmith.org
extract_odf_links: Don't print document-internal links.
3 files changed with 6 insertions and 4 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/tools/extract_odf_links.py
Show inline comments
...
 
@@ -81,26 +81,28 @@ supported in Python like \\n, \\t, \\0, \\u, etc. Default `%(default)s`.
 
        help="""ODF file(s) to extract links from. Note that %(prog)s cannot
 
read from stdin because it needs to know document paths to resolve links.
 
""")
 
    return parser.parse_args(arglist)
 

	
 
def extract_links(odf_path: Path) -> Iterator[Path]:
 
    odf_root = odf_path.parent.resolve()
 
    with odf_path.open('rb') as odf_file:
 
        odf_doc = odf.opendocument.load(odf_file)
 
    for a_elem in odf_doc.getElementsByType(odf.text.A):
 
        parts = urllib.parse.urlparse(a_elem.getAttribute('href') or '')
 
        if (parts.scheme and parts.scheme != 'file') or not parts.path:
 
            continue
 
        path = Path(urllib.parse.unquote(parts.path))
 
        if not path.is_absolute():
 
            path = (odf_path / path).resolve()
 
            try:
 
                path.relative_to(odf_root)
 
                path.relative_to(odf_path)
 
            except ValueError:
 
                logger.warning(f"link {path} is neither absolute nor relative to {odf_path}")
 
                pass
 
            else:
 
                # Link points to another document inside the ODF. Skip it.
 
                continue
 
        yield path
 

	
 
def main(arglist: Optional[Sequence[str]]=None,
 
         stdout: TextIO=sys.stdout,
 
         stderr: TextIO=sys.stderr,
 
) -> int:
setup.py
Show inline comments
...
 
@@ -2,13 +2,13 @@
 

	
 
from setuptools import setup
 

	
 
setup(
 
    name='conservancy_beancount',
 
    description="Plugin, library, and reports for reading Conservancy's books",
 
    version='1.7.0',
 
    version='1.7.1',
 
    author='Software Freedom Conservancy',
 
    author_email='info@sfconservancy.org',
 
    license='GNU AGPLv3+',
 

	
 
    install_requires=[
 
        'babel>=2.6',  # Debian:python3-babel
tests/repository/LinksReport.ods
Show inline comments
 
binary diff not shown
0 comments (0 inline, 0 general)