From b70bd37d80e92f05730208828d7d8c2593ded87d Mon Sep 17 00:00:00 2001 From: Sumpfork Date: Wed, 6 Jul 2016 15:21:00 -0700 Subject: [PATCH] - 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 --- .travis.yml | 1 + do_release.py | 26 +- domdiv/__init__.py | 561 +++++++++++++++++++++++---------------- domdiv/cards.py | 65 +++-- domdiv/draw.py | 489 ++++++++++++++++++++-------------- ez_setup.py | 391 --------------------------- setup.py | 1 - tests/carddb_tests.py | 6 +- tests/codestyle_tests.py | 13 + tests/layout_tests.py | 7 +- tests/text_tab_tests.py | 278 ++++++++++--------- 11 files changed, 859 insertions(+), 979 deletions(-) delete mode 100644 ez_setup.py create mode 100644 tests/codestyle_tests.py diff --git a/.travis.yml b/.travis.yml index 34b80d0..c001659 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/do_release.py b/do_release.py index 60a0f21..67eefa6 100644 --- a/do_release.py +++ b/do_release.py @@ -1,33 +1,35 @@ import domdiv from __init__ import __version__ -from zipfile import ZipFile,ZIP_DEFLATED +from zipfile import ZipFile, ZIP_DEFLATED prefix = 'generated/sumpfork_dominion_tabs_' postfix = 'v' + __version__ + '.pdf' -def doit(args,main): - args = args + ' ' + prefix+main+postfix + +def doit(args, main): + args = args + ' ' + prefix + main + postfix args = args.split() fname = args[-1] print ':::Generating ' + fname domdiv.main(args, '.') return fname + argsets = [ - ('',''), - ('--orientation=vertical','vertical_'), - ('--papersize=A4','A4_'), - ('--papersize=A4 --orientation=vertical','vertical_A4_'), - ('--size=sleeved','sleeved_'), - ('--size=sleeved --orientation=vertical','vertical_sleeved_') + ('', ''), ('--orientation=vertical', 'vertical_'), + ('--papersize=A4', 'A4_'), + ('--papersize=A4 --orientation=vertical', 'vertical_A4_'), + ('--size=sleeved', 'sleeved_'), + ('--size=sleeved --orientation=vertical', 'vertical_sleeved_') ] 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() - diff --git a/domdiv/__init__.py b/domdiv/__init__.py index ea7c9e6..390d55c 100644 --- a/domdiv/__init__.py +++ b/domdiv/__init__.py @@ -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,154 +22,259 @@ 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, - 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, - 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", - 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', - 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", - help="'<%f>x<%f>' (size in cm, left/right, top/bottom), default: 1x1") - parser.add_option("--papersize", type="string", 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", - 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", - 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", - 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", - 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, - 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=[], - 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=[], - 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", - help="subset of dominion expansions to produce tabs for") - parser.add_option("--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, - help="width of lines for card outlines/crop marks") - parser.add_option("--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", - help="draw only tabs to be printed on labels, no divider outlines") - parser.add_option("--order", type="choice", 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", - help="add dividers describing each expansion set") - parser.add_option("--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", - help='centre the tabs on expansion dividers') - parser.add_option("--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", - 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, - 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", - help="don't show background artwork on tabs") - parser.add_option("--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", - help="don't print the set name at the bottom of the page.") - parser.add_option("--horizontal_gap", type=float, default=0., - help="horizontal gap between dividers in centimeters") - parser.add_option("--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", - help="Draw wrapper for cards instead of a divider for the cards") - parser.add_option("--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, - 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") +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_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_argument("--orientation", + choices=["horizontal", "vertical"], + dest="orientation", + default="horizontal", + help="horizontal or vertical, default:horizontal") + 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_argument( + "--minmargin", + dest="minmargin", + default="1x1", + help="'<%f>x<%f>' (size in cm, left/right, top/bottom), default: 1x1") + parser.add_argument("--papersize", + dest="papersize", + default=None, + help="'<%f>x<%f>' (size in cm), or 'A4', or 'LETTER'") + 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_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_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_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_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_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_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_argument( + "--expansions", + action="append", + help="subset of dominion expansions to produce tabs for") + parser.add_argument( + "--cropmarks", + action="store_true", + dest="cropmarks", + help="print crop marks on both sides, rather than tab outlines on one") + parser.add_argument("--linewidth", + type=float, + default=.1, + help="width of lines for card outlines/crop marks") + parser.add_argument( + "--write_json", + action="store_true", + dest="write_json", + help="write json version of card definitions and extras") + 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_argument( + "--order", + choices=["expansion", "global", "colour"], + dest="order", + help="sort order for the cards, whether by expansion or globally alphabetical") + parser.add_argument("--expansion_dividers", + action="store_true", + dest="expansion_dividers", + help="add dividers describing each expansion set") + 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_argument("--centre_expansion_dividers", + action="store_true", + dest="centre_expansion_dividers", + help='centre the tabs on expansion dividers') + parser.add_argument( + "--num_pages", + type=int, + default=-1, + help="stop generating after this many pages, -1 for all") + 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_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_argument("--no-tab-artwork", + action="store_true", + dest="no_tab_artwork", + help="don't show background artwork on tabs") + 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_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_argument("--horizontal_gap", + type=float, + default=0., + help="horizontal gap between dividers in centimeters") + parser.add_argument("--vertical_gap", + type=float, + default=0., + help="vertical gap between dividers in centimeters") + 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_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_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_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: options.set_icon = ['tab'] - + if options.sleeved_thick: options.thickness = 3.2 - options.sleeved = True + options.sleeved = True if options.sleeved_thin: options.thickness = 2.4 - options.sleeved = True - + options.sleeved = True + 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, - [card.name for card in cards if card.cardset.lower() == 'base']) + 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 @@ -305,24 +414,29 @@ def filter_sort_cards(cards, options): with codecs.open(card_groups_file, 'r', 'utf-8') as cardgroup_file: card_groups = json.load(cardgroup_file) # 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 - + 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 + # Initialize each of the new card groups - for group in 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 - - # go through the cards and add up the number of subgroup cards + 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() - - # fix up the group card holders count & name, and weed out the subgroup cards + 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: if card.name in card_groups.keys(): card.count += subcard_count[card.name] @@ -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 @@ -398,8 +513,6 @@ def filter_sort_cards(cards, options): if holder and count > 0: holder.setCardCount(count) cards = filteredCards - - if options.cardlist: cardlist = set() @@ -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": @@ -441,24 +558,23 @@ def calculate_layout(options, cards=[]): if options.tab_side == "full" and options.tab_name_align == "edge": # This case does not make sense since there are two tab edges in this case. So picking left edge. - print >>sys.stderr, "** Warning: Aligning card name as 'left' for 'full' tabs **" + print >> sys.stderr, "** Warning: Aligning card name as 'left' for 'full' tabs **" options.tab_name_align = "left" fixedMargins = False if options.tabs_only: # fixed for Avery 8867 for now - minmarginwidth = 0.86 * cm # was 0.76 - minmarginheight = 1.37 * cm # was 1.27 - labelHeight = 1.07 * cm # was 1.27 - labelWidth = 4.24 * cm # was 4.44 - horizontalBorderSpace = 0.96 * cm # was 0.76 - verticalBorderSpace = 0.20 * cm # was 0.01 + minmarginwidth = 0.86 * cm # was 0.76 + minmarginheight = 1.37 * cm # was 1.27 + labelHeight = 1.07 * cm # was 1.27 + labelWidth = 4.24 * cm # was 4.44 + horizontalBorderSpace = 0.96 * cm # was 0.76 + verticalBorderSpace = 0.20 * cm # was 0.01 dividerBaseHeight = 0 dividerWidth = labelWidth fixedMargins = True else: - minmarginwidth, minmarginheight = parseDimensions( - options.minmargin) + minmarginwidth, minmarginheight = parseDimensions(options.minmargin) if options.tab_side == "full": labelWidth = dividerWidth else: @@ -468,18 +584,20 @@ def calculate_layout(options, cards=[]): verticalBorderSpace = options.vertical_gap * cm dividerHeight = dividerBaseHeight + labelHeight - - dividerWidthReserved = dividerWidth + horizontalBorderSpace + + 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 - notch_height = 0.25 * cm # thumb notch height - notch_width1 = options.notch_length * cm # thumb notch width: top away from tab - notch_width2 = 0.00 * cm # thumb notch width: bottom on side of tab + notch_height = 0.25 * cm # thumb notch height + notch_width1 = options.notch_length * cm # thumb notch width: top away from tab + notch_width2 = 0.00 * cm # thumb notch width: bottom on side of tab add_opt(options, 'dividerWidth', dividerWidth) add_opt(options, 'dividerHeight', dividerHeight) @@ -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) diff --git a/domdiv/cards.py b/domdiv/cards.py index 94a1a77..d23fb57 100644 --- a/domdiv/cards.py +++ b/domdiv/cards.py @@ -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() @@ -115,13 +115,13 @@ class Card(object): self.count = getType(self.types).getTypeDefaultCardCount() else: self.count = count - + def getCardCount(self): return self.count - + def setCardCount(self, value): self.count = value - + def getStackHeight(self, thickness): # return height of the stacked cards in cm. Using hight in cm of a stack of 60 Copper cards as thickness. return self.count * cm * (thickness / 60.0) + 2 @@ -147,11 +147,10 @@ class Card(object): def isPrize(self): return 'Prize' in self.getType().getTypeNames() - + 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(): @@ -215,47 +214,47 @@ class CardType(object): cardTypes = [ CardType(('Action',), 'action.png'), CardType(('Action', 'Attack'), 'action.png'), - CardType(('Action', 'Attack', 'Prize'), 'action.png',1), + CardType(('Action', 'Attack', 'Prize'), 'action.png', 1), CardType(('Action', 'Reaction'), 'reaction.png'), - CardType(('Action', 'Victory'), 'action-victory.png',12), - CardType(('Action', 'Duration'), 'duration.png',5), + CardType(('Action', 'Victory'), 'action-victory.png', 12), + CardType(('Action', 'Duration'), 'duration.png', 5), CardType(('Action', 'Duration', 'Reaction'), 'duration-reaction.png'), CardType(('Action', 'Attack', 'Duration'), 'duration.png'), CardType(('Action', 'Looter'), 'action.png'), - CardType(('Action', 'Prize'), 'action.png',1), - CardType(('Action', 'Ruins'), 'ruins.png',10, 0, 1), - CardType(('Action', 'Shelter'), 'action-shelter.png',6), + CardType(('Action', 'Prize'), 'action.png', 1), + CardType(('Action', 'Ruins'), 'ruins.png', 10, 0, 1), + CardType(('Action', 'Shelter'), 'action-shelter.png', 6), CardType(('Action', 'Attack', 'Duration'), 'duration.png'), CardType(('Action', 'Attack', 'Looter'), 'action.png'), - CardType(('Action', 'Attack', 'Traveller'), 'action.png',5), - CardType(('Action', 'Reserve'), 'reserve.png',5), - CardType(('Action', 'Reserve', 'Victory'), 'reserve-victory.png',12), - CardType(('Action', 'Traveller'), 'action.png',5), + CardType(('Action', 'Attack', 'Traveller'), 'action.png', 5), + CardType(('Action', 'Reserve'), 'reserve.png', 5), + CardType(('Action', 'Reserve', 'Victory'), 'reserve-victory.png', 12), + CardType(('Action', 'Traveller'), 'action.png', 5), CardType(('Action', 'Gathering'), 'action.png'), CardType(('Action', 'Treasure'), 'action-treasure.png'), - CardType(('Prize',), 'action.png',1), - CardType(('Event',), 'event.png',1), + CardType(('Prize',), 'action.png', 1), + CardType(('Event',), 'event.png', 1), CardType(('Reaction',), 'reaction.png'), - CardType(('Reaction', 'Shelter'), 'reaction-shelter.png',6), - CardType(('Treasure',), 'treasure.png',10, 3, 0), + CardType(('Reaction', 'Shelter'), 'reaction-shelter.png', 6), + CardType(('Treasure',), 'treasure.png', 10, 3, 0), CardType(('Treasure', 'Attack'), 'treasure.png'), - CardType(('Treasure', 'Victory'), 'treasure-victory.png',12), - CardType(('Treasure', 'Prize'), 'treasure.png',1, 3, 0), - CardType(('Treasure', 'Reaction'), 'treasure-reaction.png',10, 0, 1), + CardType(('Treasure', 'Victory'), 'treasure-victory.png', 12), + CardType(('Treasure', 'Prize'), 'treasure.png', 1, 3, 0), + CardType(('Treasure', 'Reaction'), 'treasure-reaction.png', 10, 0, 1), CardType(('Treasure', 'Reserve'), 'reserve-treasure.png'), - CardType(('Victory',), 'victory.png',12), - CardType(('Victory', 'Reaction'), 'victory-reaction.png',12, 0, 1), - CardType(('Victory', 'Shelter'), 'victory-shelter.png',6), - CardType(('Victory', 'Castle'), 'victory.png',12), + CardType(('Victory',), 'victory.png', 12), + CardType(('Victory', 'Reaction'), 'victory-reaction.png', 12, 0, 1), + CardType(('Victory', 'Shelter'), 'victory-shelter.png', 6), + CardType(('Victory', 'Castle'), 'victory.png', 12), CardType(('Curse',), 'curse.png', 30, 3), CardType(('Trash',), 'action.png', 1), - CardType(('Prizes',), 'action.png',0), - CardType(('Events',), 'event.png',0), - CardType(('Shelters',), 'shelter.png',0), - CardType(('Expansion',), 'expansion.png',0, 4), + CardType(('Prizes',), 'action.png', 0), + CardType(('Events',), 'event.png', 0), + CardType(('Shelters',), 'shelter.png', 0), + CardType(('Expansion',), 'expansion.png', 0, 4), CardType(('Blank',), ''), - CardType(('Landmark',), 'landmark.png',1), - CardType(('Landmarks',), 'landmark.png',0) + CardType(('Landmark',), 'landmark.png', 1), + CardType(('Landmarks',), 'landmark.png', 0) ] cardTypes = dict(((c.getTypeNames(), c) for c in cardTypes)) diff --git a/domdiv/draw.py b/domdiv/draw.py index c33b84f..1ce54ed 100644 --- a/domdiv/draw.py +++ b/domdiv/draw.py @@ -20,7 +20,6 @@ def split(l, n): class DividerDrawer(object): - def __init__(self): self.odd = True self.canvas = None @@ -29,91 +28,91 @@ 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" + print >> sys.stderr, "Warning, Minion Pro Font ttf file not found! Falling back on Times" self.fontNameRegular = 'Times-Roman' self.fontNameBold = 'Times-Bold' self.fontNameOblique = 'Times-Oblique' - def getOutline(self, card, isExpansionDivider = False): - - dividerWidth = self.options.dividerWidth - dividerHeight = self.options.dividerHeight + def getOutline(self, card, isExpansionDivider=False): + + dividerWidth = self.options.dividerWidth + dividerHeight = self.options.dividerHeight dividerBaseHeight = self.options.dividerBaseHeight - tabLabelWidth = self.options.labelWidth - notch_height = self.options.notch_height # thumb notch height - notch_width1 = self.options.notch_width1 # thumb notch width: top away from tab - notch_width2 = self.options.notch_width2 # thumb notch width: bottom on side of tab - - theTabHeight = dividerHeight - dividerBaseHeight - theTabWidth = self.options.labelWidth - + tabLabelWidth = self.options.labelWidth + notch_height = self.options.notch_height # thumb notch height + notch_width1 = self.options.notch_width1 # thumb notch width: top away from tab + notch_width2 = self.options.notch_width2 # thumb notch width: bottom on side of tab + + theTabHeight = dividerHeight - dividerBaseHeight + theTabWidth = self.options.labelWidth + if isExpansionDivider: side_2_tab = (dividerWidth - theTabWidth) / 2 else: side_2_tab = 0 - + nonTabWidth = dividerWidth - tabLabelWidth - side_2_tab - + def DeltaXYtoLines(delta): - result = [] + result = [] started = False - for x,y in delta: + for x, y in delta: if not started: - last_x = x - last_y = y - started = True + last_x = x + last_y = y + started = True else: - result.append( (last_x , last_y, last_x + x, last_y + y) ) + result.append((last_x, last_y, last_x + x, last_y + y)) last_x = last_x + x last_y = last_y + y return result - + self.canvas.saveState() - + if not self.options.wrapper: # Normal Card Outline # + F+-------------------+E # | | # H+-----------------------+G D+-----+C - # | | + # | | # | Generic Divider | # | Tab Centered or to the Side | # | | # A+-------------------------------------------------+B # delta x delta y - delta = [ ( 0 , 0 ), # to A - ( dividerWidth , 0 ), #A to B - ( 0 , dividerBaseHeight ), #B to C - ( -side_2_tab , 0 ), #C to D - ( 0 , theTabHeight ), #D to E - ( -theTabWidth , 0 ), #E to F - ( 0 , -theTabHeight ), #F to G - ( -nonTabWidth , 0 ), #G to H - ( 0 , -dividerBaseHeight )] #H to A + delta = [(0, 0), # to A + (dividerWidth, 0), # A to B + (0, dividerBaseHeight), # B to C + (-side_2_tab, 0), # C to D + (0, theTabHeight), # D to E + (-theTabWidth, 0), # E to F + (0, -theTabHeight), # F to G + (-nonTabWidth, 0), # G to H + (0, -dividerBaseHeight)] # H to A self.canvas.lines(DeltaXYtoLines(delta)) - + else: # Card Wrapper Outline - notch_width3 = notch_width1 # thumb notch width: bottom away from tab - stackHeight = card.getStackHeight(self.options.thickness) + notch_width3 = notch_width1 # thumb notch width: bottom away from tab + stackHeight = card.getStackHeight(self.options.thickness) body_minus_notches = dividerBaseHeight - (2.0 * notch_height) tab_2_notch = dividerWidth - theTabWidth - side_2_tab - notch_width1 if (tab_2_notch < 0): tab_2_notch = dividerWidth - theTabWidth - side_2_tab notch_width1 = 0 # + U+-------------------+T + - # | | + # | | # + V+. . . . . . . . . .+S + - # | | + # | | # + X+---------------------+W . . . . . . . . R+----+Q # | | # Z+-------+Y +P @@ -123,10 +122,10 @@ class DividerDrawer(object): # | | # AA+-------+BB N+-------+O # | | - # + +CC. . . . . . . . . . . . . . . . . .M+ + + # + +CC. . . . . . . . . . . . . . . . . .M+ + # | | # + +DD. . . . . . . . . . . . . . . . . .L+ + - # | | + # | | # FF+-------+EE K+-------+J # | | # | Reverse Side | @@ -135,89 +134,105 @@ class DividerDrawer(object): # A+-------+B +I # | | # + C+---------------------+D G+----+H - # | | - # + E+-------------------+F + + # | | + # + E+-------------------+F + # # delta x delta y - delta = [ ( 0 , theTabHeight+notch_height), # to A - ( notch_width1, 0 ), #A to B - ( 0 , -notch_height ), #B to C - ( tab_2_notch , 0 ), #C to D - ( 0 , -theTabHeight ), #D to E - ( theTabWidth , 0 ), #E to F - ( 0 , theTabHeight ), #F to G - ( side_2_tab , 0 ), #G to H - ( 0 , notch_height ), #H to I - ( 0 , body_minus_notches ), #I to J - (-notch_width2, 0 ), #J to K - ( 0 , notch_height ), #K to L - ( 0 , stackHeight ), #L to M - ( 0 , notch_height ), #M to N - ( notch_width2, 0 ), #N to O - ( 0 , body_minus_notches ), #O to P - ( 0 , notch_height ), #P to Q - (-side_2_tab , 0 ), #Q to R - ( 0 , stackHeight ), #R to S - ( 0 , theTabHeight ), #S to T - (-theTabWidth , 0 ), #T to U - ( 0 , -theTabHeight ), #U to V - ( 0 , -stackHeight ), #V to W - (-tab_2_notch , 0 ), #W to X - ( 0 , -notch_height ), #X to Y - (-notch_width1, 0 ), #Y to Z - ( 0 , -body_minus_notches ), #Z to AA - ( notch_width3, 0 ), #AA to BB - ( 0 , -notch_height ), #BB to CC - ( 0 , -stackHeight ), #CC to DD - ( 0 , -notch_height ), #DD to EE - (-notch_width3, 0 ), #EE to FF - ( 0 , -body_minus_notches )] #FF to A + delta = [(0, theTabHeight + notch_height), # to A + (notch_width1, 0), # A to B + (0, -notch_height), # B to C + (tab_2_notch, 0), # C to D + (0, -theTabHeight), # D to E + (theTabWidth, 0), # E to F + (0, theTabHeight), # F to G + (side_2_tab, 0), # G to H + (0, notch_height), # H to I + (0, body_minus_notches), # I to J + (-notch_width2, 0), # J to K + (0, notch_height), # K to L + (0, stackHeight), # L to M + (0, notch_height), # M to N + (notch_width2, 0), # N to O + (0, body_minus_notches), # O to P + (0, notch_height), # P to Q + (-side_2_tab, 0), # Q to R + (0, stackHeight), # R to S + (0, theTabHeight), # S to T + (-theTabWidth, 0), # T to U + (0, -theTabHeight), # U to V + (0, -stackHeight), # V to W + (-tab_2_notch, 0), # W to X + (0, -notch_height), # X to Y + (-notch_width1, 0), # Y to Z + (0, -body_minus_notches), # Z to AA + (notch_width3, 0), # AA to BB + (0, -notch_height), # BB to CC + (0, -stackHeight), # CC to DD + (0, -notch_height), # DD to EE + (-notch_width3, 0), # EE to FF + (0, -body_minus_notches)] # FF to A 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 = '' % ( - path, fontsize * 1.2) + replace = '' + replace = replace % (path, fontsize * 1.2) text = re.sub('(\d+)\s(c|C)oin(s)?', replace, text) - replace = '' % ( - path, fontsize * 1.2) + replace = '' + replace = replace % (path, fontsize * 1.2) text = re.sub('\?\s(c|C)oin(s)?', replace, text) - replace = '' % ( - path, fontsize * 1.2) + replace = '' + replace = replace % (path, fontsize * 1.2) text = re.sub('empty\s(c|C)oin(s)?', replace, text) - replace = '' % ( - path, fontsize * 1.5) + replace = '' + replace = replace % (path, fontsize * 1.5) text = re.sub('\', replace, text) - replace = ' ' % ( - path, fontsize * 1.2) + replace = ' ' + replace = replace % (path, fontsize * 1.2) text = re.sub('(\d+)\sDebt', replace, text) - replace = ' ' % ( - path, fontsize * 1.2) + replace = ' ' + replace = replace % (path, fontsize * 1.2) text = re.sub('Debt', replace, text) - replace = '' % ( - path, fontsize * 1.2) + replace = '' + 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) @@ -233,7 +248,7 @@ class DividerDrawer(object): self.getOutline(card, isExpansionDivider=True) else: self.getOutline(card) - + elif self.options.cropmarks and not self.options.wrapper: cmw = 0.5 * cm @@ -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,33 +290,42 @@ 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() - + def drawCardCount(self, card, x, y, offset=-1): if card.count < 1: return 0 - - # base width is 16 (for image) + 2 (1 pt border on each side) + + # base width is 16 (for image) + 2 (1 pt border on each side) width = 18 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) self.canvas.drawCentredString(x + 8, countHeight + 4, count) return width - + def drawCost(self, card, x, y, costOffset=-1): # base width is 16 (for image) + 2 (1 pt border on each side) width = 18 @@ -312,27 +336,51 @@ 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, - mask=[255, 255, 255, 255, 255, 255]) + 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, - mask=[255, 255, 255, 255, 255, 255]) + 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, - mask=[255, 255, 255, 255, 255, 255]) + 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 self.canvas.setFont(self.fontNameBold, 12) @@ -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"): @@ -363,29 +418,30 @@ class DividerDrawer(object): translate_x = self.options.dividerWidth / 2 - self.options.labelWidth / 2 translate_y = self.options.dividerHeight - self.options.labelHeight elif not rightSide: - translate_x = self.options.dividerWidth - self.options.labelWidth + translate_x = self.options.dividerWidth - self.options.labelWidth translate_y = self.options.dividerHeight - self.options.labelHeight else: translate_x = 0 translate_y = self.options.dividerHeight - self.options.labelHeight if wrapper == "back": - translate_y = self.options.labelHeight + translate_y = self.options.labelHeight if card.isExpansion() and self.options.centre_expansion_dividers: translate_x = self.options.dividerWidth / 2 + self.options.labelWidth / 2 elif not rightSide: - translate_x = self.options.dividerWidth + translate_x = self.options.dividerWidth else: - translate_x = self.options.labelWidth - + 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) - + if wrapper == "back": self.canvas.rotate(180) - + # allow for 3 pt border on each side textWidth = self.options.labelWidth - 6 textHeight = 7 @@ -397,17 +453,24 @@ 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, - card.getType().getTabCostHeightOffset()) + textInset += self.drawCost( + card, textInset, textHeight, + card.getType().getTabCostHeightOffset()) else: textInset = 6 else: @@ -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,55 +570,65 @@ 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) if i != len(words) - 1: w += drawWordPiece(' ', fontSize) - + 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 - fontSize = 8 # use the smallest font + 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) w += drawWordPiece(word[0], fontSize) w += drawWordPiece(word[1:], fontSize - 2) - + self.canvas.restoreState() def drawText(self, card, divider_text="card", wrapper="no"): - + self.canvas.saveState() usedHeight = 0 totalHeight = self.options.dividerHeight - self.options.labelHeight - + # 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: usedHeight += self.options.notch_height - + drewTopIcon = False if 'body-top' in self.options.cost and not card.isExpansion(): self.drawCost(card, cm / 4.0, totalHeight - usedHeight - 0.5 * cm) @@ -563,11 +642,12 @@ class DividerDrawer(object): totalHeight - usedHeight - 0.5 * cm - 3) Image_x -= 16 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: usedHeight += 15 @@ -578,7 +658,7 @@ class DividerDrawer(object): elif divider_text == "rules": # Add the extra rules text to the divider if card.extra: - descriptions = (card.extra,) + descriptions = (card.extra, ) else: # Asked for rules and they don't exist, so don't print anything return @@ -622,10 +702,16 @@ class DividerDrawer(object): h -= p.height p.drawOn(self.canvas, textHorizontalMargin, h) h -= spacerHeight - + 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,16 +726,19 @@ 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" else: @@ -659,7 +748,7 @@ class DividerDrawer(object): self.drawText(card, divider_text, wrapper=wrap) if self.options.wrapper: self.drawTab(card, rightSide, wrapper="back") - self.drawText(card, divider_text2, wrapper="back") + self.drawText(card, divider_text2, wrapper="back") def drawSetNames(self, pageCards): # print sets for this page @@ -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: @@ -699,11 +789,11 @@ class DividerDrawer(object): return self.canvas.setFont(fontname, fontsize) - + xPos = layout['width'] / 2 # Place at the very edge of the margin yPos = layout['minMarginHeight'] - + sets = [] for c in pageCards: setTitle = c.cardset.title() @@ -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() diff --git a/ez_setup.py b/ez_setup.py deleted file mode 100644 index 50e0dfc..0000000 --- a/ez_setup.py +++ /dev/null @@ -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()) diff --git a/setup.py b/setup.py index 58b135e..83bec3d 100644 --- a/setup.py +++ b/setup.py @@ -23,4 +23,3 @@ setup( author_email="sumpfork@mailmight.net", description="Divider Generation for the Dominion Card Game" ) - diff --git a/tests/carddb_tests.py b/tests/carddb_tests.py index 4e396f8..bd90559 100644 --- a/tests/carddb_tests.py +++ b/tests/carddb_tests.py @@ -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') diff --git a/tests/codestyle_tests.py b/tests/codestyle_tests.py new file mode 100644 index 0000000..e21a283 --- /dev/null +++ b/tests/codestyle_tests.py @@ -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).") diff --git a/tests/layout_tests.py b/tests/layout_tests.py index e643814..83a0f4d 100644 --- a/tests/layout_tests.py +++ b/tests/layout_tests.py @@ -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) - diff --git a/tests/text_tab_tests.py b/tests/text_tab_tests.py index 738c132..bd4f740 100644 --- a/tests/text_tab_tests.py +++ b/tests/text_tab_tests.py @@ -1,6 +1,5 @@ import unittest from .. import domdiv -from reportlab.lib.units import cm class TestTextTabs(unittest.TestCase): @@ -10,11 +9,11 @@ class TestTextTabs(unittest.TestCase): #################### def test_text_tabs_default(self): # should be the default - options, args = domdiv.parse_opts(['commandname']) - self.assertEquals(options.text_front, 'card') - self.assertEquals(options.text_back, 'rules') + options = domdiv.parse_opts([]) + self.assertEquals(options.text_front, 'card') + self.assertEquals(options.text_back, 'rules') self.assertEquals(options.tab_name_align, 'left') - self.assertEquals(options.tab_side, 'right-alternate') + self.assertEquals(options.tab_side, 'right-alternate') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'left') @@ -22,239 +21,280 @@ class TestTextTabs(unittest.TestCase): # Card Text Tests #################### def test_text_card_rules(self): - options, args = domdiv.parse_opts(['commandname', '--front', 'card', '--back', 'rules']) - self.assertEquals(options.text_front, 'card') - self.assertEquals(options.text_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']) - self.assertEquals(options.text_front, 'card') - self.assertEquals(options.text_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']) - self.assertEquals(options.text_front, 'card') - self.assertEquals(options.text_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']) - self.assertEquals(options.text_front, 'card') - self.assertEquals(options.text_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']) - self.assertEquals(options.text_front, 'rules') - self.assertEquals(options.text_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']) - self.assertEquals(options.text_front, 'rules') - self.assertEquals(options.text_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']) - self.assertEquals(options.text_front, 'rules') - self.assertEquals(options.text_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']) - self.assertEquals(options.text_front, 'rules') - self.assertEquals(options.text_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']) - self.assertEquals(options.text_front, 'blank') - self.assertEquals(options.text_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']) - self.assertEquals(options.text_front, 'blank') - self.assertEquals(options.text_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']) - self.assertEquals(options.text_front, 'blank') - self.assertEquals(options.text_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']) - self.assertEquals(options.text_front, 'blank') - self.assertEquals(options.text_back, 'none') + options = domdiv.parse_opts( + ['--front', 'blank', '--back', 'none']) + self.assertEquals(options.text_front, 'blank') + self.assertEquals(options.text_back, 'none') #################### # Card Tab Tests #################### # --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') + self.assertEquals(options.tab_side, 'left') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'left') - self.assertEquals(options.tab_side, 'left') + 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') + self.assertEquals(options.tab_side, 'right') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'left') - self.assertEquals(options.tab_side, 'right') + 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') + self.assertEquals(options.tab_side, 'left-alternate') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'left') - self.assertEquals(options.tab_side, 'left-alternate') + 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') + self.assertEquals(options.tab_side, 'right-alternate') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'left') - self.assertEquals(options.tab_side, 'right-alternate') + 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') + self.assertEquals(options.tab_side, 'full') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'left') - self.assertEquals(options.tab_side, 'full') - - # --tab_name_align right + self.assertEquals(options.tab_side, 'full') + + # --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') + self.assertEquals(options.tab_side, 'left') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'right') - self.assertEquals(options.tab_side, 'left') + 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') + self.assertEquals(options.tab_side, 'right') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'right') - self.assertEquals(options.tab_side, 'right') + 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') + self.assertEquals(options.tab_side, 'left-alternate') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'right') - self.assertEquals(options.tab_side, 'left-alternate') + 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') + self.assertEquals(options.tab_side, 'right-alternate') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'right') - self.assertEquals(options.tab_side, 'right-alternate') + 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') + self.assertEquals(options.tab_side, 'full') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'right') - self.assertEquals(options.tab_side, 'full') + self.assertEquals(options.tab_side, 'full') # --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') + self.assertEquals(options.tab_side, 'left') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'edge') - self.assertEquals(options.tab_side, 'left') + 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') + self.assertEquals(options.tab_side, 'right') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'edge') - self.assertEquals(options.tab_side, 'right') + 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') + self.assertEquals(options.tab_side, 'left-alternate') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'edge') - self.assertEquals(options.tab_side, 'left-alternate') + 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') + self.assertEquals(options.tab_side, 'right-alternate') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'edge') - self.assertEquals(options.tab_side, 'right-alternate') + 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') + 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_side, 'full') - - # --tab_name_align centre + 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') + self.assertEquals(options.tab_side, 'left') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'centre') - self.assertEquals(options.tab_side, 'left') + 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') + self.assertEquals(options.tab_side, 'right') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'centre') - self.assertEquals(options.tab_side, 'right') + 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') + self.assertEquals(options.tab_side, 'left-alternate') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'centre') - self.assertEquals(options.tab_side, 'left-alternate') + 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') + self.assertEquals(options.tab_side, 'right-alternate') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'centre') - self.assertEquals(options.tab_side, 'right-alternate') + 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') + self.assertEquals(options.tab_side, 'full') domdiv.calculate_layout(options) self.assertEquals(options.tab_name_align, 'centre') - self.assertEquals(options.tab_side, 'full') - + self.assertEquals(options.tab_side, 'full') + # --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') + 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_side, 'left') - - + self.assertEquals(options.tab_name_align, + 'centre') # check for change in value + self.assertEquals(options.tab_side, 'left')