Skip to content

Commit

Permalink
cli and skip
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand committed Aug 11, 2024
1 parent 33818ee commit 9ab57ab
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
env:
MACOSX_DEPLOYMENT_TARGET: 10.15
CIBW_ARCHS_MACOS: auto universal2
CIBW_SKIP: "*-win32 *-manylinux_i686"
CIBW_SKIP: "*-win32 *-manylinux_i686 cp312-win_amd64 cp37-musllinux_x86_64"
CIBW_BUILD_VERBOSITY: 1
- name: Verify clean directory
run: git diff --exit-code
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@
"test": ["pytest>=6.0"],
},
conan_profile_settings={"compiler.cppstd": "20"},
entry_points = {
"console_scripts": ["pyodr=pyodr.cli:main"],
},
)
40 changes: 40 additions & 0 deletions src/pyodr/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import sys
import argparse
from pathlib import Path
from typing import Sequence
import tempfile
import webbrowser

import pyodr.core as core


def main(args: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser(description="OpenDocument Reader")
parser.add_argument("file", type=Path, help="The file to open")
args = parser.parse_args(args)

html_config = core.HtmlConfig()

print(f"Opening file: {str(args.file)}")
file = core.open(str(args.file))
if not file.is_valid():
print(f"Unable to open")
return 1
print(f"Type detected as {file.file_type()}")

tmp_dir = Path(tempfile.mkdtemp(prefix="pyodr-", suffix=".tmp"))
print(f"Translating html to {str(tmp_dir)}")
html = core.html.translate(file, str(tmp_dir), html_config)
print("Done")

for page in html.pages():
url = f"file://{str(page.path)}"
print(f"Opening {page.name} via {url}")
webbrowser.open(url)

return 0


if __name__ == '__main__':
error = main()
sys.exit(error)
1 change: 1 addition & 0 deletions src/pyodr/core.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <odr/document.hpp>
#include <odr/document_element.hpp>
Expand Down

0 comments on commit 9ab57ab

Please sign in to comment.