Skip to content

Commit

Permalink
WIP: refactor backup
Browse files Browse the repository at this point in the history
- Move functionality into the grexd module.
- Create the hugefileviewer infra that uses mmap and only reads the
  portion of the file that is on the screen.
- works

tmp
  • Loading branch information
lpenz committed Mar 31, 2024
1 parent 9c7e694 commit 560096d
Show file tree
Hide file tree
Showing 8 changed files with 642 additions and 134 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ build-backend = "setuptools.build_meta"

[tool.mypy]
strict = true
files = "src, src/bin/grexd, tests"
scripts_are_modules = true
files = "src, src/bin/*, tests"
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ package_dir =
grexd = src/grexd
packages = find:
scripts =
src/bin/grexd
src/bin/grexd-regexbuild
src/bin/grexd-hugefileviewer
python_requires = >=3.9
install_requires = file:requirements.txt

Expand Down
132 changes: 0 additions & 132 deletions src/bin/grexd

This file was deleted.

64 changes: 64 additions & 0 deletions src/bin/grexd-hugefileviewer
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python3
"""
A visualizer for huge files
This is mostly a test for the hugefileviewer prompt-toolkit widget and
control.
"""

import argparse
import logging
import os

import grexd
from prompt_toolkit import Application
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.key_binding.key_processor import KeyPressEvent
from prompt_toolkit.layout.containers import Container, Window
from prompt_toolkit.layout.layout import Layout
from prompt_toolkit.widgets import Frame

E = KeyPressEvent


class HugeFileViewerWidget:
def __init__(self, filename: os.PathLike[str]):
self.filename = filename
with open(self.filename, "rb") as fd:
self.control = grexd.HugeFileViewerUIControl(fd=fd)
self.window = Window(self.control)

def __pt_container__(self) -> Container:
return self.window


def hugefileviewer_run(filename: os.PathLike[str]) -> None:
hugefileviewer = HugeFileViewerWidget(filename)
root_container = Frame(title=str(filename), body=hugefileviewer)
layout = Layout(root_container)
kb = KeyBindings()
app: Application[None] = Application(
layout=layout,
full_screen=True,
key_bindings=kb,
mouse_support=True,
)
kb.add("c-c")(lambda e: app.exit())
kb.add("c-d")(lambda e: app.exit())
kb.add("escape", "q")(lambda e: app.exit())
app.run()


def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--version", "-V", action="version", version="%(prog)s " + grexd.version()
)
parser.add_argument("file", type=str, nargs=1, help="File to view")
args = parser.parse_args()
logging.basicConfig(filename="log.txt", level=logging.INFO)
hugefileviewer_run(args.file[0])


if __name__ == "__main__":
main()
Loading

0 comments on commit 560096d

Please sign in to comment.