From 48b9dee6d62cbda587e82bfbd7ed76529e4bcafc Mon Sep 17 00:00:00 2001 From: Rory Hinnen Date: Fri, 10 Jul 2026 20:45:28 -0500 Subject: [PATCH] refactored into a more appropriate structure --- .gitignore | 2 + src/epubmaker.py | 6 +- src/epubmaker/__main__.py | 604 +------------------------------------- src/epubmaker/app.py | 604 -------------------------------------- src/epubmaker/cli.py | 50 ++++ src/epubmaker/models.py | 49 ++++ src/epubmaker/parser.py | 174 +++++++++++ src/epubmaker/state.py | 4 + src/epubmaker/writer.py | 312 ++++++++++++++++++++ 9 files changed, 597 insertions(+), 1208 deletions(-) create mode 100644 .gitignore delete mode 100755 src/epubmaker/app.py create mode 100644 src/epubmaker/cli.py create mode 100644 src/epubmaker/models.py create mode 100644 src/epubmaker/parser.py create mode 100644 src/epubmaker/state.py create mode 100644 src/epubmaker/writer.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea11afd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.DS_Store +*__pycache__/ diff --git a/src/epubmaker.py b/src/epubmaker.py index 5db4304..e55ef2a 100755 --- a/src/epubmaker.py +++ b/src/epubmaker.py @@ -1,4 +1,6 @@ #!/usr/bin/env python3 -from epubmaker.__main__ import main -main() +from epubmaker.cli import main + +if __name__ == "__main__": + main() diff --git a/src/epubmaker/__main__.py b/src/epubmaker/__main__.py index 31c0da6..4e28416 100644 --- a/src/epubmaker/__main__.py +++ b/src/epubmaker/__main__.py @@ -1,603 +1,3 @@ -import sys, os, argparse -from uuid import uuid4 -from shutil import rmtree, copy -from datetime import datetime -import subprocess +from .cli import main - -class Name: - def __init__(self): - self.first = "" - self.last = "" - - -class Series: - def __init__(self): - self.number = "" - self.name = "" - - -class Image: - def __init__(self): - self.name = "" - self.type = "" - self.alt = "" - self.caption = "" - - -class Section: - def __init__(self): - self.type = "" - # types: - # cover - # toc - # copyright-page - # dedication - # text - # foreward - # notes - # acknowledments - # style - # title - self.name = "" - self.title = "" - self.body = "" - - -class Book: - def __init__(self): - self.filename = "" - self.title = "" - self.titlesort = "" - self.series = Series() - self.author = [] - self.artist = Name() - self.editor = Name() - self.publisher = "" - self.copyright = "" - self.subjects = "" - self.style = "" - self.directory = "" - self.isbn = "" - self.uuid = "" - self.source = "" - self.images = [] - self.sections = [] - self.cover = Image() - self.publishDate = "" - - -def extract(line): - if line.startswith("\n' - else: - imageCode = '
\n' - imageCode += ' ' + image.alt + '\n' - imageCode += ' \n' - imageCode += '

' + image.caption + '

\n' - imageCode += '
\n
\n' - book.sections[-1].body += imageCode - case _: - pass - - -def findStyle(line): - global book - stylesheetFile = line.split(' ')[2].split('=')[1].replace('"','').replace('>','').strip() - contents = "" - with open(stylesheetFile) as file: - for line in file: - if line != '' and not line.strip().startswith("/*"): - contents += line - book.style = contents - print("found style") - - - -def parseBook(): - global book, inSection - filename = book.filename - if verbose: - print("Parsing {}".format(filename)) - with open(filename) as source: - for line in source: - if line.startswith('\n' - else: - imageCode = '
\n' - imageCode += ' ' + image.alt + '\n' - imageCode += ' \n' - imageCode += '

' + image.caption + '

\n' - imageCode += '
\n
\n' - book.sections[-1].body += imageCode - case _: - pass - - -def findStyle(line): - global book - stylesheetFile = line.split(' ')[2].split('=')[1].replace('"','').replace('>','').strip() - contents = "" - with open(stylesheetFile) as file: - for line in file: - if line != '' and not line.strip().startswith("/*"): - contents += line - book.style = contents - print("found style") - - - -def parseBook(): - global book, inSection - filename = book.filename - if verbose: - print("Parsing {}".format(filename)) - with open(filename) as source: - for line in source: - if line.startswith('\n' + else: + imageCode = '
\n' + imageCode += ' ' + image.alt + '\n' + imageCode += ' \n' + imageCode += '

' + image.caption + '

\n' + imageCode += '
\n
\n' + state.book.sections[-1].body += imageCode + case _: + pass + + +def findStyle(line): + stylesheetFile = line.split(' ')[2].split('=')[1].replace('"', '').replace('>', '').strip() + contents = "" + with open(stylesheetFile) as file: + for line in file: + if line != '' and not line.strip().startswith("/*"): + contents += line + state.book.style = contents + print("found style") + + +def parseBook(): + filename = state.book.filename + if state.verbose: + print("Parsing {}".format(filename)) + with open(filename) as source: + for line in source: + if line.startswith('