Add output dir and verbose option to txt2rst
This commit is contained in:
@ -157,7 +157,7 @@ $(RSTDIR)/%.rst : src/%.txt $(TXT2RST)
|
|||||||
@(\
|
@(\
|
||||||
mkdir -p $(RSTDIR) ; \
|
mkdir -p $(RSTDIR) ; \
|
||||||
. $(VENV)/bin/activate ;\
|
. $(VENV)/bin/activate ;\
|
||||||
txt2rst $< > $@ ;\
|
txt2rst -v $< > $@ ;\
|
||||||
deactivate ;\
|
deactivate ;\
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -662,13 +662,14 @@ class TxtConverter:
|
|||||||
parser = self.get_argument_parser()
|
parser = self.get_argument_parser()
|
||||||
parsed_args = parser.parse_args(args)
|
parsed_args = parser.parse_args(args)
|
||||||
|
|
||||||
write_to_files = len(parsed_args.files) > 1
|
write_to_files = parsed_args.output_dir or (len(parsed_args.files) > 1)
|
||||||
|
|
||||||
for filename in parsed_args.files:
|
for filename in parsed_args.files:
|
||||||
if parsed_args.skip_files and filename in parsed_args.skip_files:
|
if parsed_args.skip_files and filename in parsed_args.skip_files:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with open(filename, 'r') as f:
|
with open(filename, 'r') as f:
|
||||||
|
if parsed_args.verbose:
|
||||||
print("Converting", filename, "...", file=err)
|
print("Converting", filename, "...", file=err)
|
||||||
content = f.read()
|
content = f.read()
|
||||||
converter = self.create_converter(parsed_args)
|
converter = self.create_converter(parsed_args)
|
||||||
@ -683,6 +684,9 @@ class TxtConverter:
|
|||||||
result = msg
|
result = msg
|
||||||
|
|
||||||
if write_to_files:
|
if write_to_files:
|
||||||
|
if parsed_args.output_dir:
|
||||||
|
output_filename = os.path.join(parsed_args.output_dir, os.path.basename(self.get_output_filename(filename)))
|
||||||
|
else:
|
||||||
output_filename = self.get_output_filename(filename)
|
output_filename = self.get_output_filename(filename)
|
||||||
with open(output_filename, "w+t") as outfile:
|
with open(output_filename, "w+t") as outfile:
|
||||||
outfile.write(result)
|
outfile.write(result)
|
||||||
@ -698,6 +702,8 @@ class Txt2HtmlConverter(TxtConverter):
|
|||||||
'HTML file. useful when set of HTML files'
|
'HTML file. useful when set of HTML files'
|
||||||
' will be converted to PDF')
|
' will be converted to PDF')
|
||||||
parser.add_argument('-x', metavar='file-to-skip', dest='skip_files', action='append')
|
parser.add_argument('-x', metavar='file-to-skip', dest='skip_files', action='append')
|
||||||
|
parser.add_argument('--verbose', '-v', dest='verbose', action='store_true')
|
||||||
|
parser.add_argument('--output-directory', '-o', dest='output_dir')
|
||||||
parser.add_argument('--generate-title', dest='create_title', action='store_true', help='add HTML head page'
|
parser.add_argument('--generate-title', dest='create_title', action='store_true', help='add HTML head page'
|
||||||
'title based on first '
|
'title based on first '
|
||||||
'h1,h2,h3,h4... element')
|
'h1,h2,h3,h4... element')
|
||||||
|
|||||||
@ -395,6 +395,8 @@ class Txt2RstConverter(TxtConverter):
|
|||||||
parser = argparse.ArgumentParser(description='converts a text file with simple formatting & markup into '
|
parser = argparse.ArgumentParser(description='converts a text file with simple formatting & markup into '
|
||||||
'Restructured Text for Sphinx.')
|
'Restructured Text for Sphinx.')
|
||||||
parser.add_argument('-x', metavar='file-to-skip', dest='skip_files', action='append')
|
parser.add_argument('-x', metavar='file-to-skip', dest='skip_files', action='append')
|
||||||
|
parser.add_argument('--verbose', '-v', dest='verbose', action='store_true')
|
||||||
|
parser.add_argument('--output-directory', '-o', dest='output_dir')
|
||||||
parser.add_argument('files', metavar='file', nargs='+', help='one or more files to convert')
|
parser.add_argument('files', metavar='file', nargs='+', help='one or more files to convert')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user