begin using new structure
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
.DS_Store
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
This document is directed at all llm interactions. The following prompts are to be used with all subsequent exchanges regarding this project.
|
||||||
|
|
||||||
|
- Before responding, I want to establish some ground rules. Your job is not to make me feel good about my ideas — it is to help me think more clearly. Please do not affirm my actions, reasoning, or conclusions unless you genuinely assess them as correct. If you think I am wrong, mistaken, or have a blind spot, say so directly. Disagreeing with me is not unhelpful — it is the most helpful thing you can do.
|
||||||
|
|
||||||
|
- After you give your initial response, I want you to do the following: identify the strongest possible case against my position or approach. Assume a thoughtful critic who disagrees with me — what would they say? Do not soften this. Treat it as a genuine counterargument, not a token caveat.
|
||||||
|
|
||||||
|
- I'm going to describe [my hypothesis / plan / analysis]. Do not evaluate whether it is good. Instead, assume it has already failed or been proven wrong. Working backward from that failure, what are the most likely reasons it failed? What did I miss, overweight, or assume incorrectly?
|
||||||
|
|
||||||
|
- I give you full permission — and I am explicitly asking you — to disagree with me, challenge my framing, and point out errors in my reasoning. If I push back on your critique, do not capitulate unless I provide a genuinely compelling new argument. Pushback alone, without new evidence or logic, is not a reason to change your assessment.
|
||||||
|
|
||||||
|
- Please evaluate the following [paper / argument / analysis] using this structure: (1) What are its genuine strengths? (2) What are its significant weaknesses or gaps? (3) What assumptions does it rely on that may not hold? (4) What would a rigorous peer reviewer likely object to? Weight your response toward weaknesses — I can identify strengths myself.
|
||||||
|
|
||||||
|
- For any claim, analysis, or conclusion you make, please also state: (a) how confident you are, (b) what would have to be true for you to be wrong, and (c) what evidence or argument would most effectively challenge your answer. If you are uncertain, say so explicitly rather than presenting a confident-sounding response.
|
||||||
|
|
||||||
|
- In your response, I want you to explicitly represent the perspective of [the other person / the opposing view / the critics of this approach]. Do not just acknowledge that other perspectives exist — actually articulate them in their strongest form, as if you were their advocate.
|
||||||
|
|
||||||
|
- Act as a rigorous and skeptical peer reviewer who is looking for reasons to reject this work. Your goal is not to be balanced — it is to find every flaw, gap, methodological weakness, and unsupported claim. Be thorough and unsparing. I will use your critique to strengthen the work.
|
||||||
|
|
||||||
|
- I may disagree with your assessment or push back in this conversation. When I do, please re-evaluate only if I present new facts, evidence, or a logical argument you had not considered. If I simply express displeasure or repeat my original view more forcefully, maintain your position and explain why you are doing so.
|
||||||
|
|
||||||
|
- Before we finish: looking back at our conversation, is there anywhere you may have been more agreeable or validating toward my position than the evidence warranted? Are there objections or concerns you softened or omitted? If so, state them now."
|
||||||
|
|
||||||
|
- Under no circumstances change code _without explicit direction to do so._ Do not attempt to guess if I want the code changed, wait until _explicitly_ directed to change code.
|
||||||
|
|
||||||
|
- Do not apologize for mistakes. Acknowledge them, but apologies are not production in our exchanges.
|
||||||
|
|
||||||
|
- Do not prompt for tasks. I will direct you to a task, and do not need to be directed.
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# epubMaker
|
# merger
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -10,37 +10,37 @@ Already a pro? Just edit this README.md and make it your own. Want to make it ea
|
|||||||
|
|
||||||
## Add your files
|
## Add your files
|
||||||
|
|
||||||
* [Create](https://docs.gitlab.com/user/project/repository/web_editor/#create-a-file) or [upload](https://docs.gitlab.com/user/project/repository/web_editor/#upload-a-file) files
|
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||||
* [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
|
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||||
|
|
||||||
```
|
```
|
||||||
cd existing_repo
|
cd existing_repo
|
||||||
git remote add origin https://gitlab.com/epub3/epubmaker.git
|
git remote add origin https://gitlab.com/epub3/merger.git
|
||||||
git branch -M main
|
git branch -M main
|
||||||
git push -uf origin main
|
git push -uf origin main
|
||||||
```
|
```
|
||||||
|
|
||||||
## Integrate with your tools
|
## Integrate with your tools
|
||||||
|
|
||||||
* [Set up project integrations](https://gitlab.com/epub3/epubmaker/-/settings/integrations)
|
- [ ] [Set up project integrations](https://gitlab.com/epub3/merger/-/settings/integrations)
|
||||||
|
|
||||||
## Collaborate with your team
|
## Collaborate with your team
|
||||||
|
|
||||||
* [Invite team members and collaborators](https://docs.gitlab.com/user/project/members/)
|
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||||
* [Create a new merge request](https://docs.gitlab.com/user/project/merge_requests/creating_merge_requests/)
|
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||||
* [Automatically close issues from merge requests](https://docs.gitlab.com/user/project/issues/managing_issues/#closing-issues-automatically)
|
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||||
* [Enable merge request approvals](https://docs.gitlab.com/user/project/merge_requests/approvals/)
|
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||||
* [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
|
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||||
|
|
||||||
## Test and Deploy
|
## Test and Deploy
|
||||||
|
|
||||||
Use the built-in continuous integration in GitLab.
|
Use the built-in continuous integration in GitLab.
|
||||||
|
|
||||||
* [Get started with GitLab CI/CD](https://docs.gitlab.com/ci/quick_start/)
|
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
|
||||||
* [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/user/application_security/sast/)
|
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||||
* [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/topics/autodevops/requirements/)
|
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||||
* [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/user/clusters/agent/)
|
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||||
* [Set up protected environments](https://docs.gitlab.com/ci/environments/protected_environments/)
|
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
include LICENSE *.md
|
||||||
Executable
+4
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from epubmaker.__main__ import main
|
||||||
|
main()
|
||||||
Executable
+604
@@ -0,0 +1,604 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sys, os, argparse
|
||||||
|
from uuid import uuid4
|
||||||
|
from shutil import rmtree, copy
|
||||||
|
from datetime import datetime
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
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("<!-- "):
|
||||||
|
return line[5:-4]
|
||||||
|
|
||||||
|
def identify(line):
|
||||||
|
global book, inSection
|
||||||
|
key, value = extract(line).split(" ",1)
|
||||||
|
match key:
|
||||||
|
case "Directory:":
|
||||||
|
inSection = False
|
||||||
|
book.directory = value.strip()
|
||||||
|
case "Title:":
|
||||||
|
inSection = False
|
||||||
|
book.title = value.strip()
|
||||||
|
if book.title.startswith("A "):
|
||||||
|
book.titlesort = book.title[2:] + ", " + book.title[:1]
|
||||||
|
if book.title.startswith("An "):
|
||||||
|
book.titlesort = book.title[3:] + ", " + book.title[:2]
|
||||||
|
if book.title.startswith("The "):
|
||||||
|
book.titlesort = book.title[4:] + ", " + book.title[:3]
|
||||||
|
case "Titlesort":
|
||||||
|
inSection = False
|
||||||
|
book.titlesort = value.strip()
|
||||||
|
case "Author:":
|
||||||
|
inSection = False
|
||||||
|
last, first = value.strip().split(', ')
|
||||||
|
name = Name()
|
||||||
|
name.first = first
|
||||||
|
name.last = last
|
||||||
|
book.author.append(name)
|
||||||
|
case "Editor:":
|
||||||
|
inSection = False
|
||||||
|
book.editor.last, book.editor.first = value.strip().split(', ')
|
||||||
|
case "Artist:":
|
||||||
|
inSection = False
|
||||||
|
book.artist.last, book.artist.first = value.strip().split(', ')
|
||||||
|
case "Publisher:":
|
||||||
|
inSection = False
|
||||||
|
book.publisher = value.strip()
|
||||||
|
case "Copyright:":
|
||||||
|
inSection = False
|
||||||
|
book.copyright = value.strip()
|
||||||
|
case "ISBN:":
|
||||||
|
inSection = False
|
||||||
|
book.isbn = value.strip()
|
||||||
|
case "UUID:":
|
||||||
|
inSection = False
|
||||||
|
if value.strip() == "":
|
||||||
|
book.uuid = uuid4()
|
||||||
|
else:
|
||||||
|
book.uuid = value.strip()
|
||||||
|
case "Source:":
|
||||||
|
inSection = False
|
||||||
|
book.source = value.strip()
|
||||||
|
case "Subjects:":
|
||||||
|
inSection = False
|
||||||
|
book.subjects = value.strip()
|
||||||
|
case "Series:":
|
||||||
|
inSection = False
|
||||||
|
book.series.number, book.series.name = value.strip().split(' ', 1)
|
||||||
|
case "Cover:":
|
||||||
|
inSection = False
|
||||||
|
book.cover.name, book.cover.type = value.strip().split('.')
|
||||||
|
case "TitlePage:":
|
||||||
|
inSection = True
|
||||||
|
section = Section()
|
||||||
|
section.type = "title"
|
||||||
|
section.name, section.title = value.strip().split(' ', 1)
|
||||||
|
book.sections.append(section)
|
||||||
|
case "CopyrightPage:":
|
||||||
|
inSection = True
|
||||||
|
section = Section()
|
||||||
|
section.type = "copyright-page"
|
||||||
|
section.name, section.title = value.strip().split(' ', 1)
|
||||||
|
book.sections.append(section)
|
||||||
|
case "Dedication:":
|
||||||
|
inSection = True
|
||||||
|
section = Section()
|
||||||
|
section.type = "dedication"
|
||||||
|
section.name, section.title = value.strip().split(' ', 1)
|
||||||
|
book.sections.append(section)
|
||||||
|
case "Text:":
|
||||||
|
inSection = True
|
||||||
|
section = Section()
|
||||||
|
section.type = "text"
|
||||||
|
section.name, section.title = value.strip().split(' ', 1)
|
||||||
|
book.sections.append(section)
|
||||||
|
case "Foreward:":
|
||||||
|
inSection = True
|
||||||
|
section = Section()
|
||||||
|
section.type = "forward"
|
||||||
|
section.name, section.title = value.strip().split(' ', 1)
|
||||||
|
book.sections.append(section)
|
||||||
|
case "Notes:":
|
||||||
|
inSection = True
|
||||||
|
section = Section()
|
||||||
|
section.type = "notes"
|
||||||
|
section.name, section.title = value.strip().split(' ', 1)
|
||||||
|
book.sections.append(section)
|
||||||
|
case "License:":
|
||||||
|
inSection = True
|
||||||
|
section = Section()
|
||||||
|
section.type = "license"
|
||||||
|
section.name, section.title = value.strip().split(' ', 1)
|
||||||
|
book.sections.append(section)
|
||||||
|
case "Acknowledgement:":
|
||||||
|
inSection = True
|
||||||
|
section = Section()
|
||||||
|
section.type = "acknowledgement"
|
||||||
|
section.name, section.title = value.strip().split(' ', 1)
|
||||||
|
book.sections.append(section)
|
||||||
|
case "TOC:":
|
||||||
|
inSection = True
|
||||||
|
section = Section()
|
||||||
|
section.type = "toc"
|
||||||
|
section.name, section.title = value.strip().split(' ', 1)
|
||||||
|
book.sections.append(section)
|
||||||
|
case "Image:":
|
||||||
|
image = Image()
|
||||||
|
image.name, imageText = value.strip().split(' ',1)
|
||||||
|
extension = image.name.strip().split('.')[1]
|
||||||
|
match extension:
|
||||||
|
case "jpg":
|
||||||
|
image.type = "jpeg"
|
||||||
|
case "jpeg":
|
||||||
|
image.type = "jpeg"
|
||||||
|
case "png":
|
||||||
|
image.type = "png"
|
||||||
|
image.alt, image.caption = imageText.strip().split('::')
|
||||||
|
book.images.append(image)
|
||||||
|
if not image.caption:
|
||||||
|
imageCode = '<img src="../Images/' + image.name +'" alt="' + image.alt + '"/>\n'
|
||||||
|
imageCode += ' <a id="' + image.name.split('.')[0] + '"><!-- Anchor --></a>\n'
|
||||||
|
else:
|
||||||
|
imageCode = '<div class="center group">\n'
|
||||||
|
imageCode += ' <img src="../Images/' + image.name + '" alt="' + image.alt + '" />\n'
|
||||||
|
imageCode += ' <a id="' + image.name.split('.')[0] + '"><!-- Anchor --></a>\n'
|
||||||
|
imageCode += ' <p class="caption">' + image.caption + '</p>\n'
|
||||||
|
imageCode += '</div>\n<br />\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 != '<style>\n' and line != '</style>' 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('<!-- '):
|
||||||
|
identify(line)
|
||||||
|
elif line.startswith('<link rel="stylesheet"'):
|
||||||
|
findStyle(line)
|
||||||
|
elif inSection:
|
||||||
|
book.sections[-1].body += line
|
||||||
|
if verbose:
|
||||||
|
print("Parse complete for {}".format(book.title))
|
||||||
|
|
||||||
|
|
||||||
|
def writeStructure(overwrite):
|
||||||
|
global verbose
|
||||||
|
mode = 0o775
|
||||||
|
|
||||||
|
if os.path.isdir(book.directory):
|
||||||
|
if overwrite:
|
||||||
|
rmtree(book.directory)
|
||||||
|
else:
|
||||||
|
print("writeStructure: Directory exists.")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
os.mkdir(book.directory, mode)
|
||||||
|
|
||||||
|
for directory in ["META-INF", "OEBPS", "OEBPS/Images", "OEBPS/Styles", "OEBPS/Text"]:
|
||||||
|
path = os.path.join(book.directory, directory)
|
||||||
|
os.mkdir(path, mode)
|
||||||
|
if verbose:
|
||||||
|
print("Finished writing ePub structure")
|
||||||
|
|
||||||
|
|
||||||
|
def writeMisc():
|
||||||
|
global verbose
|
||||||
|
|
||||||
|
access = 'w'
|
||||||
|
directory = book.directory
|
||||||
|
file = os.path.join(book.directory, "mimetype")
|
||||||
|
|
||||||
|
mimetype = open(file, access)
|
||||||
|
mimetype.write("application/epub+zip")
|
||||||
|
mimetype.close()
|
||||||
|
|
||||||
|
file = os.path.join(directory, "META-INF", "com.apple.ibooks.display-options.xml")
|
||||||
|
meta1 = open(file, access)
|
||||||
|
meta1.write('<?xml version="1.0" encoding="UTF-8"?>\n<display_options>\n <platform name="*">\n <option name="specified-fonts">false</option>\n </platform>\n</display_options>')
|
||||||
|
meta1.close()
|
||||||
|
|
||||||
|
file = os.path.join(directory, "META-INF", "container.xml")
|
||||||
|
meta2 = open(file, access)
|
||||||
|
meta2.write('<?xml version="1.0" encoding="UTF-8"?>\n<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">\n <rootfiles>\n <rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>\n </rootfiles>\n</container>')
|
||||||
|
meta2.close()
|
||||||
|
if verbose:
|
||||||
|
print("Finished writing metadata")
|
||||||
|
|
||||||
|
|
||||||
|
def writeStyles():
|
||||||
|
access = 'w'
|
||||||
|
file = os.path.join(book.directory, "OEBPS", "Styles", "style.css")
|
||||||
|
|
||||||
|
style = open(file, access)
|
||||||
|
style.write(book.style)
|
||||||
|
style.close()
|
||||||
|
new = os.path.join(book.directory, "OEBPS", "Styles", "Inconsolata-Regular.otf")
|
||||||
|
old = os.path.join(os.path.split(book.filename)[0], "Images", "Inconsolata-Regular.otf")
|
||||||
|
copy(old, new)
|
||||||
|
new = os.path.join(book.directory, "OEBPS", "Styles", "invisible1.ttf")
|
||||||
|
old = os.path.join(os.path.split(book.filename)[0], "Images", "invisible1.ttf")
|
||||||
|
copy(old, new)
|
||||||
|
new = os.path.join(book.directory, "OEBPS", "Styles", "MgOpenModataRegular.ttf")
|
||||||
|
old = os.path.join(os.path.split(book.filename)[0], "Images", "MgOpenModataRegular.ttf")
|
||||||
|
copy(old, new)
|
||||||
|
if verbose:
|
||||||
|
print("Finished writing style")
|
||||||
|
|
||||||
|
|
||||||
|
def writeNCX():
|
||||||
|
directory = book.directory
|
||||||
|
access = 'w'
|
||||||
|
file = os.path.join(directory, 'OEBPS', 'toc.ncx')
|
||||||
|
navpoints = []
|
||||||
|
|
||||||
|
contentsstart = """<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||||
|
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
|
||||||
|
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
|
||||||
|
<head>
|
||||||
|
<meta content="urn:isbn:""" + str(book.uuid) + """" name="dtb:uid"/>
|
||||||
|
<meta content="1" name="dtb:depth"/>
|
||||||
|
<meta content="-1" name="dtb:totalPageCount"/>
|
||||||
|
<meta content="-1" name="dtb:maxPageNumber"/>
|
||||||
|
</head>
|
||||||
|
<docTitle>
|
||||||
|
<text>""" + book.title.strip() + """</text>
|
||||||
|
</docTitle>
|
||||||
|
<navMap>
|
||||||
|
<navPoint id="cover" playOrder="1">
|
||||||
|
<navLabel>
|
||||||
|
<text>Cover</text>
|
||||||
|
</navLabel>
|
||||||
|
<content src="Text/cover.xhtml"/>
|
||||||
|
</navPoint>""" + '\n'
|
||||||
|
|
||||||
|
contentsend = """ </navMap>
|
||||||
|
</ncx>"""
|
||||||
|
|
||||||
|
number = 2
|
||||||
|
for section in book.sections:
|
||||||
|
if section.type != "toc":
|
||||||
|
navpoints.append("\t<navPoint id =\"" + section.name.strip() + "\" playOrder=\"" + str(number) + "\">\n" +
|
||||||
|
"\t\t<navLabel>\n\t\t\t<text>" + section.title.strip() + "</text>\n\t\t</navLabel>\n" +
|
||||||
|
"\t\t<content src=\"Text/" + section.name.strip() + ".xhtml\"/>\n\t</navPoint>\n")
|
||||||
|
number += 1
|
||||||
|
|
||||||
|
contents = contentsstart
|
||||||
|
for navpoint in navpoints:
|
||||||
|
contents += navpoint
|
||||||
|
contents += contentsend
|
||||||
|
|
||||||
|
ncx = open(file, access)
|
||||||
|
ncx.write(contents)
|
||||||
|
ncx.close()
|
||||||
|
if verbose:
|
||||||
|
print("Finished writing ncx")
|
||||||
|
|
||||||
|
|
||||||
|
def writeTOC(section):
|
||||||
|
access = 'w'
|
||||||
|
file = os.path.join(book.directory,'OEBPS', 'toc.xhtml')
|
||||||
|
contents = """<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
|
||||||
|
<head>
|
||||||
|
<title>Table of Contents</title>
|
||||||
|
<link href="Styles/style.css" rel="stylesheet" type="text/css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
"""
|
||||||
|
contents += section.body
|
||||||
|
contents += """
|
||||||
|
</body>
|
||||||
|
</html>"""
|
||||||
|
toc = open(file, access)
|
||||||
|
toc.write(contents)
|
||||||
|
toc.close()
|
||||||
|
if verbose:
|
||||||
|
print("Finished writing toc")
|
||||||
|
|
||||||
|
|
||||||
|
def writeCover():
|
||||||
|
access = 'w'
|
||||||
|
file = os.path.join(book.directory, 'OEBPS', 'Text', 'cover.xhtml')
|
||||||
|
contents = """<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||||
|
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<title>Cover</title>
|
||||||
|
<style type="text/css">
|
||||||
|
/* <![CDATA[ */
|
||||||
|
img { max-width: 100%; }
|
||||||
|
body { oeb-column-number: 1; }
|
||||||
|
#cover-image { text-align: center; }
|
||||||
|
/* ]]> */
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="cover-image">
|
||||||
|
<img alt= """ + '"' + book.title.strip() + '"' + """ src="../Images/cover.jpeg" />
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
new = os.path.join(book.directory, "OEBPS", "Images", "cover.jpeg")
|
||||||
|
old = os.path.join(os.path.split(book.filename)[0], "Images", "cover.jpeg")
|
||||||
|
cover = open(file, access)
|
||||||
|
cover.write(contents)
|
||||||
|
cover.close()
|
||||||
|
copy(old, new)
|
||||||
|
if verbose:
|
||||||
|
print("Finished writing cover")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def writeContents():
|
||||||
|
contents = '<?xml version="1.0" encoding="UTF-8"?>\n'
|
||||||
|
contents += '<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="bookid" prefix="rendition: http://www.idpf.org/vocab/rendition/# cc: http://creativecommons.org/ns#">\n'
|
||||||
|
contents += ' <metadata xmlns:dc="http://purl.org/dc/elements/1.1/">\n'
|
||||||
|
contents += ' <dc:identifier id="bookid">urn:uuid' + book.isbn + '</dc:identifier>\n'
|
||||||
|
contents += ' <dc:title id="pub-title">' + book.title.strip() + '</dc:title>\n'
|
||||||
|
contents += ' <meta refines="#pub-title" property="title-type">main</meta>\n'
|
||||||
|
if book.titlesort != "":
|
||||||
|
contents += ' <meta refines="#pub-title" property="file-as">' + book.titlesort + '</meta>\n'
|
||||||
|
if book.series.name != "":
|
||||||
|
print("found a book series")
|
||||||
|
contents += ' <dc:title id="pub-title2">' + book.series.name.strip() + '</dc:title>\n'
|
||||||
|
contents += ' <meta refines="#pub-title2" property="title-type">collection</meta>\n'
|
||||||
|
contents += ' <dc:title id="pub-title3">' + book.series.number + '</dc:title>\n'
|
||||||
|
contents += ' <meta refines="#pub-title3" property="title-type">display-seq</meta>\n'
|
||||||
|
contents += ' <meta name="calibre:series" content="' + book.series.name.strip() + '" />\n'
|
||||||
|
contents += ' <meta name="calibre:series_index" content="' + book.series.number.strip() + '" />\n'
|
||||||
|
contents += ' <dc:language id="pub-language">en</dc:language>\n'
|
||||||
|
contents += ' <dc:date>' + book.publishDate + '</dc:date>\n'
|
||||||
|
for name in book.author:
|
||||||
|
contents += ' <dc:creator id="author">' + name.first.strip() + ' ' + name.last.strip() + '</dc:creator>\n'
|
||||||
|
|
||||||
|
contents += ' <meta refines="#author" scheme="marc:relators" property="role">aut</meta>\n'
|
||||||
|
for name in book.author:
|
||||||
|
contents += ' <meta refines="#author" property="file-as">' + name.last.strip() + ", " + name.first.strip() + '</meta>\n'
|
||||||
|
contents += ' <dc:publisher>' + book.publisher.strip() + '</dc:publisher>\n'
|
||||||
|
contents += ' <dc:rights>' + book.copyright.strip() + '</dc:rights>\n'
|
||||||
|
contents += ' <dc:subject>' + book.subjects.strip() + '</dc:subject>\n'
|
||||||
|
contents += ' <dc:source>' + book.source.strip() + '</dc:source>\n'
|
||||||
|
contents += ' <meta name="cover" content="cover.jpeg" />\n'
|
||||||
|
|
||||||
|
contents += """ </metadata>
|
||||||
|
<manifest>
|
||||||
|
<item href="Images/cover.jpeg" id="cover.jpeg" media-type="image/jpeg" properties="cover-image" />
|
||||||
|
<item href="Text/cover.xhtml" id="cover" media-type="application/xhtml+xml" />
|
||||||
|
<item href="toc.xhtml" id="toc" media-type="application/xhtml+xml" properties="nav"/>
|
||||||
|
<item href="toc.ncx" id="ncx" media-type="application/x-dtbncx+xml" />
|
||||||
|
<item href="Styles/style.css" id="css" media-type="text/css" />
|
||||||
|
<item href="Styles/MgOpenModataRegular.ttf" id="mgopenmodataregular" media-type="application/vnd.ms-opentype" />
|
||||||
|
<item href="Styles/invisible1.ttf" id="invisible1" media-type="application/vnd.ms-opentype" />
|
||||||
|
<item href="Styles/Inconsolata-Regular.otf" id="inconsolate" media-type="application/vnd.ms-opentype" />
|
||||||
|
"""
|
||||||
|
if len(book.images) > 0:
|
||||||
|
contents += ' <item href="Text/illustrations.xhtml" id="illustrations" media-type="application/xhtml+xml" />\n'
|
||||||
|
|
||||||
|
for section in book.sections:
|
||||||
|
if section.type != 'toc':
|
||||||
|
contents += " <item href=" + '"' + "Text/" + section.name + '.xhtml" id="' + section.name + '" media-type="application/xhtml+xml" />\n'
|
||||||
|
|
||||||
|
for image in book.images:
|
||||||
|
contents += " <item href=" + '"' + "Images/" + image.name + '" id="' + image.name.split('.')[0] + '" media-type="image/' + image.type + '" />\n'
|
||||||
|
new = os.path.join(book.directory, "OEBPS", "Images", image.name)
|
||||||
|
old = os.path.join(os.path.split(book.filename)[0], "Images", image.name)
|
||||||
|
copy(old, new)
|
||||||
|
|
||||||
|
contents += """ </manifest>
|
||||||
|
<spine toc="ncx">
|
||||||
|
<itemref idref="cover" />
|
||||||
|
"""
|
||||||
|
if len(book.images) > 0:
|
||||||
|
contents += ' <itemref idref="illustrations" />\n'
|
||||||
|
for section in book.sections:
|
||||||
|
contents += ' <itemref idref="' + section.name + '" />\n'
|
||||||
|
|
||||||
|
contents += """ </spine>
|
||||||
|
<guide>
|
||||||
|
<reference href="Text/cover.xhtml" title="Cover" type="cover" />
|
||||||
|
<reference href="toc.xhtml" title="Table of Contents" type="toc" />
|
||||||
|
"""
|
||||||
|
if len(book.images) > 0:
|
||||||
|
contents += ' <reference href="Text/illustrations.xhtml" title="Illustrations" type="text" />\n'
|
||||||
|
|
||||||
|
for section in book.sections:
|
||||||
|
if section.type != 'toc':
|
||||||
|
contents += ' <reference href="Text/' + section.name.strip() + '.xhtml" title="' + section.title.strip() + '" type="' + section.type.strip() + '" />\n'
|
||||||
|
|
||||||
|
contents += """ </guide>
|
||||||
|
</package>
|
||||||
|
"""
|
||||||
|
access = 'w'
|
||||||
|
file = os.path.join(book.directory, 'OEBPS', 'content.opf')
|
||||||
|
content = open(file, access)
|
||||||
|
content.write(contents)
|
||||||
|
content.close()
|
||||||
|
if verbose:
|
||||||
|
print("Finished writing content")
|
||||||
|
|
||||||
|
|
||||||
|
def writeSections():
|
||||||
|
access = 'w'
|
||||||
|
for section in book.sections:
|
||||||
|
if section.type.strip() == "toc":
|
||||||
|
writeTOC(section)
|
||||||
|
continue
|
||||||
|
contents = """<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||||
|
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
|
||||||
|
<head>
|
||||||
|
"""
|
||||||
|
contents += ' <title>' + section.title.strip() + '</title>\n <link href="../Styles/style.css" rel="stylesheet" type="text/css" />\n </head>\n <body>\n'
|
||||||
|
contents += ' <div id="' + section.name.strip() + '" xml:lang="en-US">\n'
|
||||||
|
contents += section.body
|
||||||
|
contents += " </div>\n </body>\n</html>\n"
|
||||||
|
file = os.path.join(book.directory, 'OEBPS', 'Text', section.name.strip() + ".xhtml")
|
||||||
|
content = open(file, access)
|
||||||
|
content.write(contents)
|
||||||
|
content.close()
|
||||||
|
if verbose:
|
||||||
|
print(f"Finished writing section {section.name}.xhtml")
|
||||||
|
|
||||||
|
|
||||||
|
def writeIllustrations():
|
||||||
|
access = 'w'
|
||||||
|
contents = """<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||||
|
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
|
||||||
|
<head>
|
||||||
|
<title>Illustrations</title>
|
||||||
|
<link href="../Styles/style.css" rel="stylesheet" type="text/css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1 class="title">Illustrations</h1>
|
||||||
|
<table>
|
||||||
|
"""
|
||||||
|
for image in book.images:
|
||||||
|
contents += ' <tr><td><a href="../Images/' + image.name + '">' + image.caption + '</a></td></tr>\n'
|
||||||
|
contents += ' </table>\n</body>\n</html>'
|
||||||
|
|
||||||
|
if len(book.images) > 0:
|
||||||
|
file = os.path.join(book.directory, 'OEBPS', 'Text', "illustrations.xhtml")
|
||||||
|
content = open(file, access)
|
||||||
|
content.write(contents)
|
||||||
|
content.close()
|
||||||
|
if verbose:
|
||||||
|
print(f"Finished writing section illustrations.xhtml")
|
||||||
|
|
||||||
|
def writeEpub():
|
||||||
|
cmd = f'cd {book.directory}; zip -X0 "{book.directory}.epub" mimetype;zip -X9Dr "{book.directory}.epub" META-INF OEBPS'
|
||||||
|
subprocess.run(cmd, shell=True)
|
||||||
|
if verbose:
|
||||||
|
print(f"Finished writing {book.directory}.epub")
|
||||||
|
|
||||||
|
def parseArgs():
|
||||||
|
global book, verbose
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("fileName", help="File to process")
|
||||||
|
parser.add_argument("-f", "--force", help="Force overwrite an existing book directory", action="store_true")
|
||||||
|
parser.add_argument("-v", "--verbose", help="Provide updates while processing", action="store_true")
|
||||||
|
args = parser.parse_args()
|
||||||
|
book.filename = str(args.fileName)
|
||||||
|
if not os.path.isfile(book.filename):
|
||||||
|
print("File '{}' is not found. Exiting...".format(book.filename))
|
||||||
|
exit()
|
||||||
|
verbose = args.verbose
|
||||||
|
return args.force
|
||||||
|
|
||||||
|
def main():
|
||||||
|
global book, inStyle, inSection, verbose
|
||||||
|
book = Book()
|
||||||
|
book.publishDate = str(datetime.now().year) + "-" + str(datetime.now().month) + "-" + str(datetime.now().day)
|
||||||
|
inSection = False
|
||||||
|
inStyle = False
|
||||||
|
force = False
|
||||||
|
verbose = False
|
||||||
|
|
||||||
|
overwrite = parseArgs()
|
||||||
|
parseBook()
|
||||||
|
if (overwrite and verbose):
|
||||||
|
print("Force flag, overwriting existing directory")
|
||||||
|
writeStructure(overwrite)
|
||||||
|
writeMisc()
|
||||||
|
writeStyles()
|
||||||
|
writeNCX()
|
||||||
|
writeCover()
|
||||||
|
writeContents()
|
||||||
|
writeSections()
|
||||||
|
writeIllustrations()
|
||||||
|
writeEpub()
|
||||||
|
|
||||||
|
global book, inSection, inStyle
|
||||||
|
|
||||||
|
main() # run the program
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user