txt2ebook 0.1.154__py3-none-any.whl → 0.1.155__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.
@@ -38,11 +38,10 @@ def build_subparser(subparsers) -> None:
38
38
 
39
39
  epub_parser.add_argument(
40
40
  "input_file",
41
- nargs=None if sys.stdin.isatty() else "?", # type: ignore
41
+ nargs="*",
42
42
  type=argparse.FileType("rb"),
43
- default=None if sys.stdin.isatty() else sys.stdin,
44
- help="source text filename",
45
- metavar="TXT_FILENAME",
43
+ help="source text filenames (can use glob patterns)",
44
+ metavar="TXT_FILENAMES",
46
45
  )
47
46
 
48
47
  epub_parser.add_argument(
@@ -124,6 +123,40 @@ def run(args: argparse.Namespace) -> None:
124
123
  Returns:
125
124
  None
126
125
  """
127
- book = parse_txt(args)
128
- writer = EpubWriter(book, args)
129
- writer.write()
126
+ input_sources = []
127
+
128
+ if not sys.stdin.isatty():
129
+ # piped input, use stdin as the single input source
130
+ input_sources.append(sys.stdin)
131
+ elif args.input_file:
132
+ # multiple file(s)
133
+ input_sources.extend(args.input_file)
134
+ else:
135
+ logger.error("No input files provided.")
136
+ sys.exit(1)
137
+
138
+ if len(input_sources) > 1 and args.output_file:
139
+ logger.error(
140
+ "Cannot specify a single output file when "
141
+ "processing multiple input files."
142
+ )
143
+ sys.exit(1)
144
+
145
+ for i, current_input_stream in enumerate(input_sources):
146
+ # ensures that `input_file` and `output_file` are correctly isolated
147
+ current_file_args = argparse.Namespace(**vars(args))
148
+ current_file_args.input_file = current_input_stream
149
+
150
+ # if an explicit output_file was provided, it must apply to the first
151
+ # input
152
+ if i > 0 and args.output_file:
153
+ current_file_args.output_file = None
154
+
155
+ book = parse_txt(current_file_args)
156
+ writer = EpubWriter(book, current_file_args)
157
+ writer.write()
158
+
159
+ # close the file stream if it was opened by argparse.FileType and is
160
+ # not sys.stdin.
161
+ if current_input_stream is not sys.stdin:
162
+ current_input_stream.close()
@@ -33,19 +33,10 @@ def build_subparser(subparsers) -> None:
33
33
 
34
34
  tex_parser.add_argument(
35
35
  "input_file",
36
- nargs=None if sys.stdin.isatty() else "?", # type: ignore
36
+ nargs="*",
37
37
  type=argparse.FileType("rb"),
38
- default=None if sys.stdin.isatty() else sys.stdin,
39
- help="source text filename",
40
- metavar="TXT_FILENAME",
41
- )
42
-
43
- tex_parser.add_argument(
44
- "output_file",
45
- nargs="?",
46
- default=None,
47
- help="converted ebook filename (default: 'TXT_FILENAME.pdf')",
48
- metavar="EBOOK_FILENAME",
38
+ help="source text filenames (can use glob patterns)",
39
+ metavar="TXT_FILENAMES",
49
40
  )
50
41
 
51
42
  tex_parser.add_argument(
@@ -121,6 +112,40 @@ def run(args: argparse.Namespace) -> None:
121
112
  Returns:
122
113
  None
123
114
  """
124
- book = parse_txt(args)
125
- writer = TexWriter(book, args)
126
- writer.write()
115
+ input_sources = []
116
+
117
+ if not sys.stdin.isatty():
118
+ # piped input, use stdin as the single input source
119
+ input_sources.append(sys.stdin)
120
+ elif args.input_file:
121
+ # multiple file(s)
122
+ input_sources.extend(args.input_file)
123
+ else:
124
+ logger.error("No input files provided.")
125
+ sys.exit(1)
126
+
127
+ if len(input_sources) > 1 and args.output_file:
128
+ logger.error(
129
+ "Cannot specify a single output file when "
130
+ "processing multiple input files."
131
+ )
132
+ sys.exit(1)
133
+
134
+ for i, current_input_stream in enumerate(input_sources):
135
+ # ensures that `input_file` and `output_file` are correctly isolated
136
+ current_file_args = argparse.Namespace(**vars(args))
137
+ current_file_args.input_file = current_input_stream
138
+
139
+ # if an explicit output_file was provided, it must apply to the first
140
+ # input
141
+ if i > 0 and args.output_file:
142
+ current_file_args.output_file = None
143
+
144
+ book = parse_txt(current_file_args)
145
+ writer = TexWriter(book, current_file_args)
146
+ writer.write()
147
+
148
+ # close the file stream if it was opened by argparse.FileType and is
149
+ # not sys.stdin.
150
+ if current_input_stream is not sys.stdin:
151
+ current_input_stream.close()
@@ -36,11 +36,10 @@ def build_subparser(subparsers) -> None:
36
36
 
37
37
  typ_parser.add_argument(
38
38
  "input_file",
39
- nargs=None if sys.stdin.isatty() else "?", # type: ignore
39
+ nargs="*",
40
40
  type=argparse.FileType("rb"),
41
- default=None if sys.stdin.isatty() else sys.stdin,
42
- help="source text filename",
43
- metavar="TXT_FILENAME",
41
+ help="source text filenames (can use glob patterns)",
42
+ metavar="TXT_FILENAMES",
44
43
  )
45
44
 
46
45
  typ_parser.add_argument(
@@ -126,11 +125,45 @@ def run(args: argparse.Namespace) -> None:
126
125
  """Run typ subcommand.
127
126
 
128
127
  Args:
129
- config (argparse.Namespace): Config from command line arguments
128
+ args (argparse.Namespace): Config from command line arguments
130
129
 
131
130
  Returns:
132
131
  None
133
132
  """
134
- book = parse_txt(args)
135
- writer = TypWriter(book, args)
136
- writer.write()
133
+ input_sources = []
134
+
135
+ if not sys.stdin.isatty():
136
+ # piped input, use stdin as the single input source
137
+ input_sources.append(sys.stdin)
138
+ elif args.input_file:
139
+ # multiple file(s)
140
+ input_sources.extend(args.input_file)
141
+ else:
142
+ logger.error("No input files provided.")
143
+ sys.exit(1)
144
+
145
+ if len(input_sources) > 1 and args.output_file:
146
+ logger.error(
147
+ "Cannot specify a single output file when "
148
+ "processing multiple input files."
149
+ )
150
+ sys.exit(1)
151
+
152
+ for i, current_input_stream in enumerate(input_sources):
153
+ # ensures that `input_file` and `output_file` are correctly isolated
154
+ current_file_args = argparse.Namespace(**vars(args))
155
+ current_file_args.input_file = current_input_stream
156
+
157
+ # if an explicit output_file was provided, it must apply to the first
158
+ # input
159
+ if i > 0 and args.output_file:
160
+ current_file_args.output_file = None
161
+
162
+ book = parse_txt(current_file_args)
163
+ writer = TypWriter(book, current_file_args)
164
+ writer.write()
165
+
166
+ # close the file stream if it was opened by argparse.FileType and is
167
+ # not sys.stdin.
168
+ if current_input_stream is not sys.stdin:
169
+ current_input_stream.close()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: txt2ebook
3
- Version: 0.1.154
3
+ Version: 0.1.155
4
4
  Summary: CLI tool to convert txt file to ebook format
5
5
  Keywords: cjk,ebook,epub,gmi,latex,md,pdf,txt,typst
6
6
  Author-email: Kian-Meng Ang <kianmeng@cpan.org>
@@ -37,16 +37,16 @@ txt2ebook/models/chapter.py,sha256=6YvUDHzR6amGMZgkQl_xHWrYZUmlfpF7mnDLilG2BpA,1
37
37
  txt2ebook/models/volume.py,sha256=koz1KfWjvGWLFbmGEQlZ23frsP93cDsuBMySYBHiXm8,1597
38
38
  txt2ebook/subcommands/__init__.py,sha256=ldhzvsrMsR8lZmhZef77JFz0jValpV3pytFfwJSkjls,1146
39
39
  txt2ebook/subcommands/env.py,sha256=gEzra4b6guy7pRZUTCWX1_eiR7JmrtR1Z-J-vxljvMY,1549
40
- txt2ebook/subcommands/epub.py,sha256=_obM1_fvVBPHOBXBOCYK8nyJadBX3_gOn9kaXA5HipA,3570
40
+ txt2ebook/subcommands/epub.py,sha256=oVk00rypqN53UAOIYhOofkAPbjrdlvkszLDIdVqexvE,4706
41
41
  txt2ebook/subcommands/gmi.py,sha256=ANnPg-RFsylTo44fUzFOSHN1fC3Ce82gBzrv-sBv5fU,3318
42
42
  txt2ebook/subcommands/massage.py,sha256=cjeee4wJJ6xPV76efnlWRVdeVkEtJYIBDaKhFMPjKTg,14643
43
43
  txt2ebook/subcommands/md.py,sha256=PmIqrqrnzLywvN4qTkle0V9N3FTIJGRWpC0Xbk76B5o,3329
44
44
  txt2ebook/subcommands/parse.py,sha256=xjhW8I9zS5DL3n3m04RyFofgci-6-_L6aF3d4N7c7M4,2938
45
45
  txt2ebook/subcommands/pdf.py,sha256=1JQtpugzAIaho6G3CK1rGYk74hotAexXZxPH9PHpRps,2980
46
- txt2ebook/subcommands/tex.py,sha256=59Bzl67VSHMZS9BtU9zZDmKwsd6cQGoFfuGftAz9efc,3438
47
- txt2ebook/subcommands/typ.py,sha256=PoyozIueAvNL3yHHpS9NnMTMVV4ppUBX37SWGXd5Zhg,3680
48
- txt2ebook-0.1.154.dist-info/entry_points.txt,sha256=AFikuCV6fqf8_GHwsvWuo9jTGNrCkWY1TJWk5GfMWSk,71
49
- txt2ebook-0.1.154.dist-info/licenses/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
50
- txt2ebook-0.1.154.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
51
- txt2ebook-0.1.154.dist-info/METADATA,sha256=WGdRZ8a87vsX3wDZPFMXDwVrWCCNDrR-eCHzCf1BGRI,4700
52
- txt2ebook-0.1.154.dist-info/RECORD,,
46
+ txt2ebook/subcommands/tex.py,sha256=8XqTV5GsOEr7sGSLUJB-B1KefIMxW3_BDq_Jm96Bt1Y,4369
47
+ txt2ebook/subcommands/typ.py,sha256=xeJ_cPmyq_uouUBiH2kbcscckHLqewPmu9j0WO36sXY,4814
48
+ txt2ebook-0.1.155.dist-info/entry_points.txt,sha256=AFikuCV6fqf8_GHwsvWuo9jTGNrCkWY1TJWk5GfMWSk,71
49
+ txt2ebook-0.1.155.dist-info/licenses/LICENSE.md,sha256=tGtFDwxWTjuR9syrJoSv1Hiffd2u8Tu8cYClfrXS_YU,31956
50
+ txt2ebook-0.1.155.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
51
+ txt2ebook-0.1.155.dist-info/METADATA,sha256=m8QqLQ3zSn6ySbwjopHdbc0kswDZzb6JZUXGSzRVvz8,4700
52
+ txt2ebook-0.1.155.dist-info/RECORD,,