txt2ebook 0.1.116__py3-none-any.whl → 0.1.117__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- txt2ebook/__init__.py +1 -1
- txt2ebook/cli.py +14 -90
- txt2ebook/parser.py +1 -1
- txt2ebook/subcommands/epub.py +9 -0
- txt2ebook/subcommands/gmi.py +9 -0
- txt2ebook/subcommands/massage.py +9 -0
- txt2ebook/subcommands/md.py +9 -0
- txt2ebook/subcommands/pdf.py +9 -0
- txt2ebook/subcommands/tex.py +9 -0
- txt2ebook/subcommands/typ.py +9 -0
- txt2ebook/tokenizer.py +5 -5
- {txt2ebook-0.1.116.dist-info → txt2ebook-0.1.117.dist-info}/METADATA +1 -1
- {txt2ebook-0.1.116.dist-info → txt2ebook-0.1.117.dist-info}/RECORD +16 -16
- {txt2ebook-0.1.116.dist-info → txt2ebook-0.1.117.dist-info}/LICENSE.md +0 -0
- {txt2ebook-0.1.116.dist-info → txt2ebook-0.1.117.dist-info}/WHEEL +0 -0
- {txt2ebook-0.1.116.dist-info → txt2ebook-0.1.117.dist-info}/entry_points.txt +0 -0
txt2ebook/__init__.py
CHANGED
txt2ebook/cli.py
CHANGED
@@ -21,19 +21,13 @@
|
|
21
21
|
"""
|
22
22
|
|
23
23
|
import argparse
|
24
|
+
import importlib
|
24
25
|
import logging
|
26
|
+
import pkgutil
|
25
27
|
import sys
|
26
28
|
from typing import Optional, Sequence
|
27
29
|
|
28
|
-
import txt2ebook.subcommands
|
29
|
-
import txt2ebook.subcommands.epub
|
30
|
-
import txt2ebook.subcommands.gmi
|
31
|
-
import txt2ebook.subcommands.massage
|
32
|
-
import txt2ebook.subcommands.md
|
33
|
-
import txt2ebook.subcommands.parse
|
34
|
-
import txt2ebook.subcommands.pdf
|
35
|
-
import txt2ebook.subcommands.tex
|
36
|
-
import txt2ebook.subcommands.typ
|
30
|
+
import txt2ebook.subcommands
|
37
31
|
from txt2ebook import __version__, setup_logger
|
38
32
|
|
39
33
|
logger = logging.getLogger(__name__)
|
@@ -128,50 +122,6 @@ def build_parser(
|
|
128
122
|
help="convert ASCII character from halfwidth to fullwidth",
|
129
123
|
)
|
130
124
|
|
131
|
-
|
132
|
-
parser.add_argument(
|
133
|
-
"-ra",
|
134
|
-
"--regex-author",
|
135
|
-
dest="re_author",
|
136
|
-
default=[],
|
137
|
-
action="append",
|
138
|
-
help="regex to parse author of the book (default: by LANGUAGE)",
|
139
|
-
metavar="REGEX",
|
140
|
-
)
|
141
|
-
|
142
|
-
parser.add_argument(
|
143
|
-
"-rc",
|
144
|
-
"--regex-chapter",
|
145
|
-
dest="re_chapter",
|
146
|
-
default=[],
|
147
|
-
action="append",
|
148
|
-
help="regex to parse chapter header (default: by LANGUAGE)",
|
149
|
-
metavar="REGEX",
|
150
|
-
)
|
151
|
-
|
152
|
-
parser.add_argument(
|
153
|
-
"-rvc",
|
154
|
-
"--regex-volume-chapter",
|
155
|
-
dest="re_volume_chapter",
|
156
|
-
default=[],
|
157
|
-
action="append",
|
158
|
-
help=(
|
159
|
-
"regex to parse volume and chapter header "
|
160
|
-
"(default: by LANGUAGE)"
|
161
|
-
),
|
162
|
-
metavar="REGEX",
|
163
|
-
)
|
164
|
-
|
165
|
-
parser.add_argument(
|
166
|
-
"-rv",
|
167
|
-
"--regex-volume",
|
168
|
-
dest="re_volume",
|
169
|
-
default=[],
|
170
|
-
action="append",
|
171
|
-
help="regex to parse volume header (default: by LANGUAGE)",
|
172
|
-
metavar="REGEX",
|
173
|
-
)
|
174
|
-
|
175
125
|
parser.add_argument(
|
176
126
|
"-hn",
|
177
127
|
"--header-number",
|
@@ -191,16 +141,6 @@ def build_parser(
|
|
191
141
|
metavar="SEPARATOR",
|
192
142
|
)
|
193
143
|
|
194
|
-
parser.add_argument(
|
195
|
-
"-rt",
|
196
|
-
"--regex-title",
|
197
|
-
dest="re_title",
|
198
|
-
default=[],
|
199
|
-
action="append",
|
200
|
-
help="regex to parse title of the book (default: by LANGUAGE)",
|
201
|
-
metavar="REGEX",
|
202
|
-
)
|
203
|
-
|
204
144
|
parser.add_argument(
|
205
145
|
"-ff",
|
206
146
|
"--filename-format",
|
@@ -216,24 +156,6 @@ def build_parser(
|
|
216
156
|
metavar="FILENAME_FORMAT",
|
217
157
|
)
|
218
158
|
|
219
|
-
parser.add_argument(
|
220
|
-
"-op",
|
221
|
-
"--open",
|
222
|
-
default=False,
|
223
|
-
action="store_true",
|
224
|
-
dest="open",
|
225
|
-
help="open the generated file using default program",
|
226
|
-
)
|
227
|
-
|
228
|
-
parser.add_argument(
|
229
|
-
"-ss",
|
230
|
-
"--sort-volume-and-chapter",
|
231
|
-
default=False,
|
232
|
-
action="store_true",
|
233
|
-
dest="sort_volume_and_chapter",
|
234
|
-
help="short volume and chapter",
|
235
|
-
)
|
236
|
-
|
237
159
|
parser.add_argument(
|
238
160
|
"-rw",
|
239
161
|
"--raise-on-warning",
|
@@ -286,15 +208,17 @@ def build_parser(
|
|
286
208
|
)
|
287
209
|
|
288
210
|
subparsers = parser.add_subparsers(help="sub-command help")
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
211
|
+
|
212
|
+
iter_namespace = pkgutil.iter_modules(
|
213
|
+
txt2ebook.subcommands.__path__, txt2ebook.subcommands.__name__ + "."
|
214
|
+
)
|
215
|
+
subcommands = {
|
216
|
+
name: importlib.import_module(name)
|
217
|
+
for finder, name, ispkg
|
218
|
+
in iter_namespace
|
219
|
+
}
|
220
|
+
for subcommand in subcommands.values():
|
221
|
+
subcommand.build_subparser(subparsers)
|
298
222
|
|
299
223
|
return parser
|
300
224
|
|
txt2ebook/parser.py
CHANGED
@@ -231,7 +231,7 @@ class Parser:
|
|
231
231
|
logger.info("Found or set tags: %s", repr(tags))
|
232
232
|
logger.info("Found or set index: %s", repr(index))
|
233
233
|
|
234
|
-
if self.config.sort_volume_and_chapter:
|
234
|
+
if hasattr(self.config, "sort_volume_and_chapter") and self.config.sort_volume_and_chapter:
|
235
235
|
self.sort_volume_and_chapter(toc)
|
236
236
|
|
237
237
|
return (book_title, authors, translators, tags, index, toc)
|
txt2ebook/subcommands/epub.py
CHANGED
@@ -79,6 +79,15 @@ def build_subparser(subparsers) -> None:
|
|
79
79
|
help="generate each volume as separate page",
|
80
80
|
)
|
81
81
|
|
82
|
+
epub_parser.add_argument(
|
83
|
+
"-op",
|
84
|
+
"--open",
|
85
|
+
default=False,
|
86
|
+
action="store_true",
|
87
|
+
dest="open",
|
88
|
+
help="open the generated file using default program",
|
89
|
+
)
|
90
|
+
|
82
91
|
|
83
92
|
def run(args: argparse.Namespace) -> None:
|
84
93
|
"""Run epub subcommand.
|
txt2ebook/subcommands/gmi.py
CHANGED
@@ -71,6 +71,15 @@ def build_subparser(subparsers) -> None:
|
|
71
71
|
help="add table of content",
|
72
72
|
)
|
73
73
|
|
74
|
+
gmi_parser.add_argument(
|
75
|
+
"-op",
|
76
|
+
"--open",
|
77
|
+
default=False,
|
78
|
+
action="store_true",
|
79
|
+
dest="open",
|
80
|
+
help="open the generated file using default program",
|
81
|
+
)
|
82
|
+
|
74
83
|
|
75
84
|
def run(args: argparse.Namespace) -> None:
|
76
85
|
"""Run md subcommand.
|
txt2ebook/subcommands/massage.py
CHANGED
@@ -117,6 +117,15 @@ def build_subparser(subparsers) -> None:
|
|
117
117
|
metavar="WIDTH",
|
118
118
|
)
|
119
119
|
|
120
|
+
massage_parser.add_argument(
|
121
|
+
"-ss",
|
122
|
+
"--sort-volume-and-chapter",
|
123
|
+
default=False,
|
124
|
+
action="store_true",
|
125
|
+
dest="sort_volume_and_chapter",
|
126
|
+
help="short volume and chapter",
|
127
|
+
)
|
128
|
+
|
120
129
|
massage_parser.set_defaults(func=run)
|
121
130
|
|
122
131
|
|
txt2ebook/subcommands/md.py
CHANGED
@@ -71,6 +71,15 @@ def build_subparser(subparsers) -> None:
|
|
71
71
|
help="add table of content",
|
72
72
|
)
|
73
73
|
|
74
|
+
md_parser.add_argument(
|
75
|
+
"-op",
|
76
|
+
"--open",
|
77
|
+
default=False,
|
78
|
+
action="store_true",
|
79
|
+
dest="open",
|
80
|
+
help="open the generated file using default program",
|
81
|
+
)
|
82
|
+
|
74
83
|
|
75
84
|
def run(args: argparse.Namespace) -> None:
|
76
85
|
"""Run md subcommand.
|
txt2ebook/subcommands/pdf.py
CHANGED
@@ -62,6 +62,15 @@ def build_subparser(subparsers) -> None:
|
|
62
62
|
metavar="PAGE_SIZE",
|
63
63
|
)
|
64
64
|
|
65
|
+
pdf_parser.add_argument(
|
66
|
+
"-op",
|
67
|
+
"--open",
|
68
|
+
default=False,
|
69
|
+
action="store_true",
|
70
|
+
dest="open",
|
71
|
+
help="open the generated file using default program",
|
72
|
+
)
|
73
|
+
|
65
74
|
|
66
75
|
def run(args: argparse.Namespace) -> None:
|
67
76
|
"""Run pdf subcommand.
|
txt2ebook/subcommands/tex.py
CHANGED
@@ -68,6 +68,15 @@ def build_subparser(subparsers) -> None:
|
|
68
68
|
|
69
69
|
tex_parser.set_defaults(func=run)
|
70
70
|
|
71
|
+
tex_parser.add_argument(
|
72
|
+
"-op",
|
73
|
+
"--open",
|
74
|
+
default=False,
|
75
|
+
action="store_true",
|
76
|
+
dest="open",
|
77
|
+
help="open the generated file using default program",
|
78
|
+
)
|
79
|
+
|
71
80
|
|
72
81
|
def run(args: argparse.Namespace) -> None:
|
73
82
|
"""Run tex subcommand.
|
txt2ebook/subcommands/typ.py
CHANGED
@@ -79,6 +79,15 @@ def build_subparser(subparsers) -> None:
|
|
79
79
|
help="keyword to index (default: '%(default)s')",
|
80
80
|
)
|
81
81
|
|
82
|
+
typ_parser.add_argument(
|
83
|
+
"-op",
|
84
|
+
"--open",
|
85
|
+
default=False,
|
86
|
+
action="store_true",
|
87
|
+
dest="open",
|
88
|
+
help="open the generated file using default program",
|
89
|
+
)
|
90
|
+
|
82
91
|
|
83
92
|
def run(args: argparse.Namespace) -> None:
|
84
93
|
"""Run typ subcommand.
|
txt2ebook/tokenizer.py
CHANGED
@@ -114,11 +114,11 @@ class Tokenizer:
|
|
114
114
|
"""Tokenize the metadata of the book."""
|
115
115
|
for line in self._extract_metadata():
|
116
116
|
re_title = f"^{self.langconf.DEFAULT_RE_TITLE}"
|
117
|
-
if self.config.re_title:
|
117
|
+
if hasattr(self.config, "re_title") and self.config.re_title:
|
118
118
|
re_title = self.config.re_title[0]
|
119
119
|
|
120
120
|
re_author = f"{self.langconf.DEFAULT_RE_AUTHOR}"
|
121
|
-
if self.config.re_author:
|
121
|
+
if hasattr(self.config, "re_author") and self.config.re_author:
|
122
122
|
re_author = self.config.re_author[0]
|
123
123
|
|
124
124
|
token_type_regex_map = [
|
@@ -205,7 +205,7 @@ class Tokenizer:
|
|
205
205
|
rf"^{self.langconf.DEFAULT_RE_VOLUME}\s*"
|
206
206
|
rf"{self.langconf.DEFAULT_RE_CHAPTER}"
|
207
207
|
)
|
208
|
-
if self.config.re_volume_chapter:
|
208
|
+
if hasattr(self.config, "re_volume_chapter") and self.config.re_volume_chapter:
|
209
209
|
re_volume_chapter = self.config.re_volume_chapter[0]
|
210
210
|
|
211
211
|
match = re.search(re_volume_chapter, line)
|
@@ -228,7 +228,7 @@ class Tokenizer:
|
|
228
228
|
token = None
|
229
229
|
|
230
230
|
re_volume = rf"^{self.langconf.DEFAULT_RE_VOLUME}$"
|
231
|
-
if self.config.re_volume:
|
231
|
+
if hasattr(self.config, "re_volume") and self.config.re_volume:
|
232
232
|
re_volume = "(" + "|".join(self.config.re_volume) + ")"
|
233
233
|
|
234
234
|
match = re.search(re_volume, line)
|
@@ -244,7 +244,7 @@ class Tokenizer:
|
|
244
244
|
token = None
|
245
245
|
|
246
246
|
re_chapter = rf"^{self.langconf.DEFAULT_RE_CHAPTER}$"
|
247
|
-
if self.config.re_chapter:
|
247
|
+
if hasattr(self.config, "re_chapter") and self.config.re_chapter:
|
248
248
|
re_chapter = "(" + "|".join(self.config.re_chapter) + ")"
|
249
249
|
|
250
250
|
match = re.search(re_chapter, line)
|
@@ -1,6 +1,6 @@
|
|
1
|
-
txt2ebook/__init__.py,sha256=
|
1
|
+
txt2ebook/__init__.py,sha256=BMEbrj7B5ltQJ8tMBXRt7CJtaH518F5Ripn4vXVsSeE,2681
|
2
2
|
txt2ebook/__main__.py,sha256=gMLvgpqc_BL4cBqNe0vqErRF5dlJPAbvqu1zndcAHYI,850
|
3
|
-
txt2ebook/cli.py,sha256=
|
3
|
+
txt2ebook/cli.py,sha256=QvojARWAJxgpu9AJBVP1bGEHJg6vfJrpGKjHMA-1T_A,6530
|
4
4
|
txt2ebook/exceptions.py,sha256=b2HDsXdqweLJbvSJEGt48nxvGkZq20SfYezSjwp77JU,842
|
5
5
|
txt2ebook/formats/__init__.py,sha256=WhiRWGvbUjc8QZfhAIkKCg6GL8vNNlEF73meZSzYhDA,2463
|
6
6
|
txt2ebook/formats/base.py,sha256=SMt6Op88-HoIxRA-tgPBNSlrt7-KZ-m5-BytAEJT4m0,5814
|
@@ -32,21 +32,21 @@ txt2ebook/models/__init__.py,sha256=8_k1oI_PnPMekhdZCXiTtg5WghdR6fugQEHJHsy1-Ds,
|
|
32
32
|
txt2ebook/models/book.py,sha256=Q4EzFFAGigz4MPSM9Vu_F-JxNOWjm82469Vy8-vq-pw,2758
|
33
33
|
txt2ebook/models/chapter.py,sha256=buECAklNQgM3tDehzyVO9YfA_F0iXyLq2PaMZGV_Zaw,1681
|
34
34
|
txt2ebook/models/volume.py,sha256=HyT4XO9yZ8d0PgZVfMMyAYUDFv58RrUmsSFNNmU-sHY,1592
|
35
|
-
txt2ebook/parser.py,sha256=
|
35
|
+
txt2ebook/parser.py,sha256=mrkpwyPwnFjrJUCQ7ghTgWmVJ0Q4m9R93MIM-tcqm08,8759
|
36
36
|
txt2ebook/subcommands/env.py,sha256=26wcAhEbjKfWYeNiIsjm9TTaBUyNDYx1MYUtV2ZFkmg,1481
|
37
|
-
txt2ebook/subcommands/epub.py,sha256=
|
38
|
-
txt2ebook/subcommands/gmi.py,sha256=
|
39
|
-
txt2ebook/subcommands/massage.py,sha256=
|
40
|
-
txt2ebook/subcommands/md.py,sha256=
|
37
|
+
txt2ebook/subcommands/epub.py,sha256=2zUL5wbp8Bv7OdwJPCuXV1rpjNkgnCTR4W2rKNVdMXo,2783
|
38
|
+
txt2ebook/subcommands/gmi.py,sha256=mO0OFNcO89fx5ny3m646v9HxsfA7m3V1cirXJ4WYByY,2598
|
39
|
+
txt2ebook/subcommands/massage.py,sha256=NkXW95MkwVyKPm1NMV8cekPAQ9NJQx3DGAGgpsRj5MY,7249
|
40
|
+
txt2ebook/subcommands/md.py,sha256=Dd8qQTLyasfBGpB00pJ5mDwlyLNaFrWZvFwI7XtkkHY,2610
|
41
41
|
txt2ebook/subcommands/parse.py,sha256=BpEHs-gFYbJK1-50FPUX_3INfuxkgL5Glgpd3IBdJfs,2730
|
42
|
-
txt2ebook/subcommands/pdf.py,sha256=
|
43
|
-
txt2ebook/subcommands/tex.py,sha256=
|
44
|
-
txt2ebook/subcommands/typ.py,sha256=
|
45
|
-
txt2ebook/tokenizer.py,sha256=
|
42
|
+
txt2ebook/subcommands/pdf.py,sha256=WAhf4BPYW_ejm1M4-_vPVkANTmDQtgXbNkNMwBm5_LI,2384
|
43
|
+
txt2ebook/subcommands/tex.py,sha256=nQ3OK5oZGNh3H9Y_Pz40q9eKIS_s-p5GYqRI59EgPiE,2534
|
44
|
+
txt2ebook/subcommands/typ.py,sha256=JPnDqrxAHdQGcP4MBKHNoBaTiQRrUp1rNx3TOQmVLow,2777
|
45
|
+
txt2ebook/tokenizer.py,sha256=785qIUg1WybCUtNG7r_m3zZv0P0DlSQhlH_TEVyrdbo,9554
|
46
46
|
txt2ebook/txt2ebook.py,sha256=ZP-5RxZcKasoowjuJjUR1yEBzHqekOBPruGvyj47sKg,13539
|
47
47
|
txt2ebook/zh_utils.py,sha256=EgKVbwqYGaTGswQUGcOCeSfRelzwkAb9WWY9TrsX1x4,4882
|
48
|
-
txt2ebook-0.1.
|
49
|
-
txt2ebook-0.1.
|
50
|
-
txt2ebook-0.1.
|
51
|
-
txt2ebook-0.1.
|
52
|
-
txt2ebook-0.1.
|
48
|
+
txt2ebook-0.1.117.dist-info/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
|
49
|
+
txt2ebook-0.1.117.dist-info/METADATA,sha256=7cyip_mosrVqWfLFSjmPnvoPH2mYJS8NhhF4F1J_3o8,7845
|
50
|
+
txt2ebook-0.1.117.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
51
|
+
txt2ebook-0.1.117.dist-info/entry_points.txt,sha256=JLW3Iv7eUyABlQeUFiUWQhLKfRdnB9o5SIcNlneGR0Q,77
|
52
|
+
txt2ebook-0.1.117.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|