summaryrefslogtreecommitdiffstats
path: root/fedora_business_cards
diff options
context:
space:
mode:
authorIan Weller <ianweller@gmail.com>2008-09-28 15:46:02 -0500
committerIan Weller <ianweller@gmail.com>2008-09-28 15:46:02 -0500
commit9ecf23c0166871e4147533147e14fc488c011f92 (patch)
tree2578c2075fe26b3cf068ae53606c63d1ea65026e /fedora_business_cards
parentd6519bd2f246221e1d563700656736308cdcdbe9 (diff)
downloadfedora-business-cards-9ecf23c0166871e4147533147e14fc488c011f92.tar.gz
fedora-business-cards-9ecf23c0166871e4147533147e14fc488c011f92.tar.xz
fedora-business-cards-9ecf23c0166871e4147533147e14fc488c011f92.zip
Do all sorts of fun reorganization
Diffstat (limited to 'fedora_business_cards')
-rw-r--r--fedora_business_cards/__init__.py29
-rw-r--r--fedora_business_cards/config.ini3
-rw-r--r--fedora_business_cards/config.py40
-rw-r--r--fedora_business_cards/exceptions.py37
-rw-r--r--fedora_business_cards/export.py52
-rw-r--r--fedora_business_cards/frontend/__init__.py20
-rw-r--r--fedora_business_cards/frontend/cmdline.py21
-rw-r--r--fedora_business_cards/generate.py63
-rw-r--r--fedora_business_cards/information.py61
9 files changed, 326 insertions, 0 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