txt2ebook 0.1.116__tar.gz → 0.1.117__tar.gz

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.
Files changed (51) hide show
  1. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/PKG-INFO +1 -1
  2. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/pyproject.toml +1 -1
  3. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/__init__.py +1 -1
  4. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/cli.py +14 -90
  5. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/parser.py +1 -1
  6. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/subcommands/epub.py +9 -0
  7. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/subcommands/gmi.py +9 -0
  8. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/subcommands/massage.py +9 -0
  9. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/subcommands/md.py +9 -0
  10. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/subcommands/pdf.py +9 -0
  11. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/subcommands/tex.py +9 -0
  12. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/subcommands/typ.py +9 -0
  13. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/tokenizer.py +5 -5
  14. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/LICENSE.md +0 -0
  15. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/README.md +0 -0
  16. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/__main__.py +0 -0
  17. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/exceptions.py +0 -0
  18. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/formats/__init__.py +0 -0
  19. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/formats/base.py +0 -0
  20. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/formats/epub.py +0 -0
  21. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/formats/gmi.py +0 -0
  22. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/formats/md.py +0 -0
  23. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/formats/pdf.py +0 -0
  24. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/formats/templates/__init__.py +0 -0
  25. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/formats/templates/epub/__init__.py +0 -0
  26. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/formats/templates/epub/clean.css +0 -0
  27. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/formats/templates/epub/condense.css +0 -0
  28. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/formats/templates/epub/noindent.css +0 -0
  29. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/formats/tex.py +0 -0
  30. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/formats/txt.py +0 -0
  31. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/formats/typ.py +0 -0
  32. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/helpers/__init__.py +0 -0
  33. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/languages/__init__.py +0 -0
  34. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/languages/en.py +0 -0
  35. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/languages/zh_cn.py +0 -0
  36. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/languages/zh_tw.py +0 -0
  37. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/locales/en/LC_MESSAGES/txt2ebook.mo +0 -0
  38. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/locales/en/LC_MESSAGES/txt2ebook.po +0 -0
  39. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/locales/txt2ebook.pot +0 -0
  40. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/locales/zh-cn/LC_MESSAGES/txt2ebook.mo +0 -0
  41. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/locales/zh-cn/LC_MESSAGES/txt2ebook.po +0 -0
  42. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/locales/zh-tw/LC_MESSAGES/txt2ebook.mo +0 -0
  43. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/locales/zh-tw/LC_MESSAGES/txt2ebook.po +0 -0
  44. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/models/__init__.py +0 -0
  45. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/models/book.py +0 -0
  46. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/models/chapter.py +0 -0
  47. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/models/volume.py +0 -0
  48. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/subcommands/env.py +0 -0
  49. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/subcommands/parse.py +0 -0
  50. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/txt2ebook.py +0 -0
  51. {txt2ebook-0.1.116 → txt2ebook-0.1.117}/src/txt2ebook/zh_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: txt2ebook
3
- Version: 0.1.116
3
+ Version: 0.1.117
4
4
  Summary: CLI tool to convert txt file to ebook format
5
5
  Home-page: https://github.com/kianmeng/txt2ebook
6
6
  License: AGPL-3.0-or-later
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "txt2ebook"
3
- version = "0.1.116"
3
+ version = "0.1.117"
4
4
  description = "CLI tool to convert txt file to ebook format"
5
5
  authors = ["Kian-Meng Ang <kianmeng@cpan.org>"]
6
6
  license = "AGPL-3.0-or-later"
@@ -24,7 +24,7 @@ import langdetect
24
24
 
25
25
  logger = logging.getLogger(__name__)
26
26
 
27
- __version__ = "0.1.116"
27
+ __version__ = "0.1.117"
28
28
 
29
29
 
30
30
  def setup_logger(config: argparse.Namespace) -> None:
@@ -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.env
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
- txt2ebook.subcommands.parse.build_subparser(subparsers)
290
- txt2ebook.subcommands.massage.build_subparser(subparsers)
291
- txt2ebook.subcommands.epub.build_subparser(subparsers)
292
- txt2ebook.subcommands.tex.build_subparser(subparsers)
293
- txt2ebook.subcommands.pdf.build_subparser(subparsers)
294
- txt2ebook.subcommands.typ.build_subparser(subparsers)
295
- txt2ebook.subcommands.md.build_subparser(subparsers)
296
- txt2ebook.subcommands.gmi.build_subparser(subparsers)
297
- txt2ebook.subcommands.env.build_subparser(subparsers)
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
 
@@ -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)
@@ -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.
@@ -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.
@@ -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
 
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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)
File without changes
File without changes