summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Weller <ianweller@gmail.com>2008-10-01 00:01:38 -0500
committerIan Weller <ianweller@gmail.com>2008-10-01 00:01:38 -0500
commitd8894e95048d143c09888d1cc964882372260036 (patch)
tree3c6fa8840aeec7fdffa91153e8b8554c2b7fc66c
parentd0ace2f9c69a5d897e748060f2421e9b60d6175c (diff)
downloadfedora-business-cards-d8894e95048d143c09888d1cc964882372260036.zip
fedora-business-cards-d8894e95048d143c09888d1cc964882372260036.tar.gz
fedora-business-cards-d8894e95048d143c09888d1cc964882372260036.tar.xz
Add --svg
-rw-r--r--fedora_business_cards/export.py10
-rw-r--r--fedora_business_cards/frontend.py16
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)