- start using argparse instead of optionparser
- make all code conform to pep8 once more - add a unit test to check for pep8 compliance - delete old ez_setup
This commit is contained in:
parent
669fa4c7e6
commit
b70bd37d80
@ -4,6 +4,7 @@ python:
|
||||
# command to install dependencies
|
||||
install:
|
||||
- pip install -U setuptools
|
||||
- pip install -U pycodestyle
|
||||
- pip install .
|
||||
# command to run tests
|
||||
script: nosetests
|
||||
|
||||
@ -5,6 +5,7 @@ from zipfile import ZipFile,ZIP_DEFLATED
|
||||
prefix = 'generated/sumpfork_dominion_tabs_'
|
||||
postfix = 'v' + __version__ + '.pdf'
|
||||
|
||||
|
||||
def doit(args, main):
|
||||
args = args + ' ' + prefix + main + postfix
|
||||
args = args.split()
|
||||
@ -13,9 +14,9 @@ def doit(args,main):
|
||||
domdiv.main(args, '.')
|
||||
return fname
|
||||
|
||||
|
||||
argsets = [
|
||||
('',''),
|
||||
('--orientation=vertical','vertical_'),
|
||||
('', ''), ('--orientation=vertical', 'vertical_'),
|
||||
('--papersize=A4', 'A4_'),
|
||||
('--papersize=A4 --orientation=vertical', 'vertical_A4_'),
|
||||
('--size=sleeved', 'sleeved_'),
|
||||
@ -23,11 +24,12 @@ argsets = [
|
||||
]
|
||||
additional = ['--expansion_dividers']
|
||||
|
||||
fnames = [doit(args[0] + ' ' + ' '.join(additional),args[1]) for args in argsets]
|
||||
fnames = [doit(args[0] + ' ' + ' '.join(additional), args[1])
|
||||
for args in argsets]
|
||||
print fnames
|
||||
|
||||
zip = ZipFile('generated/sumpfork_dominion_tabs_v' + __version__ + '.zip','w',ZIP_DEFLATED)
|
||||
zip = ZipFile('generated/sumpfork_dominion_tabs_v' + __version__ + '.zip', 'w',
|
||||
ZIP_DEFLATED)
|
||||
for f in fnames:
|
||||
zip.write(f)
|
||||
zip.close()
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
from optparse import OptionParser
|
||||
import os
|
||||
import codecs
|
||||
import json
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
import reportlab.lib.pagesizes as pagesizes
|
||||
from reportlab.lib.units import cm
|
||||
@ -12,7 +12,8 @@ from draw import DividerDrawer
|
||||
|
||||
LOCATION_CHOICES = ["tab", "body-top", "hide"]
|
||||
NAME_ALIGN_CHOICES = ["left", "right", "centre", "edge"]
|
||||
TAB_SIDE_CHOICES = ["left", "right", "left-alternate", "right-alternate", "full"]
|
||||
TAB_SIDE_CHOICES = ["left", "right", "left-alternate", "right-alternate",
|
||||
"full"]
|
||||
TEXT_CHOICES = ["card", "rules", "blank"]
|
||||
|
||||
|
||||
@ -21,137 +22,242 @@ def add_opt(options, option, value):
|
||||
setattr(options, option, value)
|
||||
|
||||
|
||||
def parse_opts(argstring):
|
||||
parser = OptionParser()
|
||||
parser.add_option("--back_offset", type="float", dest="back_offset", default=0,
|
||||
def parse_opts(arglist):
|
||||
parser = argparse.ArgumentParser(description="Generate Dominion Dividers")
|
||||
parser.add_argument('--outfile', default="dominion_dividers.pdf")
|
||||
parser.add_argument(
|
||||
"--back_offset",
|
||||
type=float,
|
||||
dest="back_offset",
|
||||
default=0,
|
||||
help="Points to offset the back page to the right; needed for some printers")
|
||||
parser.add_option("--back_offset_height", type="float", dest="back_offset_height", default=0,
|
||||
parser.add_argument(
|
||||
"--back_offset_height",
|
||||
type=float,
|
||||
dest="back_offset_height",
|
||||
default=0,
|
||||
help="Points to offset the back page upward; needed for some printers")
|
||||
parser.add_option("--orientation", type="choice", choices=["horizontal", "vertical"],
|
||||
dest="orientation", default="horizontal",
|
||||
parser.add_argument("--orientation",
|
||||
choices=["horizontal", "vertical"],
|
||||
dest="orientation",
|
||||
default="horizontal",
|
||||
help="horizontal or vertical, default:horizontal")
|
||||
parser.add_option("--sleeved", action="store_true",
|
||||
dest="sleeved", help="use --size=sleeved instead")
|
||||
parser.add_option("--size", type="string", dest="size", default='normal',
|
||||
parser.add_argument("--sleeved",
|
||||
action="store_true",
|
||||
dest="sleeved",
|
||||
help="use --size=sleeved instead")
|
||||
parser.add_argument(
|
||||
"--size",
|
||||
dest="size",
|
||||
default='normal',
|
||||
help="'<%f>x<%f>' (size in cm), or 'normal' = '9.1x5.9', or 'sleeved' = '9.4x6.15'")
|
||||
parser.add_option("--minmargin", type="string", dest="minmargin", default="1x1",
|
||||
parser.add_argument(
|
||||
"--minmargin",
|
||||
dest="minmargin",
|
||||
default="1x1",
|
||||
help="'<%f>x<%f>' (size in cm, left/right, top/bottom), default: 1x1")
|
||||
parser.add_option("--papersize", type="string", dest="papersize", default=None,
|
||||
parser.add_argument("--papersize",
|
||||
dest="papersize",
|
||||
default=None,
|
||||
help="'<%f>x<%f>' (size in cm), or 'A4', or 'LETTER'")
|
||||
parser.add_option("--front", type="choice", choices=TEXT_CHOICES,
|
||||
dest="text_front", default="card",
|
||||
parser.add_argument(
|
||||
"--front",
|
||||
choices=TEXT_CHOICES,
|
||||
dest="text_front",
|
||||
default="card",
|
||||
help="Text to print on the front of the divider. choices: card, rules, blank;"
|
||||
" 'card' will print the text from the game card;"
|
||||
" 'rules' will print additional rules for the game card;"
|
||||
" 'blank' will not print text on the divider;"
|
||||
" default:card")
|
||||
parser.add_option("--back", type="choice", choices=TEXT_CHOICES + ["none"],
|
||||
dest="text_back", default="rules",
|
||||
parser.add_argument(
|
||||
"--back",
|
||||
choices=TEXT_CHOICES + ["none"],
|
||||
dest="text_back",
|
||||
default="rules",
|
||||
help="Text to print on the back of the divider. choices: card, rules, blank, none;"
|
||||
" 'card' will print the text from the game card;"
|
||||
" 'rules' will print additional rules for the game card;"
|
||||
" 'blank' will not print text on the divider;"
|
||||
" 'none' will prevent the back pages from printing;"
|
||||
" default:rules")
|
||||
parser.add_option("--tab_name_align", type="choice", choices=NAME_ALIGN_CHOICES + ["center"],
|
||||
dest="tab_name_align", default="left",
|
||||
parser.add_argument(
|
||||
"--tab_name_align",
|
||||
choices=NAME_ALIGN_CHOICES + ["center"],
|
||||
dest="tab_name_align",
|
||||
default="left",
|
||||
help="Alignment of text on the tab. choices: left, right, centre (or center), edge."
|
||||
" The edge option will align the card name to the outside edge of the"
|
||||
" tab, so that when using tabs on alternating sides,"
|
||||
" the name is less likely to be hidden by the tab in front"
|
||||
" (edge will revert to left when tab_side is full since there is no edge in that case);"
|
||||
" default:left")
|
||||
parser.add_option("--tab_side", type="choice", choices=TAB_SIDE_CHOICES,
|
||||
dest="tab_side", default="right-alternate",
|
||||
parser.add_argument(
|
||||
"--tab_side",
|
||||
choices=TAB_SIDE_CHOICES,
|
||||
dest="tab_side",
|
||||
default="right-alternate",
|
||||
help="Alignment of tab. choices: left, right, left-alternate, right-alternate, full;"
|
||||
" left/right forces all tabs to left/right side;"
|
||||
" left-alternate will start on the left and then toggle between left and right for the tabs;"
|
||||
" right-alternate will start on the right and then toggle between right and left for the tabs;" # noqa
|
||||
" full will force all label tabs to be full width of the divider"
|
||||
" default:right-alternate")
|
||||
parser.add_option("--tabwidth", type="float", default=4,
|
||||
parser.add_argument(
|
||||
"--tabwidth",
|
||||
type=float,
|
||||
default=4,
|
||||
help="width in cm of stick-up tab (ignored if tab_side is full or tabs-only is used)")
|
||||
parser.add_option("--cost", action="append", type="choice",
|
||||
choices=LOCATION_CHOICES, default=[],
|
||||
parser.add_argument("--cost",
|
||||
action="append",
|
||||
choices=LOCATION_CHOICES,
|
||||
default=[],
|
||||
help="where to display the card cost; may be set to"
|
||||
" 'hide' to indicate it should not be displayed, or"
|
||||
" given multiple times to show it in multiple"
|
||||
" places; valid values are: %s; defaults to 'tab'"
|
||||
% ", ".join("'%s'" % x for x in LOCATION_CHOICES))
|
||||
parser.add_option("--set_icon", action="append", type="choice",
|
||||
choices=LOCATION_CHOICES, default=[],
|
||||
" places; valid values are: %s; defaults to 'tab'" %
|
||||
", ".join("'%s'" % x for x in LOCATION_CHOICES))
|
||||
parser.add_argument("--set_icon",
|
||||
action="append",
|
||||
choices=LOCATION_CHOICES,
|
||||
default=[],
|
||||
help="where to display the set icon; may be set to"
|
||||
" 'hide' to indicate it should not be displayed, or"
|
||||
" given multiple times to show it in multiple"
|
||||
" places; valid values are: %s; defaults to 'tab'"
|
||||
% ", ".join("'%s'" % x for x in LOCATION_CHOICES))
|
||||
parser.add_option("--expansions", action="append", type="string",
|
||||
" places; valid values are: %s; defaults to 'tab'" %
|
||||
", ".join("'%s'" % x for x in LOCATION_CHOICES))
|
||||
parser.add_argument(
|
||||
"--expansions",
|
||||
action="append",
|
||||
help="subset of dominion expansions to produce tabs for")
|
||||
parser.add_option("--cropmarks", action="store_true", dest="cropmarks",
|
||||
parser.add_argument(
|
||||
"--cropmarks",
|
||||
action="store_true",
|
||||
dest="cropmarks",
|
||||
help="print crop marks on both sides, rather than tab outlines on one")
|
||||
parser.add_option("--linewidth", type="float", default=.1,
|
||||
parser.add_argument("--linewidth",
|
||||
type=float,
|
||||
default=.1,
|
||||
help="width of lines for card outlines/crop marks")
|
||||
parser.add_option("--write_json", action="store_true", dest="write_json",
|
||||
parser.add_argument(
|
||||
"--write_json",
|
||||
action="store_true",
|
||||
dest="write_json",
|
||||
help="write json version of card definitions and extras")
|
||||
parser.add_option("--tabs-only", action="store_true", dest="tabs_only",
|
||||
parser.add_argument(
|
||||
"--tabs-only",
|
||||
action="store_true",
|
||||
dest="tabs_only",
|
||||
help="draw only tabs to be printed on labels, no divider outlines")
|
||||
parser.add_option("--order", type="choice", choices=["expansion", "global", "colour"], dest="order",
|
||||
parser.add_argument(
|
||||
"--order",
|
||||
choices=["expansion", "global", "colour"],
|
||||
dest="order",
|
||||
help="sort order for the cards, whether by expansion or globally alphabetical")
|
||||
parser.add_option("--expansion_dividers", action="store_true", dest="expansion_dividers",
|
||||
parser.add_argument("--expansion_dividers",
|
||||
action="store_true",
|
||||
dest="expansion_dividers",
|
||||
help="add dividers describing each expansion set")
|
||||
parser.add_option("--base_cards_with_expansion", action="store_true",
|
||||
parser.add_argument(
|
||||
"--base_cards_with_expansion",
|
||||
action="store_true",
|
||||
help='print the base cards as part of the expansion; ie, a divider for "Silver"'
|
||||
' will be printed as both a "Dominion" card and as an "Intrigue" card; if this'
|
||||
' option is not given, all base cards are placed in their own "Base" expansion')
|
||||
parser.add_option("--centre_expansion_dividers", action="store_true", dest="centre_expansion_dividers",
|
||||
parser.add_argument("--centre_expansion_dividers",
|
||||
action="store_true",
|
||||
dest="centre_expansion_dividers",
|
||||
help='centre the tabs on expansion dividers')
|
||||
parser.add_option("--num_pages", type="int", default=-1,
|
||||
parser.add_argument(
|
||||
"--num_pages",
|
||||
type=int,
|
||||
default=-1,
|
||||
help="stop generating after this many pages, -1 for all")
|
||||
parser.add_option("--language", default='en_us', help="language of card texts")
|
||||
parser.add_option("--include_blanks", action="store_true",
|
||||
parser.add_argument("--language",
|
||||
default='en_us',
|
||||
help="language of card texts")
|
||||
parser.add_argument("--include_blanks",
|
||||
action="store_true",
|
||||
help="include a few dividers with extra text")
|
||||
parser.add_option("--exclude_events", action="store_true",
|
||||
default=False, help="exclude individual dividers for events")
|
||||
parser.add_option("--exclude_landmarks", action="store_true",
|
||||
default=False, help="exclude individual dividers for landmarks")
|
||||
parser.add_option("--special_card_groups", action="store_true",
|
||||
default=False, help="group some cards under special dividers (e.g. Shelters, Prizes)")
|
||||
parser.add_option("--exclude_prizes", action="store_true",
|
||||
default=False, help="exclude individual dividers for prizes (cornucopia)")
|
||||
parser.add_option("--cardlist", type="string", dest="cardlist", default=None,
|
||||
parser.add_argument("--exclude_events",
|
||||
action="store_true",
|
||||
help="exclude individual dividers for events")
|
||||
parser.add_argument("--exclude_landmarks",
|
||||
action="store_true",
|
||||
help="exclude individual dividers for landmarks")
|
||||
parser.add_argument(
|
||||
"--special_card_groups",
|
||||
action="store_true",
|
||||
help="group some cards under special dividers (e.g. Shelters, Prizes)")
|
||||
parser.add_argument(
|
||||
"--exclude_prizes",
|
||||
action="store_true",
|
||||
help="exclude individual dividers for prizes (cornucopia)")
|
||||
parser.add_argument(
|
||||
"--cardlist",
|
||||
dest="cardlist",
|
||||
help="Path to file that enumerates each card to be printed on its own line.")
|
||||
parser.add_option("--no-tab-artwork", action="store_true", dest="no_tab_artwork",
|
||||
parser.add_argument("--no-tab-artwork",
|
||||
action="store_true",
|
||||
dest="no_tab_artwork",
|
||||
help="don't show background artwork on tabs")
|
||||
parser.add_option("--use-text-set-icon", action="store_true", dest="use_text_set_icon",
|
||||
parser.add_argument(
|
||||
"--use-text-set-icon",
|
||||
action="store_true",
|
||||
dest="use_text_set_icon",
|
||||
help="use text/letters to represent a card's set instead of the set icon")
|
||||
parser.add_option("--no-page-footer", action="store_true", dest="no_page_footer",
|
||||
parser.add_argument(
|
||||
"--no-page-footer",
|
||||
action="store_true",
|
||||
dest="no_page_footer",
|
||||
help="don't print the set name at the bottom of the page.")
|
||||
parser.add_option("--horizontal_gap", type=float, default=0.,
|
||||
parser.add_argument("--horizontal_gap",
|
||||
type=float,
|
||||
default=0.,
|
||||
help="horizontal gap between dividers in centimeters")
|
||||
parser.add_option("--vertical_gap", type=float, default=0.,
|
||||
parser.add_argument("--vertical_gap",
|
||||
type=float,
|
||||
default=0.,
|
||||
help="vertical gap between dividers in centimeters")
|
||||
parser.add_option("--count", action="store_true", dest="count",
|
||||
default=False, help="Display card count on body of the divider.")
|
||||
parser.add_option("--wrapper", action="store_true", dest="wrapper",
|
||||
parser.add_argument("--count",
|
||||
action="store_true",
|
||||
dest="count",
|
||||
help="Display card count on body of the divider.")
|
||||
parser.add_argument(
|
||||
"--wrapper",
|
||||
action="store_true",
|
||||
dest="wrapper",
|
||||
help="Draw wrapper for cards instead of a divider for the cards")
|
||||
parser.add_option("--thickness", type=float, default=2.0,
|
||||
parser.add_argument(
|
||||
"--thickness",
|
||||
type=float,
|
||||
default=2.0,
|
||||
help="Thickness of a stack of 60 cards (Copper) in centimeters."
|
||||
" Typically unsleeved cards are 2.0, thin sleeved cards are 2.4, and thick sleeved cards are 3.2."
|
||||
" This is only valid with the --wrapper option."
|
||||
" default:2.0")
|
||||
parser.add_option("--sleeved_thick", action="store_true",
|
||||
dest="sleeved_thick", help="same as --size=sleeved --thickness 3.2")
|
||||
parser.add_option("--sleeved_thin", action="store_true",
|
||||
dest="sleeved_thin", help="same as --size=sleeved --thickness 2.4")
|
||||
parser.add_option("--notch_length", type=float, default=0.0,
|
||||
parser.add_argument("--sleeved_thick",
|
||||
action="store_true",
|
||||
dest="sleeved_thick",
|
||||
help="same as --size=sleeved --thickness 3.2")
|
||||
parser.add_argument("--sleeved_thin",
|
||||
action="store_true",
|
||||
dest="sleeved_thin",
|
||||
help="same as --size=sleeved --thickness 2.4")
|
||||
parser.add_argument(
|
||||
"--notch_length",
|
||||
type=float,
|
||||
default=0.0,
|
||||
help="Length of thumb notch on wrapper in centimeters."
|
||||
" This can make it easier to remove the cards from the wrapper."
|
||||
" This is only valid with the --wrapper option."
|
||||
" default:0.0 (i.e., no notch on wrapper)")
|
||||
parser.add_option("--notch", action="store_true",
|
||||
dest="notch", help="same as --notch_length thickness 1.5")
|
||||
parser.add_argument("--notch",
|
||||
action="store_true",
|
||||
dest="notch",
|
||||
help="same as --notch_length thickness 1.5")
|
||||
|
||||
options, args = parser.parse_args(argstring)
|
||||
options = parser.parse_args(arglist)
|
||||
if not options.cost:
|
||||
options.cost = ['tab']
|
||||
if not options.set_icon:
|
||||
@ -168,7 +274,7 @@ def parse_opts(argstring):
|
||||
if options.notch:
|
||||
options.notch_length = 1.5
|
||||
|
||||
return options, args
|
||||
return options
|
||||
|
||||
|
||||
def parseDimensions(dimensionsStr):
|
||||
@ -202,7 +308,8 @@ def parse_papersize(spec):
|
||||
except AttributeError:
|
||||
try:
|
||||
paperwidth, paperheight = parseDimensions(papersize)
|
||||
print 'Using custom paper size, %.2fcm x %.2fcm' % (paperwidth / cm, paperheight / cm)
|
||||
print 'Using custom paper size, %.2fcm x %.2fcm' % (
|
||||
paperwidth / cm, paperheight / cm)
|
||||
except ValueError:
|
||||
paperwidth, paperheight = pagesizes.LETTER
|
||||
return paperwidth, paperheight
|
||||
@ -212,16 +319,16 @@ def parse_cardsize(spec, sleeved):
|
||||
spec = spec.upper()
|
||||
if spec == 'SLEEVED' or sleeved:
|
||||
dominionCardWidth, dominionCardHeight = (9.4 * cm, 6.15 * cm)
|
||||
print 'Using sleeved card size, %.2fcm x %.2fcm' % (dominionCardWidth / cm,
|
||||
dominionCardHeight / cm)
|
||||
print 'Using sleeved card size, %.2fcm x %.2fcm' % (
|
||||
dominionCardWidth / cm, dominionCardHeight / cm)
|
||||
elif spec in ['NORMAL', 'UNSLEEVED']:
|
||||
dominionCardWidth, dominionCardHeight = (9.1 * cm, 5.9 * cm)
|
||||
print 'Using normal card size, %.2fcm x%.2fcm' % (dominionCardWidth / cm,
|
||||
dominionCardHeight / cm)
|
||||
print 'Using normal card size, %.2fcm x%.2fcm' % (
|
||||
dominionCardWidth / cm, dominionCardHeight / cm)
|
||||
else:
|
||||
dominionCardWidth, dominionCardHeight = parseDimensions(spec)
|
||||
print 'Using custom card size, %.2fcm x %.2fcm' % (dominionCardWidth / cm,
|
||||
dominionCardHeight / cm)
|
||||
print 'Using custom card size, %.2fcm x %.2fcm' % (
|
||||
dominionCardWidth / cm, dominionCardHeight / cm)
|
||||
return dominionCardWidth, dominionCardHeight
|
||||
|
||||
|
||||
@ -250,7 +357,6 @@ def read_write_card_data(options):
|
||||
|
||||
|
||||
class CardSorter(object):
|
||||
|
||||
def __init__(self, order, baseCards):
|
||||
self.order = order
|
||||
if order == "global":
|
||||
@ -280,7 +386,8 @@ class CardSorter(object):
|
||||
return int(card.isExpansion()), self.baseIndex(card.name), card.name
|
||||
|
||||
def by_expansion_sort_key(self, card):
|
||||
return card.cardset, int(card.isExpansion()), self.baseIndex(card.name), card.name
|
||||
return card.cardset, int(card.isExpansion()), self.baseIndex(
|
||||
card.name), card.name
|
||||
|
||||
def colour_sort_key(self, card):
|
||||
return card.getType().getTypeNames(), card.name
|
||||
@ -291,12 +398,14 @@ class CardSorter(object):
|
||||
|
||||
def filter_sort_cards(cards, options):
|
||||
|
||||
cardSorter = CardSorter(options.order,
|
||||
cardSorter = CardSorter(
|
||||
options.order,
|
||||
[card.name for card in cards if card.cardset.lower() == 'base'])
|
||||
if options.base_cards_with_expansion:
|
||||
cards = [card for card in cards if card.cardset.lower() != 'base']
|
||||
else:
|
||||
cards = [card for card in cards if not cardSorter.isBaseExpansionCard(card)]
|
||||
cards = [card for card in cards
|
||||
if not cardSorter.isBaseExpansionCard(card)]
|
||||
|
||||
if options.special_card_groups:
|
||||
# Load the card groups file
|
||||
@ -307,20 +416,25 @@ def filter_sort_cards(cards, options):
|
||||
# pull out any cards which are a subcard, and rename the master card
|
||||
new_cards = [] # holds the cards that are to be kept
|
||||
all_subcards = [] # holds names of cards that will be removed
|
||||
subcard_parent = {} # holds reverse map of subcard name to group name
|
||||
subcard_count = {} # holds total card count of the subcards for a group
|
||||
subcard_parent = {
|
||||
} # holds reverse map of subcard name to group name
|
||||
subcard_count = {
|
||||
} # holds total card count of the subcards for a group
|
||||
|
||||
# Initialize each of the new card groups
|
||||
for group in card_groups:
|
||||
subcard_count[group] = 0
|
||||
for subs in card_groups[group]["subcards"]:
|
||||
all_subcards.append(subs) # add card names to the list for removal
|
||||
subcard_parent[subs] = group # create the reverse mapping of subgroup to group
|
||||
all_subcards.append(
|
||||
subs) # add card names to the list for removal
|
||||
subcard_parent[
|
||||
subs] = group # create the reverse mapping of subgroup to group
|
||||
|
||||
# go through the cards and add up the number of subgroup cards
|
||||
for card in cards:
|
||||
if card.name in all_subcards:
|
||||
subcard_count[ subcard_parent[card.name] ] += card.getCardCount()
|
||||
subcard_count[subcard_parent[
|
||||
card.name]] += card.getCardCount()
|
||||
|
||||
# fix up the group card holders count & name, and weed out the subgroup cards
|
||||
for card in cards:
|
||||
@ -333,21 +447,22 @@ def filter_sort_cards(cards, options):
|
||||
cards = new_cards
|
||||
|
||||
if options.expansions:
|
||||
options.expansions = [o.lower()
|
||||
for o in options.expansions]
|
||||
reverseMapping = {
|
||||
v: k for k, v in Card.language_mapping.iteritems()}
|
||||
options.expansions = [o.lower() for o in options.expansions]
|
||||
reverseMapping = {v: k for k, v in Card.language_mapping.iteritems()}
|
||||
options.expansions = [
|
||||
reverseMapping.get(e, e) for e in options.expansions]
|
||||
reverseMapping.get(e, e) for e in options.expansions
|
||||
]
|
||||
filteredCards = []
|
||||
knownExpansions = set()
|
||||
for c in cards:
|
||||
knownExpansions.add(c.cardset)
|
||||
if next((e for e in options.expansions if c.cardset.startswith(e)), None):
|
||||
if next((e for e in options.expansions
|
||||
if c.cardset.startswith(e)), None):
|
||||
filteredCards.append(c)
|
||||
unknownExpansions = set(options.expansions) - knownExpansions
|
||||
if unknownExpansions:
|
||||
print "Error - unknown expansion(s): %s" % ", ".join(unknownExpansions)
|
||||
print "Error - unknown expansion(s): %s" % ", ".join(
|
||||
unknownExpansions)
|
||||
|
||||
cards = filteredCards
|
||||
|
||||
@ -399,8 +514,6 @@ def filter_sort_cards(cards, options):
|
||||
holder.setCardCount(count)
|
||||
cards = filteredCards
|
||||
|
||||
|
||||
|
||||
if options.cardlist:
|
||||
cardlist = set()
|
||||
with open(options.cardlist) as cardfile:
|
||||
@ -414,11 +527,14 @@ def filter_sort_cards(cards, options):
|
||||
for c in cards:
|
||||
if cardSorter.isBaseExpansionCard(c):
|
||||
continue
|
||||
cardnamesByExpansion.setdefault(
|
||||
c.cardset, []).append(c.name.strip())
|
||||
cardnamesByExpansion.setdefault(c.cardset,
|
||||
[]).append(c.name.strip())
|
||||
for exp, names in cardnamesByExpansion.iteritems():
|
||||
c = Card(
|
||||
exp, exp, ("Expansion",), None, ' | '.join(sorted(names)), count=len(names))
|
||||
c = Card(exp,
|
||||
exp, ("Expansion", ),
|
||||
None,
|
||||
' | '.join(sorted(names)),
|
||||
count=len(names))
|
||||
cards.append(c)
|
||||
|
||||
cards.sort(key=cardSorter)
|
||||
@ -428,7 +544,8 @@ def filter_sort_cards(cards, options):
|
||||
|
||||
def calculate_layout(options, cards=[]):
|
||||
|
||||
dominionCardWidth, dominionCardHeight = parse_cardsize(options.size, options.sleeved)
|
||||
dominionCardWidth, dominionCardHeight = parse_cardsize(options.size,
|
||||
options.sleeved)
|
||||
paperwidth, paperheight = parse_papersize(options.papersize)
|
||||
|
||||
if options.orientation == "vertical":
|
||||
@ -457,8 +574,7 @@ def calculate_layout(options, cards=[]):
|
||||
dividerWidth = labelWidth
|
||||
fixedMargins = True
|
||||
else:
|
||||
minmarginwidth, minmarginheight = parseDimensions(
|
||||
options.minmargin)
|
||||
minmarginwidth, minmarginheight = parseDimensions(options.minmargin)
|
||||
if options.tab_side == "full":
|
||||
labelWidth = dividerWidth
|
||||
else:
|
||||
@ -472,8 +588,10 @@ def calculate_layout(options, cards=[]):
|
||||
dividerWidthReserved = dividerWidth + horizontalBorderSpace
|
||||
dividerHeightReserved = dividerHeight + verticalBorderSpace
|
||||
if options.wrapper:
|
||||
max_card_stack_height = max(c.getStackHeight(options.thickness) for c in cards)
|
||||
dividerHeightReserved = (dividerHeightReserved * 2) + (max_card_stack_height * 2)
|
||||
max_card_stack_height = max(c.getStackHeight(options.thickness)
|
||||
for c in cards)
|
||||
dividerHeightReserved = (dividerHeightReserved * 2) + (
|
||||
max_card_stack_height * 2)
|
||||
print "Max Card Stack Height: {:.2f}cm ".format(max_card_stack_height)
|
||||
|
||||
# Notch measurements
|
||||
@ -495,16 +613,20 @@ def calculate_layout(options, cards=[]):
|
||||
# as we don't draw anything in the final border, it shouldn't count towards how many tabs we can fit
|
||||
# so it gets added back in to the page size here
|
||||
numDividersVerticalP = int(
|
||||
(paperheight - 2 * minmarginheight + verticalBorderSpace) / options.dividerHeightReserved)
|
||||
(paperheight - 2 * minmarginheight + verticalBorderSpace) /
|
||||
options.dividerHeightReserved)
|
||||
numDividersHorizontalP = int(
|
||||
(paperwidth - 2 * minmarginwidth + horizontalBorderSpace) / options.dividerWidthReserved)
|
||||
(paperwidth - 2 * minmarginwidth + horizontalBorderSpace) /
|
||||
options.dividerWidthReserved)
|
||||
numDividersVerticalL = int(
|
||||
(paperwidth - 2 * minmarginwidth + verticalBorderSpace) / options.dividerHeightReserved)
|
||||
(paperwidth - 2 * minmarginwidth + verticalBorderSpace) /
|
||||
options.dividerHeightReserved)
|
||||
numDividersHorizontalL = int(
|
||||
(paperheight - 2 * minmarginheight + horizontalBorderSpace) / options.dividerWidthReserved)
|
||||
(paperheight - 2 * minmarginheight + horizontalBorderSpace) /
|
||||
options.dividerWidthReserved)
|
||||
|
||||
if ((numDividersVerticalL * numDividersHorizontalL >
|
||||
numDividersVerticalP * numDividersHorizontalP) and not fixedMargins):
|
||||
if ((numDividersVerticalL * numDividersHorizontalL > numDividersVerticalP *
|
||||
numDividersHorizontalP) and not fixedMargins):
|
||||
add_opt(options, 'numDividersVertical', numDividersVerticalL)
|
||||
add_opt(options, 'numDividersHorizontal', numDividersHorizontalL)
|
||||
add_opt(options, 'paperheight', paperwidth)
|
||||
@ -522,17 +644,17 @@ def calculate_layout(options, cards=[]):
|
||||
if not fixedMargins:
|
||||
# dynamically max margins
|
||||
add_opt(options, 'horizontalMargin',
|
||||
(options.paperwidth -
|
||||
options.numDividersHorizontal * options.dividerWidthReserved + horizontalBorderSpace) / 2)
|
||||
(options.paperwidth - options.numDividersHorizontal *
|
||||
options.dividerWidthReserved + horizontalBorderSpace) / 2)
|
||||
add_opt(options, 'verticalMargin',
|
||||
(options.paperheight -
|
||||
options.numDividersVertical * options.dividerHeightReserved + verticalBorderSpace) / 2)
|
||||
(options.paperheight - options.numDividersVertical *
|
||||
options.dividerHeightReserved + verticalBorderSpace) / 2)
|
||||
else:
|
||||
add_opt(options, 'horizontalMargin', minmarginwidth)
|
||||
add_opt(options, 'verticalMargin', minmarginheight)
|
||||
|
||||
|
||||
def generate(options, data_path, f):
|
||||
def generate(options, data_path):
|
||||
|
||||
add_opt(options, 'data_path', data_path)
|
||||
|
||||
@ -543,26 +665,19 @@ def generate(options, data_path, f):
|
||||
|
||||
calculate_layout(options, cards)
|
||||
|
||||
print "Paper dimensions: {:.2f}cm (w) x {:.2f}cm (h)".format(options.paperwidth / cm,
|
||||
options.paperheight / cm)
|
||||
print "Tab dimensions: {:.2f}cm (w) x {:.2f}cm (h)".format(options.dividerWidthReserved / cm,
|
||||
options.dividerHeightReserved / cm)
|
||||
print '{} dividers horizontally, {} vertically'.format(options.numDividersHorizontal,
|
||||
options.numDividersVertical)
|
||||
print "Margins: {:.2f}cm h, {:.2f}cm v\n".format(options.horizontalMargin / cm,
|
||||
options.verticalMargin / cm)
|
||||
|
||||
|
||||
if not f:
|
||||
f = "dominion_dividers.pdf"
|
||||
print "Paper dimensions: {:.2f}cm (w) x {:.2f}cm (h)".format(
|
||||
options.paperwidth / cm, options.paperheight / cm)
|
||||
print "Tab dimensions: {:.2f}cm (w) x {:.2f}cm (h)".format(
|
||||
options.dividerWidthReserved / cm, options.dividerHeightReserved / cm)
|
||||
print '{} dividers horizontally, {} vertically'.format(
|
||||
options.numDividersHorizontal, options.numDividersVertical)
|
||||
print "Margins: {:.2f}cm h, {:.2f}cm v\n".format(
|
||||
options.horizontalMargin / cm, options.verticalMargin / cm)
|
||||
|
||||
dd = DividerDrawer()
|
||||
dd.draw(f, cards, options)
|
||||
dd.draw(cards, options)
|
||||
|
||||
|
||||
def main(argstring, data_path):
|
||||
options, args = parse_opts(argstring)
|
||||
fname = None
|
||||
if args:
|
||||
fname = args[0]
|
||||
return generate(options, data_path, fname)
|
||||
def main(arglist, data_path):
|
||||
options = parse_opts(arglist)
|
||||
return generate(options, data_path)
|
||||
|
||||
@ -2,6 +2,7 @@ import json
|
||||
import os
|
||||
from reportlab.lib.units import cm
|
||||
|
||||
|
||||
def getType(typespec):
|
||||
return cardTypes[tuple(typespec)]
|
||||
|
||||
@ -101,7 +102,6 @@ class Card(object):
|
||||
return promoTextIcons[cardName.lower()]
|
||||
return None
|
||||
|
||||
|
||||
def __init__(self, name, cardset, types, cost, description='', potcost=0, debtcost=0, extra='', count=-1):
|
||||
self.name = name.strip()
|
||||
self.cardset = cardset.strip()
|
||||
@ -151,7 +151,6 @@ class Card(object):
|
||||
def isType(self, what):
|
||||
return what in self.getType().getTypeNames()
|
||||
|
||||
|
||||
def setImage(self):
|
||||
setImage = Card.getSetImage(self.cardset, self.name)
|
||||
if setImage is None and self.cardset not in ['base', 'extra'] and not self.isExpansion():
|
||||
|
||||
271
domdiv/draw.py
271
domdiv/draw.py
@ -20,7 +20,6 @@ def split(l, n):
|
||||
|
||||
|
||||
class DividerDrawer(object):
|
||||
|
||||
def __init__(self):
|
||||
self.odd = True
|
||||
self.canvas = None
|
||||
@ -29,14 +28,14 @@ class DividerDrawer(object):
|
||||
try:
|
||||
dirn = os.path.join(self.options.data_path, 'fonts')
|
||||
self.fontNameRegular = 'MinionPro-Regular'
|
||||
pdfmetrics.registerFont(
|
||||
TTFont(self.fontNameRegular, os.path.join(dirn, 'MinionPro-Regular.ttf')))
|
||||
pdfmetrics.registerFont(TTFont(self.fontNameRegular, os.path.join(
|
||||
dirn, 'MinionPro-Regular.ttf')))
|
||||
self.fontNameBold = 'MinionPro-Bold'
|
||||
pdfmetrics.registerFont(
|
||||
TTFont(self.fontNameBold, os.path.join(dirn, 'MinionPro-Bold.ttf')))
|
||||
pdfmetrics.registerFont(TTFont(self.fontNameBold, os.path.join(
|
||||
dirn, 'MinionPro-Bold.ttf')))
|
||||
self.fontNameOblique = 'MinionPro-Oblique'
|
||||
pdfmetrics.registerFont(
|
||||
TTFont(self.fontNameOblique, os.path.join(dirn, 'MinionPro-It.ttf')))
|
||||
pdfmetrics.registerFont(TTFont(self.fontNameOblique, os.path.join(
|
||||
dirn, 'MinionPro-It.ttf')))
|
||||
except:
|
||||
print >> sys.stderr, "Warning, Minion Pro Font ttf file not found! Falling back on Times"
|
||||
self.fontNameRegular = 'Times-Roman'
|
||||
@ -176,48 +175,64 @@ class DividerDrawer(object):
|
||||
self.canvas.lines(DeltaXYtoLines(delta))
|
||||
|
||||
self.canvas.setStrokeGray(0.9)
|
||||
self.canvas.line(dividerWidth-side_2_tab, dividerHeight + dividerBaseHeight + stackHeight , dividerWidth-side_2_tab-theTabWidth , dividerHeight + dividerBaseHeight + stackHeight )
|
||||
self.canvas.line(dividerWidth-side_2_tab, dividerHeight + dividerBaseHeight + 2*stackHeight , dividerWidth-side_2_tab-theTabWidth , dividerHeight + dividerBaseHeight + 2*stackHeight )
|
||||
self.canvas.line(notch_width1 , dividerHeight , dividerWidth - notch_width2, dividerHeight )
|
||||
self.canvas.line(notch_width1 , dividerHeight + stackHeight , dividerWidth - notch_width2, dividerHeight + stackHeight )
|
||||
self.canvas.line(dividerWidth - side_2_tab,
|
||||
dividerHeight + dividerBaseHeight + stackHeight,
|
||||
dividerWidth - side_2_tab - theTabWidth,
|
||||
dividerHeight + dividerBaseHeight + stackHeight)
|
||||
self.canvas.line(
|
||||
dividerWidth - side_2_tab, dividerHeight + dividerBaseHeight +
|
||||
2 * stackHeight, dividerWidth - side_2_tab - theTabWidth,
|
||||
dividerHeight + dividerBaseHeight + 2 * stackHeight)
|
||||
self.canvas.line(notch_width1, dividerHeight,
|
||||
dividerWidth - notch_width2, dividerHeight)
|
||||
self.canvas.line(notch_width1, dividerHeight + stackHeight,
|
||||
dividerWidth - notch_width2,
|
||||
dividerHeight + stackHeight)
|
||||
|
||||
self.canvas.restoreState()
|
||||
|
||||
def draw(self, fname, cards, options):
|
||||
def draw(self, cards, options):
|
||||
self.options = options
|
||||
|
||||
self.registerFonts()
|
||||
self.canvas = canvas.Canvas(
|
||||
fname, pagesize=(options.paperwidth, options.paperheight))
|
||||
options.outfile,
|
||||
pagesize=(options.paperwidth, options.paperheight))
|
||||
self.drawDividers(cards)
|
||||
self.canvas.save()
|
||||
|
||||
def add_inline_images(self, text, fontsize):
|
||||
path = os.path.join(self.options.data_path, 'images')
|
||||
replace = '<img src='"'%s/coin_small_\\1.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (
|
||||
path, fontsize * 1.2)
|
||||
replace = '<img src=' "'%s/coin_small_\\1.png'" ' width=%d height=' "'100%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
text = re.sub('(\d+)\s(c|C)oin(s)?', replace, text)
|
||||
replace = '<img src='"'%s/coin_small_question.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (
|
||||
path, fontsize * 1.2)
|
||||
replace = '<img src=' "'%s/coin_small_question.png'" ' width=%d height=' "'100%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
text = re.sub('\?\s(c|C)oin(s)?', replace, text)
|
||||
replace = '<img src='"'%s/coin_small_empty.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (
|
||||
path, fontsize * 1.2)
|
||||
replace = '<img src=' "'%s/coin_small_empty.png'" ' width=%d height=' "'100%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
text = re.sub('empty\s(c|C)oin(s)?', replace, text)
|
||||
replace = '<img src='"'%s/victory_emblem.png'"' width=%d height='"'120%%'"' valign='"'middle'"'/>' % (
|
||||
path, fontsize * 1.5)
|
||||
replace = '<img src=' "'%s/victory_emblem.png'" ' width=%d height=' "'120%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (path, fontsize * 1.5)
|
||||
text = re.sub('\<VP\>', replace, text)
|
||||
replace = '<img src='"'%s/debt_\\1.png'"' width=%d height='"'105%%'"' valign='"'middle'"'/> ' % (
|
||||
path, fontsize * 1.2)
|
||||
replace = '<img src=' "'%s/debt_\\1.png'" ' width=%d height=' "'105%%'" ' valign=' "'middle'" '/> '
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
text = re.sub('(\d+)\sDebt', replace, text)
|
||||
replace = '<img src='"'%s/debt.png'"' width=%d height='"'105%%'"' valign='"'middle'"'/> ' % (
|
||||
path, fontsize * 1.2)
|
||||
replace = '<img src=' "'%s/debt.png'" ' width=%d height=' "'105%%'" ' valign=' "'middle'" '/> '
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
text = re.sub('Debt', replace, text)
|
||||
replace = '<img src='"'%s/potion_small.png'"' width=%d height='"'100%%'"' valign='"'middle'"'/>' % (
|
||||
path, fontsize * 1.2)
|
||||
replace = '<img src=' "'%s/potion_small.png'" ' width=%d height=' "'100%%'" ' valign=' "'middle'" '/>'
|
||||
replace = replace % (path, fontsize * 1.2)
|
||||
text = re.sub('Potion', replace, text)
|
||||
return text
|
||||
|
||||
def drawOutline(self, card, x, y, rightSide, isBack=False, isExpansionDivider=False):
|
||||
def drawOutline(self,
|
||||
card,
|
||||
x,
|
||||
y,
|
||||
rightSide,
|
||||
isBack=False,
|
||||
isExpansionDivider=False):
|
||||
# draw outline or cropmarks
|
||||
self.canvas.saveState()
|
||||
self.canvas.setLineWidth(self.options.linewidth)
|
||||
@ -245,11 +260,11 @@ class DividerDrawer(object):
|
||||
self.canvas.scale(-1, 1)
|
||||
if cropmarksleft or cropmarksright:
|
||||
self.canvas.line(-2 * cmw, 0, -cmw, 0)
|
||||
self.canvas.line(-2 * cmw,
|
||||
self.options.dividerBaseHeight, -cmw, self.options.dividerBaseHeight)
|
||||
self.canvas.line(-2 * cmw, self.options.dividerBaseHeight,
|
||||
-cmw, self.options.dividerBaseHeight)
|
||||
if y > 0:
|
||||
self.canvas.line(-2 * cmw,
|
||||
self.options.dividerHeight, -cmw, self.options.dividerHeight)
|
||||
self.canvas.line(-2 * cmw, self.options.dividerHeight,
|
||||
-cmw, self.options.dividerHeight)
|
||||
if mirror:
|
||||
self.canvas.restoreState()
|
||||
|
||||
@ -275,12 +290,15 @@ class DividerDrawer(object):
|
||||
self.canvas.line(leftLine, -2 * cmw, leftLine, -cmw)
|
||||
if y == self.options.numDividersVertical - 1:
|
||||
self.canvas.line(rightLine, self.options.dividerHeight + cmw,
|
||||
rightLine, self.options.dividerHeight + 2 * cmw)
|
||||
rightLine,
|
||||
self.options.dividerHeight + 2 * cmw)
|
||||
self.canvas.line(middleLine, self.options.dividerHeight + cmw,
|
||||
middleLine, self.options.dividerHeight + 2 * cmw)
|
||||
middleLine,
|
||||
self.options.dividerHeight + 2 * cmw)
|
||||
if cropmarksleft:
|
||||
self.canvas.line(leftLine, self.options.dividerHeight + cmw,
|
||||
leftLine, self.options.dividerHeight + 2 * cmw)
|
||||
self.canvas.line(
|
||||
leftLine, self.options.dividerHeight + cmw, leftLine,
|
||||
self.options.dividerHeight + 2 * cmw)
|
||||
|
||||
self.canvas.restoreState()
|
||||
|
||||
@ -294,8 +312,14 @@ class DividerDrawer(object):
|
||||
cardIconHeight = y + offset
|
||||
countHeight = cardIconHeight - 4
|
||||
|
||||
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', 'card.png'),
|
||||
x, countHeight, 16, 16, preserveAspectRatio=True, mask='auto')
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images', 'card.png'),
|
||||
x,
|
||||
countHeight,
|
||||
16,
|
||||
16,
|
||||
preserveAspectRatio=True,
|
||||
mask='auto')
|
||||
|
||||
self.canvas.setFont(self.fontNameBold, 10)
|
||||
count = str(card.count)
|
||||
@ -312,26 +336,50 @@ class DividerDrawer(object):
|
||||
potSize = 11
|
||||
|
||||
if card.debtcost:
|
||||
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', 'debt.png'),
|
||||
x, coinHeight, 16, 16, preserveAspectRatio=True,
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images', 'debt.png'),
|
||||
x,
|
||||
coinHeight,
|
||||
16,
|
||||
16,
|
||||
preserveAspectRatio=True,
|
||||
mask=[255, 255, 255, 255, 255, 255])
|
||||
cost = str(card.debtcost)
|
||||
if card.cost != "" and int(card.cost) > 0:
|
||||
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', 'coin_small.png'), x + 17,
|
||||
coinHeight, 16, 16, preserveAspectRatio=True,
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images',
|
||||
'coin_small.png'),
|
||||
x + 17,
|
||||
coinHeight,
|
||||
16,
|
||||
16,
|
||||
preserveAspectRatio=True,
|
||||
mask=[255, 255, 255, 255, 255, 255])
|
||||
self.canvas.setFont(self.fontNameBold, 12)
|
||||
self.canvas.drawCentredString(x + 8 + 17, costHeight, str(card.cost))
|
||||
self.canvas.drawCentredString(x + 8 + 17, costHeight,
|
||||
str(card.cost))
|
||||
self.canvas.setFillColorRGB(0, 0, 0)
|
||||
width += 16
|
||||
self.canvas.setFillColorRGB(1, 1, 1)
|
||||
else:
|
||||
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', 'coin_small.png'),
|
||||
x, coinHeight, 16, 16, preserveAspectRatio=True, mask='auto')
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images',
|
||||
'coin_small.png'),
|
||||
x,
|
||||
coinHeight,
|
||||
16,
|
||||
16,
|
||||
preserveAspectRatio=True,
|
||||
mask='auto')
|
||||
cost = str(card.cost)
|
||||
if card.potcost:
|
||||
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', 'potion.png'), x + 17,
|
||||
potHeight, potSize, potSize, preserveAspectRatio=True,
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images', 'potion.png'),
|
||||
x + 17,
|
||||
potHeight,
|
||||
potSize,
|
||||
potSize,
|
||||
preserveAspectRatio=True,
|
||||
mask=[255, 255, 255, 255, 255, 255])
|
||||
width += potSize
|
||||
|
||||
@ -343,17 +391,24 @@ class DividerDrawer(object):
|
||||
def drawSetIcon(self, setImage, x, y):
|
||||
# set image
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images', setImage), x, y, 14, 12, mask='auto')
|
||||
os.path.join(self.options.data_path, 'images', setImage),
|
||||
x,
|
||||
y,
|
||||
14,
|
||||
12,
|
||||
mask='auto')
|
||||
|
||||
def nameWidth(self, name, fontSize):
|
||||
w = 0
|
||||
name_parts = name.split()
|
||||
for i, part in enumerate(name_parts):
|
||||
if i != 0:
|
||||
w += pdfmetrics.stringWidth(' ', self.fontNameRegular, fontSize)
|
||||
w += pdfmetrics.stringWidth(part[0], self.fontNameRegular, fontSize)
|
||||
w += pdfmetrics.stringWidth(part[1:],
|
||||
self.fontNameRegular, fontSize - 2)
|
||||
w += pdfmetrics.stringWidth(' ', self.fontNameRegular,
|
||||
fontSize)
|
||||
w += pdfmetrics.stringWidth(part[0], self.fontNameRegular,
|
||||
fontSize)
|
||||
w += pdfmetrics.stringWidth(part[1:], self.fontNameRegular,
|
||||
fontSize - 2)
|
||||
return w
|
||||
|
||||
def drawTab(self, card, rightSide, wrapper="no"):
|
||||
@ -379,7 +434,8 @@ class DividerDrawer(object):
|
||||
translate_x = self.options.labelWidth
|
||||
|
||||
if wrapper == "front":
|
||||
translate_y = translate_y + self.options.dividerHeight + 2.0 * card.getStackHeight(self.options.thickness)
|
||||
translate_y = translate_y + self.options.dividerHeight + 2.0 * card.getStackHeight(
|
||||
self.options.thickness)
|
||||
|
||||
self.canvas.translate(translate_x, translate_y)
|
||||
|
||||
@ -397,16 +453,23 @@ class DividerDrawer(object):
|
||||
# draw banner
|
||||
img = card.getType().getNoCoinTabImageFile()
|
||||
if not self.options.no_tab_artwork and img:
|
||||
self.canvas.drawImage(os.path.join(self.options.data_path, 'images', img), 1, 0,
|
||||
self.options.labelWidth -
|
||||
2, self.options.labelHeight - 1,
|
||||
preserveAspectRatio=False, anchor='n', mask='auto')
|
||||
self.canvas.drawImage(
|
||||
os.path.join(self.options.data_path, 'images', img),
|
||||
1,
|
||||
0,
|
||||
self.options.labelWidth - 2,
|
||||
self.options.labelHeight - 1,
|
||||
preserveAspectRatio=False,
|
||||
anchor='n',
|
||||
mask='auto')
|
||||
|
||||
# draw cost
|
||||
if not card.isExpansion() and not card.isBlank() and not card.isLandmark() and not card.isType('Trash'):
|
||||
if not card.isExpansion() and not card.isBlank(
|
||||
) and not card.isLandmark() and not card.isType('Trash'):
|
||||
if 'tab' in self.options.cost:
|
||||
textInset = 4
|
||||
textInset += self.drawCost(card, textInset, textHeight,
|
||||
textInset += self.drawCost(
|
||||
card, textInset, textHeight,
|
||||
card.getType().getTabCostHeightOffset())
|
||||
else:
|
||||
textInset = 6
|
||||
@ -424,7 +487,8 @@ class DividerDrawer(object):
|
||||
if setText is None:
|
||||
setText = ""
|
||||
|
||||
self.canvas.drawCentredString(self.options.labelWidth - 10, textHeight + 2, setText)
|
||||
self.canvas.drawCentredString(self.options.labelWidth - 10,
|
||||
textHeight + 2, setText)
|
||||
textInsetRight = 15
|
||||
else:
|
||||
setImage = card.setImage()
|
||||
@ -469,13 +533,16 @@ class DividerDrawer(object):
|
||||
h -= h / 2
|
||||
|
||||
words = line.split()
|
||||
NotRightEdge = ( not self.options.tab_name_align == "right"
|
||||
and (self.options.tab_name_align == "centre" or rightSide or not self.options.tab_name_align == "edge"))
|
||||
NotRightEdge = (
|
||||
not self.options.tab_name_align == "right" and
|
||||
(self.options.tab_name_align == "centre" or rightSide or
|
||||
not self.options.tab_name_align == "edge"))
|
||||
if wrapper == "back" and not self.options.tab_name_align == "centre":
|
||||
NotRightEdge = not NotRightEdge
|
||||
if NotRightEdge:
|
||||
if self.options.tab_name_align == "centre":
|
||||
w = self.options.labelWidth / 2 - self.nameWidth(line, fontSize) / 2
|
||||
w = self.options.labelWidth / 2 - self.nameWidth(
|
||||
line, fontSize) / 2
|
||||
else:
|
||||
w = textInset
|
||||
|
||||
@ -483,7 +550,9 @@ class DividerDrawer(object):
|
||||
self.canvas.setFont(self.fontNameRegular, fontSize)
|
||||
if text != ' ':
|
||||
self.canvas.drawString(w, h, text)
|
||||
return pdfmetrics.stringWidth(text, self.fontNameRegular, fontSize)
|
||||
return pdfmetrics.stringWidth(text, self.fontNameRegular,
|
||||
fontSize)
|
||||
|
||||
for i, word in enumerate(words):
|
||||
if i != 0:
|
||||
w += drawWordPiece(' ', fontSize)
|
||||
@ -501,7 +570,9 @@ class DividerDrawer(object):
|
||||
self.canvas.setFont(self.fontNameRegular, fontSize)
|
||||
if text != ' ':
|
||||
self.canvas.drawRightString(w, h, text)
|
||||
return -pdfmetrics.stringWidth(text, self.fontNameRegular, fontSize)
|
||||
return -pdfmetrics.stringWidth(text, self.fontNameRegular,
|
||||
fontSize)
|
||||
|
||||
for i, word in enumerate(words):
|
||||
w += drawWordPiece(word[1:], fontSize - 2)
|
||||
w += drawWordPiece(word[0], fontSize)
|
||||
@ -510,20 +581,26 @@ class DividerDrawer(object):
|
||||
|
||||
if wrapper == "front" and card.getCardCount() >= 5:
|
||||
# Print smaller version of name on the top wrapper edge
|
||||
self.canvas.translate(0 , -card.getStackHeight(self.options.thickness)) # move into area used by the wrapper
|
||||
self.canvas.translate(0, -card.getStackHeight(
|
||||
self.options.thickness)) # move into area used by the wrapper
|
||||
fontSize = 8 # use the smallest font
|
||||
self.canvas.setFont(self.fontNameRegular, fontSize)
|
||||
|
||||
textHeight = fontSize - 2
|
||||
textHeight = card.getStackHeight(self.options.thickness) / 2 - textHeight / 2
|
||||
textHeight = card.getStackHeight(
|
||||
self.options.thickness) / 2 - textHeight / 2
|
||||
h = textHeight
|
||||
words = name.split()
|
||||
w = self.options.labelWidth / 2 - self.nameWidth(name, fontSize) / 2
|
||||
w = self.options.labelWidth / 2 - self.nameWidth(name,
|
||||
fontSize) / 2
|
||||
|
||||
def drawWordPiece(text, fontSize):
|
||||
self.canvas.setFont(self.fontNameRegular, fontSize)
|
||||
if text != ' ':
|
||||
self.canvas.drawString(w, h, text)
|
||||
return pdfmetrics.stringWidth(text, self.fontNameRegular, fontSize)
|
||||
return pdfmetrics.stringWidth(text, self.fontNameRegular,
|
||||
fontSize)
|
||||
|
||||
for i, word in enumerate(words):
|
||||
if i != 0:
|
||||
w += drawWordPiece(' ', fontSize)
|
||||
@ -540,11 +617,13 @@ class DividerDrawer(object):
|
||||
|
||||
# Figure out if any translation needs to be done
|
||||
if wrapper == "back":
|
||||
self.canvas.translate(self.options.dividerWidth, self.options.dividerHeight)
|
||||
self.canvas.translate(self.options.dividerWidth,
|
||||
self.options.dividerHeight)
|
||||
self.canvas.rotate(180)
|
||||
|
||||
if wrapper == "front":
|
||||
self.canvas.translate( 0 , self.options.dividerHeight + card.getStackHeight(self.options.thickness))
|
||||
self.canvas.translate(0, self.options.dividerHeight +
|
||||
card.getStackHeight(self.options.thickness))
|
||||
|
||||
if wrapper == "front" or wrapper == "back":
|
||||
if self.options.notch_width1 > 0:
|
||||
@ -565,7 +644,8 @@ class DividerDrawer(object):
|
||||
drewTopIcon = True
|
||||
|
||||
if self.options.count:
|
||||
self.drawCardCount(card, Image_x, totalHeight - usedHeight - 0.5 * cm)
|
||||
self.drawCardCount(card, Image_x,
|
||||
totalHeight - usedHeight - 0.5 * cm)
|
||||
drewTopIcon = True
|
||||
|
||||
if drewTopIcon:
|
||||
@ -625,7 +705,13 @@ class DividerDrawer(object):
|
||||
|
||||
self.canvas.restoreState()
|
||||
|
||||
def drawDivider(self, card, x, y, isBack=False, divider_text="card", divider_text2="rules"):
|
||||
def drawDivider(self,
|
||||
card,
|
||||
x,
|
||||
y,
|
||||
isBack=False,
|
||||
divider_text="card",
|
||||
divider_text2="rules"):
|
||||
# figure out whether the tab should go on the right side or not
|
||||
if self.options.tab_side == "right":
|
||||
rightSide = isBack
|
||||
@ -640,15 +726,18 @@ class DividerDrawer(object):
|
||||
|
||||
# apply the transforms to get us to the corner of the current card
|
||||
self.canvas.resetTransforms()
|
||||
self.canvas.translate(self.options.horizontalMargin, self.options.verticalMargin)
|
||||
self.canvas.translate(self.options.horizontalMargin,
|
||||
self.options.verticalMargin)
|
||||
if isBack:
|
||||
self.canvas.translate(self.options.back_offset, self.options.back_offset_height)
|
||||
self.canvas.translate(self.options.back_offset,
|
||||
self.options.back_offset_height)
|
||||
self.canvas.translate(x * self.options.dividerWidthReserved,
|
||||
y * self.options.dividerHeightReserved)
|
||||
|
||||
# actual drawing
|
||||
if not self.options.tabs_only:
|
||||
self.drawOutline(card, x, y, rightSide, isBack, card.getType().getTypeNames() == ('Expansion',))
|
||||
self.drawOutline(card, x, y, rightSide, isBack,
|
||||
card.getType().getTypeNames() == ('Expansion', ))
|
||||
|
||||
if self.options.wrapper:
|
||||
wrap = "front"
|
||||
@ -671,7 +760,8 @@ class DividerDrawer(object):
|
||||
minFontsize = 6
|
||||
fontname = self.fontNameRegular
|
||||
font = pdfmetrics.getFont(fontname)
|
||||
fontHeightRelative = (font.face.ascent + abs(font.face.descent)) / 1000.0
|
||||
fontHeightRelative = (
|
||||
font.face.ascent + abs(font.face.descent)) / 1000.0
|
||||
|
||||
canFit = False
|
||||
|
||||
@ -685,8 +775,8 @@ class DividerDrawer(object):
|
||||
'width': self.options.paperheight}]
|
||||
|
||||
for layout in layouts:
|
||||
availableMargin = layout[
|
||||
'totalMarginHeight'] - layout['minMarginHeight']
|
||||
availableMargin = layout['totalMarginHeight'] - layout[
|
||||
'minMarginHeight']
|
||||
fontsize = availableMargin / fontHeightRelative
|
||||
fontsize = min(maxFontsize, fontsize)
|
||||
if fontsize >= minFontsize:
|
||||
@ -725,7 +815,8 @@ class DividerDrawer(object):
|
||||
|
||||
def drawDividers(self, cards):
|
||||
# split into pages
|
||||
cards = split(cards, self.options.numDividersVertical * self.options.numDividersHorizontal)
|
||||
cards = split(cards, self.options.numDividersVertical *
|
||||
self.options.numDividersHorizontal)
|
||||
|
||||
# Starting with tabs on the left or the right?
|
||||
if self.options.tab_side in ["right-alternate", "right"]:
|
||||
@ -738,14 +829,21 @@ class DividerDrawer(object):
|
||||
# remember whether we start with odd or even divider for tab
|
||||
# location
|
||||
pageStartOdd = self.odd
|
||||
if not self.options.no_page_footer and (not self.options.tabs_only and self.options.order != "global"):
|
||||
if not self.options.no_page_footer and (
|
||||
not self.options.tabs_only and
|
||||
self.options.order != "global"):
|
||||
self.drawSetNames(pageCards)
|
||||
for i, card in enumerate(pageCards):
|
||||
# print card
|
||||
x = i % self.options.numDividersHorizontal
|
||||
y = i / self.options.numDividersHorizontal
|
||||
self.canvas.saveState()
|
||||
self.drawDivider(card, x, self.options.numDividersVertical - 1 - y, isBack=False, divider_text=self.options.text_front, divider_text2=self.options.text_back)
|
||||
self.drawDivider(card,
|
||||
x,
|
||||
self.options.numDividersVertical - 1 - y,
|
||||
isBack=False,
|
||||
divider_text=self.options.text_front,
|
||||
divider_text2=self.options.text_back)
|
||||
self.canvas.restoreState()
|
||||
self.odd = not self.odd
|
||||
self.canvas.showPage()
|
||||
@ -760,10 +858,15 @@ class DividerDrawer(object):
|
||||
self.odd = pageStartOdd
|
||||
for i, card in enumerate(pageCards):
|
||||
# print card
|
||||
x = (self.options.numDividersHorizontal - 1 - i) % self.options.numDividersHorizontal
|
||||
x = (self.options.numDividersHorizontal - 1 - i
|
||||
) % self.options.numDividersHorizontal
|
||||
y = i / self.options.numDividersHorizontal
|
||||
self.canvas.saveState()
|
||||
self.drawDivider(card, x, self.options.numDividersVertical - 1 - y, isBack=True, divider_text=self.options.text_back)
|
||||
self.drawDivider(card,
|
||||
x,
|
||||
self.options.numDividersVertical - 1 - y,
|
||||
isBack=True,
|
||||
divider_text=self.options.text_back)
|
||||
self.canvas.restoreState()
|
||||
self.odd = not self.odd
|
||||
self.canvas.showPage()
|
||||
|
||||
391
ez_setup.py
391
ez_setup.py
@ -1,391 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Setuptools bootstrapping installer.
|
||||
|
||||
Run this script to install or upgrade setuptools.
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import zipfile
|
||||
import optparse
|
||||
import subprocess
|
||||
import platform
|
||||
import textwrap
|
||||
import contextlib
|
||||
import warnings
|
||||
|
||||
from distutils import log
|
||||
|
||||
try:
|
||||
from urllib.request import urlopen
|
||||
except ImportError:
|
||||
from urllib2 import urlopen
|
||||
|
||||
try:
|
||||
from site import USER_SITE
|
||||
except ImportError:
|
||||
USER_SITE = None
|
||||
|
||||
DEFAULT_VERSION = "18.5"
|
||||
DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/"
|
||||
DEFAULT_SAVE_DIR = os.curdir
|
||||
|
||||
|
||||
def _python_cmd(*args):
|
||||
"""
|
||||
Execute a command.
|
||||
|
||||
Return True if the command succeeded.
|
||||
"""
|
||||
args = (sys.executable,) + args
|
||||
return subprocess.call(args) == 0
|
||||
|
||||
|
||||
def _install(archive_filename, install_args=()):
|
||||
"""Install Setuptools."""
|
||||
with archive_context(archive_filename):
|
||||
# installing
|
||||
log.warn('Installing Setuptools')
|
||||
if not _python_cmd('setup.py', 'install', *install_args):
|
||||
log.warn('Something went wrong during the installation.')
|
||||
log.warn('See the error message above.')
|
||||
# exitcode will be 2
|
||||
return 2
|
||||
|
||||
|
||||
def _build_egg(egg, archive_filename, to_dir):
|
||||
"""Build Setuptools egg."""
|
||||
with archive_context(archive_filename):
|
||||
# building an egg
|
||||
log.warn('Building a Setuptools egg in %s', to_dir)
|
||||
_python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
|
||||
# returning the result
|
||||
log.warn(egg)
|
||||
if not os.path.exists(egg):
|
||||
raise IOError('Could not build the egg.')
|
||||
|
||||
|
||||
class ContextualZipFile(zipfile.ZipFile):
|
||||
|
||||
"""Supplement ZipFile class to support context manager for Python 2.6."""
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
self.close()
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
"""Construct a ZipFile or ContextualZipFile as appropriate."""
|
||||
if hasattr(zipfile.ZipFile, '__exit__'):
|
||||
return zipfile.ZipFile(*args, **kwargs)
|
||||
return super(ContextualZipFile, cls).__new__(cls)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def archive_context(filename):
|
||||
"""
|
||||
Unzip filename to a temporary directory, set to the cwd.
|
||||
|
||||
The unzipped target is cleaned up after.
|
||||
"""
|
||||
tmpdir = tempfile.mkdtemp()
|
||||
log.warn('Extracting in %s', tmpdir)
|
||||
old_wd = os.getcwd()
|
||||
try:
|
||||
os.chdir(tmpdir)
|
||||
with ContextualZipFile(filename) as archive:
|
||||
archive.extractall()
|
||||
|
||||
# going in the directory
|
||||
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
|
||||
os.chdir(subdir)
|
||||
log.warn('Now working in %s', subdir)
|
||||
yield
|
||||
|
||||
finally:
|
||||
os.chdir(old_wd)
|
||||
shutil.rmtree(tmpdir)
|
||||
|
||||
|
||||
def _do_download(version, download_base, to_dir, download_delay):
|
||||
"""Download Setuptools."""
|
||||
egg = os.path.join(to_dir, 'setuptools-%s-py%d.%d.egg'
|
||||
% (version, sys.version_info[0], sys.version_info[1]))
|
||||
if not os.path.exists(egg):
|
||||
archive = download_setuptools(version, download_base,
|
||||
to_dir, download_delay)
|
||||
_build_egg(egg, archive, to_dir)
|
||||
sys.path.insert(0, egg)
|
||||
|
||||
# Remove previously-imported pkg_resources if present (see
|
||||
# https://bitbucket.org/pypa/setuptools/pull-request/7/ for details).
|
||||
if 'pkg_resources' in sys.modules:
|
||||
del sys.modules['pkg_resources']
|
||||
|
||||
import setuptools
|
||||
setuptools.bootstrap_install_from = egg
|
||||
|
||||
|
||||
def use_setuptools(
|
||||
version=DEFAULT_VERSION, download_base=DEFAULT_URL,
|
||||
to_dir=DEFAULT_SAVE_DIR, download_delay=15):
|
||||
"""
|
||||
Ensure that a setuptools version is installed.
|
||||
|
||||
Return None. Raise SystemExit if the requested version
|
||||
or later cannot be installed.
|
||||
"""
|
||||
to_dir = os.path.abspath(to_dir)
|
||||
|
||||
# prior to importing, capture the module state for
|
||||
# representative modules.
|
||||
rep_modules = 'pkg_resources', 'setuptools'
|
||||
imported = set(sys.modules).intersection(rep_modules)
|
||||
|
||||
try:
|
||||
import pkg_resources
|
||||
pkg_resources.require("setuptools>=" + version)
|
||||
# a suitable version is already installed
|
||||
return
|
||||
except ImportError:
|
||||
# pkg_resources not available; setuptools is not installed; download
|
||||
pass
|
||||
except pkg_resources.DistributionNotFound:
|
||||
# no version of setuptools was found; allow download
|
||||
pass
|
||||
except pkg_resources.VersionConflict as VC_err:
|
||||
if imported:
|
||||
_conflict_bail(VC_err, version)
|
||||
|
||||
# otherwise, unload pkg_resources to allow the downloaded version to
|
||||
# take precedence.
|
||||
del pkg_resources
|
||||
_unload_pkg_resources()
|
||||
|
||||
return _do_download(version, download_base, to_dir, download_delay)
|
||||
|
||||
|
||||
def _conflict_bail(VC_err, version):
|
||||
"""
|
||||
Setuptools was imported prior to invocation, so it is
|
||||
unsafe to unload it. Bail out.
|
||||
"""
|
||||
conflict_tmpl = textwrap.dedent("""
|
||||
The required version of setuptools (>={version}) is not available,
|
||||
and can't be installed while this script is running. Please
|
||||
install a more recent version first, using
|
||||
'easy_install -U setuptools'.
|
||||
|
||||
(Currently using {VC_err.args[0]!r})
|
||||
""")
|
||||
msg = conflict_tmpl.format(**locals())
|
||||
sys.stderr.write(msg)
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
def _unload_pkg_resources():
|
||||
del_modules = [
|
||||
name for name in sys.modules
|
||||
if name.startswith('pkg_resources')
|
||||
]
|
||||
for mod_name in del_modules:
|
||||
del sys.modules[mod_name]
|
||||
|
||||
|
||||
def _clean_check(cmd, target):
|
||||
"""
|
||||
Run the command to download target.
|
||||
|
||||
If the command fails, clean up before re-raising the error.
|
||||
"""
|
||||
try:
|
||||
subprocess.check_call(cmd)
|
||||
except subprocess.CalledProcessError:
|
||||
if os.access(target, os.F_OK):
|
||||
os.unlink(target)
|
||||
raise
|
||||
|
||||
|
||||
def download_file_powershell(url, target):
|
||||
"""
|
||||
Download the file at url to target using Powershell.
|
||||
|
||||
Powershell will validate trust.
|
||||
Raise an exception if the command cannot complete.
|
||||
"""
|
||||
target = os.path.abspath(target)
|
||||
ps_cmd = (
|
||||
"[System.Net.WebRequest]::DefaultWebProxy.Credentials = "
|
||||
"[System.Net.CredentialCache]::DefaultCredentials; "
|
||||
"(new-object System.Net.WebClient).DownloadFile(%(url)r, %(target)r)"
|
||||
% vars()
|
||||
)
|
||||
cmd = [
|
||||
'powershell',
|
||||
'-Command',
|
||||
ps_cmd,
|
||||
]
|
||||
_clean_check(cmd, target)
|
||||
|
||||
|
||||
def has_powershell():
|
||||
"""Determine if Powershell is available."""
|
||||
if platform.system() != 'Windows':
|
||||
return False
|
||||
cmd = ['powershell', '-Command', 'echo test']
|
||||
with open(os.path.devnull, 'wb') as devnull:
|
||||
try:
|
||||
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
|
||||
except Exception:
|
||||
return False
|
||||
return True
|
||||
download_file_powershell.viable = has_powershell
|
||||
|
||||
|
||||
def download_file_curl(url, target):
|
||||
cmd = ['curl', url, '--silent', '--output', target]
|
||||
_clean_check(cmd, target)
|
||||
|
||||
|
||||
def has_curl():
|
||||
cmd = ['curl', '--version']
|
||||
with open(os.path.devnull, 'wb') as devnull:
|
||||
try:
|
||||
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
|
||||
except Exception:
|
||||
return False
|
||||
return True
|
||||
download_file_curl.viable = has_curl
|
||||
|
||||
|
||||
def download_file_wget(url, target):
|
||||
cmd = ['wget', url, '--quiet', '--output-document', target]
|
||||
_clean_check(cmd, target)
|
||||
|
||||
|
||||
def has_wget():
|
||||
cmd = ['wget', '--version']
|
||||
with open(os.path.devnull, 'wb') as devnull:
|
||||
try:
|
||||
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
|
||||
except Exception:
|
||||
return False
|
||||
return True
|
||||
download_file_wget.viable = has_wget
|
||||
|
||||
|
||||
def download_file_insecure(url, target):
|
||||
"""Use Python to download the file, without connection authentication."""
|
||||
src = urlopen(url)
|
||||
try:
|
||||
# Read all the data in one block.
|
||||
data = src.read()
|
||||
finally:
|
||||
src.close()
|
||||
|
||||
# Write all the data in one block to avoid creating a partial file.
|
||||
with open(target, "wb") as dst:
|
||||
dst.write(data)
|
||||
download_file_insecure.viable = lambda: True
|
||||
|
||||
|
||||
def get_best_downloader():
|
||||
downloaders = (
|
||||
download_file_powershell,
|
||||
download_file_curl,
|
||||
download_file_wget,
|
||||
download_file_insecure,
|
||||
)
|
||||
viable_downloaders = (dl for dl in downloaders if dl.viable())
|
||||
return next(viable_downloaders, None)
|
||||
|
||||
|
||||
def download_setuptools(
|
||||
version=DEFAULT_VERSION, download_base=DEFAULT_URL,
|
||||
to_dir=DEFAULT_SAVE_DIR, delay=15,
|
||||
downloader_factory=get_best_downloader):
|
||||
"""
|
||||
Download setuptools from a specified location and return its filename.
|
||||
|
||||
`version` should be a valid setuptools version number that is available
|
||||
as an sdist for download under the `download_base` URL (which should end
|
||||
with a '/'). `to_dir` is the directory where the egg will be downloaded.
|
||||
`delay` is the number of seconds to pause before an actual download
|
||||
attempt.
|
||||
|
||||
``downloader_factory`` should be a function taking no arguments and
|
||||
returning a function for downloading a URL to a target.
|
||||
"""
|
||||
# making sure we use the absolute path
|
||||
to_dir = os.path.abspath(to_dir)
|
||||
zip_name = "setuptools-%s.zip" % version
|
||||
url = download_base + zip_name
|
||||
saveto = os.path.join(to_dir, zip_name)
|
||||
if not os.path.exists(saveto): # Avoid repeated downloads
|
||||
log.warn("Downloading %s", url)
|
||||
downloader = downloader_factory()
|
||||
downloader(url, saveto)
|
||||
return os.path.realpath(saveto)
|
||||
|
||||
|
||||
def _build_install_args(options):
|
||||
"""
|
||||
Build the arguments to 'python setup.py install' on the setuptools package.
|
||||
|
||||
Returns list of command line arguments.
|
||||
"""
|
||||
return ['--user'] if options.user_install else []
|
||||
|
||||
|
||||
def _parse_args():
|
||||
"""Parse the command line for options."""
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option(
|
||||
'--user', dest='user_install', action='store_true', default=False,
|
||||
help='install in user site package (requires Python 2.6 or later)')
|
||||
parser.add_option(
|
||||
'--download-base', dest='download_base', metavar="URL",
|
||||
default=DEFAULT_URL,
|
||||
help='alternative URL from where to download the setuptools package')
|
||||
parser.add_option(
|
||||
'--insecure', dest='downloader_factory', action='store_const',
|
||||
const=lambda: download_file_insecure, default=get_best_downloader,
|
||||
help='Use internal, non-validating downloader'
|
||||
)
|
||||
parser.add_option(
|
||||
'--version', help="Specify which version to download",
|
||||
default=DEFAULT_VERSION,
|
||||
)
|
||||
parser.add_option(
|
||||
'--to-dir',
|
||||
help="Directory to save (and re-use) package",
|
||||
default=DEFAULT_SAVE_DIR,
|
||||
)
|
||||
options, args = parser.parse_args()
|
||||
# positional arguments are ignored
|
||||
return options
|
||||
|
||||
|
||||
def _download_args(options):
|
||||
"""Return args for download_setuptools function from cmdline args."""
|
||||
return dict(
|
||||
version=options.version,
|
||||
download_base=options.download_base,
|
||||
downloader_factory=options.downloader_factory,
|
||||
to_dir=options.to_dir,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
"""Install or upgrade setuptools and EasyInstall."""
|
||||
options = _parse_args()
|
||||
archive = download_setuptools(**_download_args(options))
|
||||
return _install(archive, _build_install_args(options))
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
1
setup.py
1
setup.py
@ -23,4 +23,3 @@ setup(
|
||||
author_email="sumpfork@mailmight.net",
|
||||
description="Divider Generation for the Dominion Card Game"
|
||||
)
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ from ..domdiv import cards as domdiv_cards
|
||||
class TestCardDB(unittest.TestCase):
|
||||
|
||||
def test_cardread(self):
|
||||
options, args = domdiv.parse_opts(['commandname'])
|
||||
options = domdiv.parse_opts([])
|
||||
options.data_path = '.'
|
||||
cards = domdiv.read_write_card_data(options)
|
||||
self.assertEquals(len(cards), 383)
|
||||
@ -36,13 +36,13 @@ class TestCardDB(unittest.TestCase):
|
||||
|
||||
def test_languages(self):
|
||||
# for now, just test that they load
|
||||
options, args = domdiv.parse_opts(['commandname', '--language', 'it'])
|
||||
options = domdiv.parse_opts(['--language', 'it'])
|
||||
options.data_path = '.'
|
||||
cards = domdiv.read_write_card_data(options)
|
||||
self.assertTrue(cards, 'Italians cards did not read properly')
|
||||
self.assertIn("Maledizione", [card.name for card in cards])
|
||||
|
||||
options, args = domdiv.parse_opts(['commandname', '--language', 'de'])
|
||||
options = domdiv.parse_opts(['--language', 'de'])
|
||||
options.data_path = '.'
|
||||
cards = domdiv.read_write_card_data(options)
|
||||
self.assertTrue(cards, 'German cards did not read properly')
|
||||
|
||||
13
tests/codestyle_tests.py
Normal file
13
tests/codestyle_tests.py
Normal file
@ -0,0 +1,13 @@
|
||||
import unittest
|
||||
import pycodestyle
|
||||
import glob
|
||||
|
||||
|
||||
class TestCodeFormat(unittest.TestCase):
|
||||
|
||||
def test_conformance(self):
|
||||
"""Test that we conform to PEP-8."""
|
||||
style = pycodestyle.StyleGuide(max_line_length=120)
|
||||
result = style.check_files(glob.glob('*.py') + glob.glob('domdiv/*.py') + glob.glob('tests/*.py'))
|
||||
self.assertEqual(result.total_errors, 0,
|
||||
"Found code style errors (and warnings).")
|
||||
@ -7,7 +7,7 @@ class TestLayout(unittest.TestCase):
|
||||
|
||||
def test_horizontal(self):
|
||||
# should be the default
|
||||
options, args = domdiv.parse_opts(['commandname'])
|
||||
options = domdiv.parse_opts([])
|
||||
self.assertEquals(options.orientation, 'horizontal')
|
||||
domdiv.calculate_layout(options)
|
||||
self.assertEquals(options.numDividersHorizontal, 2)
|
||||
@ -17,7 +17,7 @@ class TestLayout(unittest.TestCase):
|
||||
self.assertEquals(options.dividerHeight, 5.9 * cm + options.labelHeight)
|
||||
|
||||
def test_vertical(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--orientation', 'vertical'])
|
||||
options = domdiv.parse_opts(['--orientation', 'vertical'])
|
||||
self.assertEquals(options.orientation, 'vertical')
|
||||
domdiv.calculate_layout(options)
|
||||
self.assertEquals(options.numDividersHorizontal, 3)
|
||||
@ -27,9 +27,8 @@ class TestLayout(unittest.TestCase):
|
||||
self.assertEquals(options.dividerHeight, 9.1 * cm + options.labelHeight)
|
||||
|
||||
def test_sleeved(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--size', 'sleeved'])
|
||||
options = domdiv.parse_opts(['--size', 'sleeved'])
|
||||
domdiv.calculate_layout(options)
|
||||
self.assertEquals(options.dividerWidth, 9.4 * cm)
|
||||
self.assertEquals(options.labelHeight, 0.9 * cm)
|
||||
self.assertEquals(options.dividerHeight, 6.15 * cm + options.labelHeight)
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import unittest
|
||||
from .. import domdiv
|
||||
from reportlab.lib.units import cm
|
||||
|
||||
|
||||
class TestTextTabs(unittest.TestCase):
|
||||
@ -10,7 +9,7 @@ class TestTextTabs(unittest.TestCase):
|
||||
####################
|
||||
def test_text_tabs_default(self):
|
||||
# should be the default
|
||||
options, args = domdiv.parse_opts(['commandname'])
|
||||
options = domdiv.parse_opts([])
|
||||
self.assertEquals(options.text_front, 'card')
|
||||
self.assertEquals(options.text_back, 'rules')
|
||||
self.assertEquals(options.tab_name_align, 'left')
|
||||
@ -22,62 +21,74 @@ class TestTextTabs(unittest.TestCase):
|
||||
# Card Text Tests
|
||||
####################
|
||||
def test_text_card_rules(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--front', 'card', '--back', 'rules'])
|
||||
options = domdiv.parse_opts(
|
||||
['--front', 'card', '--back', 'rules'])
|
||||
self.assertEquals(options.text_front, 'card')
|
||||
self.assertEquals(options.text_back, 'rules')
|
||||
|
||||
def test_text_card_blank(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--front', 'card', '--back', 'blank'])
|
||||
options = domdiv.parse_opts(
|
||||
['--front', 'card', '--back', 'blank'])
|
||||
self.assertEquals(options.text_front, 'card')
|
||||
self.assertEquals(options.text_back, 'blank')
|
||||
|
||||
def test_text_card_card(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--front', 'card', '--back', 'card'])
|
||||
options = domdiv.parse_opts(
|
||||
['--front', 'card', '--back', 'card'])
|
||||
self.assertEquals(options.text_front, 'card')
|
||||
self.assertEquals(options.text_back, 'card')
|
||||
|
||||
def test_text_card_none(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--front', 'card', '--back', 'none'])
|
||||
options = domdiv.parse_opts(
|
||||
['--front', 'card', '--back', 'none'])
|
||||
self.assertEquals(options.text_front, 'card')
|
||||
self.assertEquals(options.text_back, 'none')
|
||||
|
||||
def test_text_rules_rules(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--front', 'rules', '--back', 'rules'])
|
||||
options = domdiv.parse_opts(
|
||||
['--front', 'rules', '--back', 'rules'])
|
||||
self.assertEquals(options.text_front, 'rules')
|
||||
self.assertEquals(options.text_back, 'rules')
|
||||
|
||||
def test_text_rules_blank(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--front', 'rules', '--back', 'blank'])
|
||||
options = domdiv.parse_opts(
|
||||
['--front', 'rules', '--back', 'blank'])
|
||||
self.assertEquals(options.text_front, 'rules')
|
||||
self.assertEquals(options.text_back, 'blank')
|
||||
|
||||
def test_text_rules_card(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--front', 'rules', '--back', 'card'])
|
||||
options = domdiv.parse_opts(
|
||||
['--front', 'rules', '--back', 'card'])
|
||||
self.assertEquals(options.text_front, 'rules')
|
||||
self.assertEquals(options.text_back, 'card')
|
||||
|
||||
def test_text_rules_none(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--front', 'rules', '--back', 'none'])
|
||||
options = domdiv.parse_opts(
|
||||
['--front', 'rules', '--back', 'none'])
|
||||
self.assertEquals(options.text_front, 'rules')
|
||||
self.assertEquals(options.text_back, 'none')
|
||||
|
||||
def test_text_blank_rules(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--front', 'blank', '--back', 'rules'])
|
||||
options = domdiv.parse_opts(
|
||||
['--front', 'blank', '--back', 'rules'])
|
||||
self.assertEquals(options.text_front, 'blank')
|
||||
self.assertEquals(options.text_back, 'rules')
|
||||
|
||||
def test_text_blank_blank(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--front', 'blank', '--back', 'blank'])
|
||||
options = domdiv.parse_opts(
|
||||
['--front', 'blank', '--back', 'blank'])
|
||||
self.assertEquals(options.text_front, 'blank')
|
||||
self.assertEquals(options.text_back, 'blank')
|
||||
|
||||
def test_text_blank_card(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--front', 'blank', '--back', 'card'])
|
||||
options = domdiv.parse_opts(
|
||||
['--front', 'blank', '--back', 'card'])
|
||||
self.assertEquals(options.text_front, 'blank')
|
||||
self.assertEquals(options.text_back, 'card')
|
||||
|
||||
def test_text_blank_none(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--front', 'blank', '--back', 'none'])
|
||||
options = domdiv.parse_opts(
|
||||
['--front', 'blank', '--back', 'none'])
|
||||
self.assertEquals(options.text_front, 'blank')
|
||||
self.assertEquals(options.text_back, 'none')
|
||||
|
||||
@ -86,7 +97,8 @@ class TestTextTabs(unittest.TestCase):
|
||||
####################
|
||||
# --tab_name_align left
|
||||
def test_tab_left_left(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'left', '--tab_side', 'left'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'left', '--tab_side', 'left'])
|
||||
self.assertEquals(options.tab_name_align, 'left')
|
||||
self.assertEquals(options.tab_side, 'left')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -94,7 +106,8 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'left')
|
||||
|
||||
def test_tab_left_right(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'left', '--tab_side', 'right'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'left', '--tab_side', 'right'])
|
||||
self.assertEquals(options.tab_name_align, 'left')
|
||||
self.assertEquals(options.tab_side, 'right')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -102,7 +115,9 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'right')
|
||||
|
||||
def test_tab_left_leftalt(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'left', '--tab_side', 'left-alternate'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'left', '--tab_side',
|
||||
'left-alternate'])
|
||||
self.assertEquals(options.tab_name_align, 'left')
|
||||
self.assertEquals(options.tab_side, 'left-alternate')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -110,7 +125,9 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'left-alternate')
|
||||
|
||||
def test_tab_left_rightalt(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'left', '--tab_side', 'right-alternate'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'left', '--tab_side',
|
||||
'right-alternate'])
|
||||
self.assertEquals(options.tab_name_align, 'left')
|
||||
self.assertEquals(options.tab_side, 'right-alternate')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -118,7 +135,8 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'right-alternate')
|
||||
|
||||
def test_tab_left_full(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'left', '--tab_side', 'full'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'left', '--tab_side', 'full'])
|
||||
self.assertEquals(options.tab_name_align, 'left')
|
||||
self.assertEquals(options.tab_side, 'full')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -127,7 +145,8 @@ class TestTextTabs(unittest.TestCase):
|
||||
|
||||
# --tab_name_align right
|
||||
def test_tab_right_left(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'right', '--tab_side', 'left'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'right', '--tab_side', 'left'])
|
||||
self.assertEquals(options.tab_name_align, 'right')
|
||||
self.assertEquals(options.tab_side, 'left')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -135,7 +154,8 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'left')
|
||||
|
||||
def test_tab_right_right(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'right', '--tab_side', 'right'])
|
||||
options = domdiv.parse_opts(['--tab_name_align',
|
||||
'right', '--tab_side', 'right'])
|
||||
self.assertEquals(options.tab_name_align, 'right')
|
||||
self.assertEquals(options.tab_side, 'right')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -143,7 +163,9 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'right')
|
||||
|
||||
def test_tab_right_leftalt(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'right', '--tab_side', 'left-alternate'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'right', '--tab_side',
|
||||
'left-alternate'])
|
||||
self.assertEquals(options.tab_name_align, 'right')
|
||||
self.assertEquals(options.tab_side, 'left-alternate')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -151,7 +173,9 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'left-alternate')
|
||||
|
||||
def test_tab_right_rightalt(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'right', '--tab_side', 'right-alternate'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'right', '--tab_side',
|
||||
'right-alternate'])
|
||||
self.assertEquals(options.tab_name_align, 'right')
|
||||
self.assertEquals(options.tab_side, 'right-alternate')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -159,7 +183,8 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'right-alternate')
|
||||
|
||||
def test_tab_right_full(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'right', '--tab_side', 'full'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'right', '--tab_side', 'full'])
|
||||
self.assertEquals(options.tab_name_align, 'right')
|
||||
self.assertEquals(options.tab_side, 'full')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -168,7 +193,8 @@ class TestTextTabs(unittest.TestCase):
|
||||
|
||||
# --tab_name_align edge
|
||||
def test_tab_edge_left(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'edge', '--tab_side', 'left'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'edge', '--tab_side', 'left'])
|
||||
self.assertEquals(options.tab_name_align, 'edge')
|
||||
self.assertEquals(options.tab_side, 'left')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -176,7 +202,8 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'left')
|
||||
|
||||
def test_tab_edge_right(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'edge', '--tab_side', 'right'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'edge', '--tab_side', 'right'])
|
||||
self.assertEquals(options.tab_name_align, 'edge')
|
||||
self.assertEquals(options.tab_side, 'right')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -184,7 +211,9 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'right')
|
||||
|
||||
def test_tab_edge_leftalt(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'edge', '--tab_side', 'left-alternate'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'edge', '--tab_side',
|
||||
'left-alternate'])
|
||||
self.assertEquals(options.tab_name_align, 'edge')
|
||||
self.assertEquals(options.tab_side, 'left-alternate')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -192,7 +221,9 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'left-alternate')
|
||||
|
||||
def test_tab_edge_rightalt(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'edge', '--tab_side', 'right-alternate'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'edge', '--tab_side',
|
||||
'right-alternate'])
|
||||
self.assertEquals(options.tab_name_align, 'edge')
|
||||
self.assertEquals(options.tab_side, 'right-alternate')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -200,16 +231,19 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'right-alternate')
|
||||
|
||||
def test_tab_edge_full(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'edge', '--tab_side', 'full'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'edge', '--tab_side', 'full'])
|
||||
self.assertEquals(options.tab_name_align, 'edge')
|
||||
self.assertEquals(options.tab_side, 'full')
|
||||
domdiv.calculate_layout(options)
|
||||
self.assertEquals(options.tab_name_align, 'left') # special check for odd condition
|
||||
self.assertEquals(options.tab_name_align,
|
||||
'left') # special check for odd condition
|
||||
self.assertEquals(options.tab_side, 'full')
|
||||
|
||||
# --tab_name_align centre
|
||||
def test_tab_centre_left(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'centre', '--tab_side', 'left'])
|
||||
options = domdiv.parse_opts(['--tab_name_align',
|
||||
'centre', '--tab_side', 'left'])
|
||||
self.assertEquals(options.tab_name_align, 'centre')
|
||||
self.assertEquals(options.tab_side, 'left')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -217,7 +251,8 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'left')
|
||||
|
||||
def test_tab_centre_right(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'centre', '--tab_side', 'right'])
|
||||
options = domdiv.parse_opts(['--tab_name_align',
|
||||
'centre', '--tab_side', 'right'])
|
||||
self.assertEquals(options.tab_name_align, 'centre')
|
||||
self.assertEquals(options.tab_side, 'right')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -225,7 +260,9 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'right')
|
||||
|
||||
def test_tab_centre_leftalt(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'centre', '--tab_side', 'left-alternate'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'centre', '--tab_side',
|
||||
'left-alternate'])
|
||||
self.assertEquals(options.tab_name_align, 'centre')
|
||||
self.assertEquals(options.tab_side, 'left-alternate')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -233,7 +270,9 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'left-alternate')
|
||||
|
||||
def test_tab_centre_rightalt(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'centre', '--tab_side', 'right-alternate'])
|
||||
options = domdiv.parse_opts(
|
||||
['--tab_name_align', 'centre', '--tab_side',
|
||||
'right-alternate'])
|
||||
self.assertEquals(options.tab_name_align, 'centre')
|
||||
self.assertEquals(options.tab_side, 'right-alternate')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -241,7 +280,8 @@ class TestTextTabs(unittest.TestCase):
|
||||
self.assertEquals(options.tab_side, 'right-alternate')
|
||||
|
||||
def test_tab_centre_full(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'centre', '--tab_side', 'full'])
|
||||
options = domdiv.parse_opts(['--tab_name_align',
|
||||
'centre', '--tab_side', 'full'])
|
||||
self.assertEquals(options.tab_name_align, 'centre')
|
||||
self.assertEquals(options.tab_side, 'full')
|
||||
domdiv.calculate_layout(options)
|
||||
@ -250,11 +290,11 @@ class TestTextTabs(unittest.TestCase):
|
||||
|
||||
# --tab_name_align center. Just do one since this is an alias to centre
|
||||
def test_tab_center_left(self):
|
||||
options, args = domdiv.parse_opts(['commandname', '--tab_name_align', 'center', '--tab_side', 'left'])
|
||||
options = domdiv.parse_opts(['--tab_name_align',
|
||||
'center', '--tab_side', 'left'])
|
||||
self.assertEquals(options.tab_name_align, 'center')
|
||||
self.assertEquals(options.tab_side, 'left')
|
||||
domdiv.calculate_layout(options)
|
||||
self.assertEquals(options.tab_name_align, 'centre') # check for change in value
|
||||
self.assertEquals(options.tab_name_align,
|
||||
'centre') # check for change in value
|
||||
self.assertEquals(options.tab_side, 'left')
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user