From d8894e95048d143c09888d1cc964882372260036 Mon Sep 17 00:00:00 2001 From: Ian Weller Date: Wed, 1 Oct 2008 00:01:38 -0500 Subject: Add --svg --- fedora_business_cards/export.py | 10 ++++++++++ fedora_business_cards/frontend.py | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/fedora_business_cards/export.py b/fedora_business_cards/export.py index 597c61a..c6d8a86 100644 --- a/fedora_business_cards/export.py +++ b/fedora_business_cards/export.py @@ -24,6 +24,15 @@ Functions to export cards from SVGs. import subprocess +def svg_to_file(xmlstring, filename): + """ + Write an SVG to a file. + """ + f = file(filename, 'w') + f.write(xmlstring.encode('utf-8')) + f.close() + return True + def svg_to_pdf_png(xmlstring, filename, format='png', dpi=300): """ Export an SVG to either a PDF or PNG. @@ -45,3 +54,4 @@ def svg_to_pdf_png(xmlstring, filename, format='png', dpi=300): sp.communicate(stdin) else: raise Exception("Invalid file format requested") + return True diff --git a/fedora_business_cards/frontend.py b/fedora_business_cards/frontend.py index 283b495..c9e47c7 100644 --- a/fedora_business_cards/frontend.py +++ b/fedora_business_cards/frontend.py @@ -60,6 +60,8 @@ def cmdline(): action="store_const", help="Export as PDF") parser.add_option("--png", dest="output", default="png", const="png", action="store_const", help="Export as PNG (default)") + parser.add_option("--svg", dest="output", default="png", const="svg", + action="store_const", help="Export as SVG") options = parser.parse_args()[0] # check what templates are available templates_dir = config.parser.get('location', 'templates') @@ -145,9 +147,15 @@ def cmdline(): lines[int(lineno)] = newdata # generate front of business card xml = generate.gen_front(name, title, lines, options.template) - export.svg_to_pdf_png(xml, options.username+'-front.'+options.output, - options.output, options.dpi) + if options.output == "svg": + export.svg_to_file(xml, options.username+'-front.'+options.output) + else: + export.svg_to_pdf_png(xml, options.username+'-front.'+options.output, + options.output, options.dpi) # generate back of business card xml = generate.gen_back(options.template) - export.svg_to_pdf_png(xml, options.username+'-back.'+options.output, - options.output, options.dpi) + if options.output == "svg": + export.svg_to_file(xml, options.username+'-back.'+options.output) + else: + export.svg_to_pdf_png(xml, options.username+'-back.'+options.output, + options.output, options.dpi) -- cgit