diff options
-rw-r--r-- | fedora_business_cards/__init__.py | 29 | ||||
-rw-r--r-- | fedora_business_cards/config.ini | 3 | ||||
-rw-r--r-- | fedora_business_cards/config.py | 40 | ||||
-rw-r--r-- | fedora_business_cards/exceptions.py | 37 | ||||
-rw-r--r-- | fedora_business_cards/export.py | 52 | ||||
-rw-r--r-- | fedora_business_cards/frontend/__init__.py | 20 | ||||
-rw-r--r-- | fedora_business_cards/frontend/cmdline.py | 21 | ||||
-rw-r--r-- | fedora_business_cards/generate.py | 63 | ||||
-rw-r--r-- | fedora_business_cards/information.py | 61 | ||||
-rw-r--r-- | templates/back-northamerica.svg (renamed from templates/back.svg) | 0 | ||||
-rw-r--r-- | templates/bleed16-under.svg | 102 | ||||
-rw-r--r-- | templates/front-northamerica.svg (renamed from templates/front-template.svg) | 0 |
12 files changed, 326 insertions, 102 deletions
diff --git a/fedora_business_cards/__init__.py b/fedora_business_cards/__init__.py new file mode 100644 index 0000000..07a90f4 --- /dev/null +++ b/fedora_business_cards/__init__.py @@ -0,0 +1,29 @@ +### +# fedora-business-cards - for rendering Fedora contributor business cards +# Copyright (C) 2008 Ian Weller <ianweller@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +### + +""" +The Fedora business cards generator will generate business cards for Fedora +contributors. It connects to FAS to retrieve user information and lays it out on +a SVG, then exports that to a PDF and PNG. Different templates are/will be +available for different business card sizes, or different requirements by +different companies. +""" + +__all__ = ('config', 'exceptions', 'export', 'frontend', 'generate', + 'information') diff --git a/fedora_business_cards/config.ini b/fedora_business_cards/config.ini new file mode 100644 index 0000000..eff2723 --- /dev/null +++ b/fedora_business_cards/config.ini @@ -0,0 +1,3 @@ +[location] +; this can be relative to the directory with config.py in it +templates = ../templates diff --git a/fedora_business_cards/config.py b/fedora_business_cards/config.py new file mode 100644 index 0000000..259b4db --- /dev/null +++ b/fedora_business_cards/config.py @@ -0,0 +1,40 @@ +### +# fedora-business-cards - for rendering Fedora contributor business cards +# Copyright (C) 2008 Ian Weller <ianweller@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +### + +""" +Controls the locations of configuration files, and imports configurations from +all those files in a specific order. +""" + +import iniparse +import os + +# locations, in reverse-order of priority +LOCATIONS = ['./config.ini', + '/usr/share/fedora-business-cards/config.ini', + '/etc/fedora-business-cards.ini', + os.getenv('HOME')+'/.fedora-business-cards.ini'] + +parser = iniparse.ConfigParser() + +# import the configs +for i in LOCATIONS: + parser.read(LOCATIONS[i]) + +__all__ = ('parser') diff --git a/fedora_business_cards/exceptions.py b/fedora_business_cards/exceptions.py new file mode 100644 index 0000000..9e87efb --- /dev/null +++ b/fedora_business_cards/exceptions.py @@ -0,0 +1,37 @@ +### +# fedora-business-cards - for rendering Fedora contributor business cards +# Copyright (C) 2008 Ian Weller <ianweller@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +### + +""" +Miscellaneous exceptions used specifically for this module. +""" + + +class NoGPGKeyError(StandardError): + """ + Exception used when the GPG key for a specific ID isn't available on the + system; usually used when we can't derive the fingerprint from the ID + because we don't have the key. + """ + + def __init__(self, keyid): + StandardError.__init__(self) + self.keyid = keyid + + def __str__(self): + return self.keyid diff --git a/fedora_business_cards/export.py b/fedora_business_cards/export.py new file mode 100644 index 0000000..d4b6c37 --- /dev/null +++ b/fedora_business_cards/export.py @@ -0,0 +1,52 @@ +### +# fedora-business-cards - for rendering Fedora contributor business cards +# Copyright (C) 2008 Ian Weller <ianweller@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +### + +""" +Functions to export cards from SVGs. +""" + +# Thanks much to Jef Spaleta for this code. + +import rsvg +import cairo + +if not cairo.HAS_PDF_SURFACE: + raise SystemExit('cairo was not compiled with PDF support') +if not cairo.HAS_PNG_FUNCTIONS: + raise SystemExit('cairo was not compiled with PNG support') + + +def svg_to_pdf_png(pdfname, pngname, xmlstring, dpi=300): + """ + Export an SVG to both a PDF and PNG. + pngname = location of PNG file to export to + pdfname = location of pdf file to export to + xmlstring = the SVG XML to export + dpi = DPI to export PNG with (default: 300) + """ + svg = rsvg.Handle(data=xmlstring) + pdffile = file(pdfname, 'w') + width = int(svg.props.width/90.*dpi) + height = int(svg.props.height/90.*dpi) + surface = cairo.PDFSurface(pdffile, width, height) + ctx = cairo.Context(surface) + svg.render_cairo(ctx) + surface.write_to_png(pngname) + surface.finish() + pdffile.close() diff --git a/fedora_business_cards/frontend/__init__.py b/fedora_business_cards/frontend/__init__.py new file mode 100644 index 0000000..5fba6d4 --- /dev/null +++ b/fedora_business_cards/frontend/__init__.py @@ -0,0 +1,20 @@ +### +# fedora-business-cards - for rendering Fedora contributor business cards +# Copyright (C) 2008 Ian Weller <ianweller@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +### + +__all__ = ('frontend') diff --git a/fedora_business_cards/frontend/cmdline.py b/fedora_business_cards/frontend/cmdline.py new file mode 100644 index 0000000..8144e8e --- /dev/null +++ b/fedora_business_cards/frontend/cmdline.py @@ -0,0 +1,21 @@ +### +# fedora-business-cards - for rendering Fedora contributor business cards +# Copyright (C) 2008 Ian Weller <ianweller@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +### + +from optparse import OptionParser + diff --git a/fedora_business_cards/generate.py b/fedora_business_cards/generate.py new file mode 100644 index 0000000..5a92039 --- /dev/null +++ b/fedora_business_cards/generate.py @@ -0,0 +1,63 @@ +### +# fedora-business-cards - for rendering Fedora contributor business cards +# Copyright (C) 2008 Ian Weller <ianweller@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +### + +""" +Generates both sides of the business card. +""" + +from xml.dom import minidom +from . import config + + +def find_node(doc_node, tag_name, attribute_name, attribute_value): + """ + Gets a specific node from a DOM tree with a certain tag name, attribute + name, and attribute value. + """ + # thanks, mizmo + elements = doc_node.getElementsByTagName(tag_name) + for element in elements: + if element.hasAttribute(attribute_name): + if element.getAttribute(attribute_name) == attribute_value: + return element + + +def gen_front(name, title, lines, template="northamerica"): + """ + Generates the front of the business card. + """ + dom = minidom.parse(config.parser.get('location', 'templates')+'/front-'+\ + template+'.svg') + namenode = find_node(dom, 'text', 'id', 'fullname') + namenode.appendChild(dom.createTextNode(name)) + titlenode = find_node(dom, 'text', 'id', 'title') + titlenode.appendChild(dom.createTextNode(title)) + for i in range(6): + node = find_node(dom, 'tspan', 'id', 'line%d' % (i+1)) + node.appendChild(dom.createTextNode(lines[i])) + return dom.toxml() + + +def gen_back(template="northamerica"): + """ + Generates the back of the business card. + """ + dom = minidom.parse(config.parser.get('location', 'templates')+'/back-'+\ + template+'.svg') + return dom.toxml() diff --git a/fedora_business_cards/information.py b/fedora_business_cards/information.py new file mode 100644 index 0000000..9fbaf48 --- /dev/null +++ b/fedora_business_cards/information.py @@ -0,0 +1,61 @@ +### +# fedora-business-cards - for rendering Fedora contributor business cards +# Copyright (C) 2008 Ian Weller <ianweller@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +### + +""" +Assembles information about a person from FAS and their GPG key. +""" + +from fedora.client.fas2 import AccountSystem +import gpgme +import re +from . import exceptions + + +def get_gpg_fingerprint(keyid): + """ + Gets the GPG fingerprint from the key ID. + """ + ctx = gpgme.Context() + try: + key = ctx.get_key(keyid) + except: + raise exceptions.NoGPGKeyError(keyid) + fpr = key.subkeys[0].fpr + return ' '.join([i for i in re.split('([A-Z0-9]{4})', fpr) if i]) + + +def get_information(loginname, password, username=None): + """ + Fetches information about a certain contributor from FAS. + loginname: username to *login with* on FAS + password: password to loginname + username: username to get information on (default: same as loginname) + """ + if username == None: + username = loginname + fas = AccountSystem(username=loginname, password=password) + userinfo = fas.person_by_username(username) + infodict = {} + infodict['name'] = userinfo["human_name"] + infodict['title'] = "Fedora Project Contributor" + infodict['email'] = "%s@fedoraproject.org" % username + infodict['phone'] = "(919) 424-0063 x 5%s" % userinfo['id'] + infodict['url'] = 'fedoraproject.org' + infodict['gpgid'] = userinfo['gpg_keyid'] + return infodict diff --git a/templates/back.svg b/templates/back-northamerica.svg index 246b883..246b883 100644 --- a/templates/back.svg +++ b/templates/back-northamerica.svg diff --git a/templates/bleed16-under.svg b/templates/bleed16-under.svg deleted file mode 100644 index c29ec21..0000000 --- a/templates/bleed16-under.svg +++ /dev/null @@ -1,102 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<!-- Created with Inkscape (http://www.inkscape.org/) --> -<svg - xmlns:i="http://ns.adobe.com/AdobeIllustrator/10.0/" - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:cc="http://creativecommons.org/ns#" - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - xmlns:xlink="http://www.w3.org/1999/xlink" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - height="191.39999" - id="svg2" - inkscape:export-filename="/home/ianweller/art/fedora-business-cards/bizcard07-foundations.png" - inkscape:export-xdpi="90" - inkscape:export-ydpi="90" - inkscape:output_extension="org.inkscape.output.svg.inkscape" - inkscape:version="0.46" - sodipodi:docname="out.svg" - sodipodi:version="0.32" - version="1.0" - width="326.39999"> - <metadata - id="metadata42"> - <rdf:RDF> - <cc:Work - rdf:about=""> - <dc:format>image/svg+xml</dc:format> - <dc:type - rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - </cc:Work> - </rdf:RDF> - </metadata> - <sodipodi:namedview - bordercolor="#666666" - borderopacity="1.0" - gridtolerance="10.0" - guidetolerance="10.0" - id="base" - inkscape:current-layer="svg2" - inkscape:cx="217.68523" - inkscape:cy="81.731301" - inkscape:document-units="in" - inkscape:guide-bbox="true" - inkscape:pageopacity="0.0" - inkscape:pageshadow="2" - inkscape:snap-bbox="false" - inkscape:snap-nodes="true" - inkscape:window-height="480" - inkscape:window-width="640" - inkscape:zoom="1.9881" - objecttolerance="10.0" - pagecolor="#ffffff" - showgrid="false" - showguides="false" - units="px"> - <sodipodi:guide - id="guide4103" - orientation="1,0" - position="18,209.02957" /> - <sodipodi:guide - id="guide4105" - orientation="0,1" - position="-27.948244,18" /> - <sodipodi:guide - id="guide4107" - orientation="0,1" - position="-20.961183,162" /> - <sodipodi:guide - id="guide4109" - orientation="1,0" - position="279,112.95749" /> - </sodipodi:namedview> - <defs - id="defs4"> - <inkscape:perspective - id="perspective44" - inkscape:persp3d-origin="157.5 : 60 : 1" - inkscape:vp_x="0 : 90 : 1" - inkscape:vp_y="0 : 1000 : 0" - inkscape:vp_z="315 : 90 : 1" - sodipodi:type="inkscape:persp3d" /> - <foreignObject - height="1" - id="foreignObject8" - requiredExtensions="http://ns.adobe.com/AdobeIllustrator/10.0/" - width="1" - x="0" - y="0"> - <i:pgfRef - xlink:href="#adobe_illustrator_pgf" /> - </foreignObject> - </defs> - <rect - height="191.39999" - id="rect3330" - style="fill:#3c6eb4;fill-opacity:1;stroke:none;stroke-width:0.89999998;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" - width="23.700001" - x="302.70001" - y="0" /> -</svg> diff --git a/templates/front-template.svg b/templates/front-northamerica.svg index c2a7a98..c2a7a98 100644 --- a/templates/front-template.svg +++ b/templates/front-northamerica.svg |