33For further information please check the file README.txt!
44"""
55
6- import sys
76import argparse
7+ import sys
88import textwrap
99from datetime import datetime
1010from os .path import dirname , basename , splitext , exists
@@ -19,14 +19,14 @@ def svg2pdf(path, outputPat=None):
1919
2020 # derive output filename from output pattern
2121 file_info = {
22- ' dirname' : dirname (path ) or '.' ,
23- ' basename' : basename (path ),
24- ' base' : basename (splitext (path )[0 ]),
25- ' ext' : splitext (path )[1 ],
26- ' now' : datetime .now (),
27- ' format' : ' pdf'
22+ " dirname" : dirname (path ) or "." ,
23+ " basename" : basename (path ),
24+ " base" : basename (splitext (path )[0 ]),
25+ " ext" : splitext (path )[1 ],
26+ " now" : datetime .now (),
27+ " format" : " pdf" ,
2828 }
29- out_pattern = outputPat or ' %(dirname)s/%(base)s.%(format)s'
29+ out_pattern = outputPat or " %(dirname)s/%(base)s.%(format)s"
3030 # allow classic %%(name)s notation
3131 out_path = out_pattern % file_info
3232 # allow also newer {name} notation
@@ -36,7 +36,7 @@ def svg2pdf(path, outputPat=None):
3636 try :
3737 drawing = svglib .svg2rlg (path )
3838 except :
39- print (' Rendering failed.' )
39+ print (" Rendering failed." )
4040 raise
4141
4242 # save converted file
@@ -46,24 +46,26 @@ def svg2pdf(path, outputPat=None):
4646
4747# command-line usage stuff
4848def main ():
49- ext = 'pdf'
49+ """Main entry point for the CLI."""
50+ ext = "pdf"
5051 ext_caps = ext .upper ()
5152 args = dict (
5253 prog = basename (sys .argv [0 ]),
5354 version = svglib .__version__ ,
5455 author = svglib .__author__ ,
5556 license = svglib .__license__ ,
5657 copyleft_year = str (datetime .now ().year ),
57- ts_pattern = "{{dirname}}/out-" \
58- "{{now.hour}}-{{now.minute}}-{{now.second}}-" \
59- "%(base)s" ,
58+ ts_pattern = "{{dirname}}/out-"
59+ "{{now.hour}}-{{now.minute}}-{{now.second}}-"
60+ "%(base)s" ,
6061 ext = ext ,
61- ext_caps = ext_caps
62+ ext_caps = ext_caps ,
6263 )
63- args ['ts_pattern' ] += ('.%s' % args ['ext' ])
64- desc = '{prog} v. {version}\n ' .format (** args )
65- desc += 'A converter from SVG to {} (via ReportLab Graphics)\n ' .format (ext_caps )
66- epilog = textwrap .dedent ('''\
64+ args ["ts_pattern" ] += ".%s" % args ["ext" ]
65+ desc = "{prog} v. {version}\n " .format (** args )
66+ desc += "A converter from SVG to {} (via ReportLab Graphics)\n " .format (ext_caps )
67+ epilog = textwrap .dedent (
68+ """\
6769 examples:
6870 # convert path/file.svg to path/file.{ext}
6971 {prog} path/file.svg
@@ -86,27 +88,34 @@ def main():
8688 https://github.com/deeplook/svglib
8789
8890 Copyleft by {author}, 2008-{copyleft_year} ({license}):
89- https://www.gnu.org/licenses/lgpl-3.0.html''' .format (** args ))
91+ https://www.gnu.org/licenses/lgpl-3.0.html""" .format (
92+ ** args
93+ )
94+ )
9095 p = argparse .ArgumentParser (
9196 description = desc ,
9297 epilog = epilog ,
93- formatter_class = argparse .RawDescriptionHelpFormatter
98+ formatter_class = argparse .RawDescriptionHelpFormatter ,
9499 )
95100
96- p .add_argument ('-v' , '--version' ,
97- help = ' Print version number and exit.' ,
98- action = 'store_true' )
101+ p .add_argument (
102+ "-v" , "--version" , help = " Print version number and exit." , action = "store_true"
103+ )
99104
100- p .add_argument ('-o' , '--output' ,
101- metavar = 'PATH_PAT' ,
102- help = 'Set output path (incl. the placeholders: dirname, basename,'
103- 'base, ext, now) in both, %%(name)s and {name} notations.'
105+ p .add_argument (
106+ "-o" ,
107+ "--output" ,
108+ metavar = "PATH_PAT" ,
109+ help = "Set output path (incl. the placeholders: dirname, basename,"
110+ "base, ext, now) in both, %%(name)s and {name} notations." ,
104111 )
105112
106- p .add_argument ('input' ,
107- metavar = 'PATH' ,
108- nargs = '*' ,
109- help = 'Input SVG file path with extension .svg or .svgz.' )
113+ p .add_argument (
114+ "input" ,
115+ metavar = "PATH" ,
116+ nargs = "*" ,
117+ help = "Input SVG file path with extension .svg or .svgz." ,
118+ )
110119
111120 args = p .parse_args ()
112121
0 commit comments