1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
###
# 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.
###
"""
Frontend to the business card generator. Theoretically expandable to GUI and
whatnot, but for now just has a command-line interface.
"""
from optparse import OptionParser
from . import config
import os
import sys
def cmdline():
"""
Command-line interface to business card generator. Takes no arguments; uses
optparser.OptionParser instead.
"""
# setup option parser
parser = OptionParser()
parser.usage = "%prog [options] [outfile]"
parser.add_option("-d", "--dpi", dest="dpi", default=300, type="int",
help="DPI of exported file")
parser.add_option("-t", "--template", dest="template",
default="northamerica", help="Name of template to use, "+\
"run with --list-templates to see a list")
parser.add_option("--list-templates", action="store_true", default=False,
dest="listtemplates", help="List available templates")
parser.add_option("-u", "--username", dest="username", default="",
help="If set, use a different name than the one logged"+\
" in with to fill out business card information")
parser.add_option("--pdf", dest="output", default="png", const="pdf",
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)")
options = parser.parse_args()[0]
# check what templates are available
templates_dir = config.parser.get('location', 'templates')
contents = os.listdir(templates_dir)
checked_once = []
available_templates = []
for i in contents:
if i[-4:] == '.svg':
if i[:6] == 'front-':
name = i[6:-4]
elif i[:5] == 'back-':
name = i[5:-4]
else:
continue
if name in checked_once:
available_templates.append(name)
else:
checked_once.append(name)
if options.listtemplates:
print "Available templates:"
for i in available_templates:
print " %s" % i
sys.exit(0)
if options.template not in available_templates:
print "%s not an available template" % options.template
sys.exit(1)
|