def test_formats_drawing_name_one_based_index_and_layer_name(self): f = format_name_as(drawing_number()) assert_that( f.format(drawing_with_name('DrawingName'), 3, layer_with_name('Layer Name')), equal_to('DrawingName-4')) assert_that( f.format(drawing_with_name('Drawing Name'), 3, layer_with_name('LayerName')), equal_to('Drawing Name-4'))
def test_replaces_spaces_with_dashes(self): f = format_name_as(FormatterBuilder(self).with_spaces()) assert_that(f.format(None, 0, None), equal_to("So very much spaces"))
def test_replaces_spaces_with_dashes(self): f = format_name_as(FormatterBuilder(self).lower_case()) assert_that(f.format(None, 0, None), equal_to("namewithcapitals"))
def main(): parser = ArgumentParser(description='''\ Splits up concepts drawing so that each layer is in its own drawing. Works in two modes: 1. Split mode (the default) creates a new drawing for each of the layers in the input drawing. Each of the generated drawings contains only one layer. The name of the drawing (and its file) is the original drawing name and the layer name concatenated. 2. Stacked mode creates a new drawing for each of the layers in the input drawing. Each of the generated drawings contains an incremental number of layers. i.e.: The first drawing contains on layer (the first layer), the second contains the first and the second layer, and so on. The last drawing is the same drawing as the original. The naming scheme of the output drawings is just like the naming scheme in split mode. ''', formatter_class=RawDescriptionHelpFormatter) parser.add_argument('concepts_svg_file', help="path to the the input svg file") parser.add_argument('-v', '--version', help="show version and exit", action='version', version='consplit {}'.format(version)) parser.add_argument('-s', '--stacked', help="use stacked mode", action='store_const', const='_stacked', default='') parser.add_argument('--png', help="create png as output format", action='store_const', const='store_true') formatting_group = parser.add_argument_group('formatting') name_formatting_group = formatting_group.add_mutually_exclusive_group() name_formatting_group.add_argument( '--format-drawing-n-layer', help="format names as <drawing>-<layer-index>-<layer> - the default", action='store_true') name_formatting_group.add_argument( '--format-drawing-layer', help="format names as <drawing>-<layer>", action='store_true') name_formatting_group.add_argument( '--format-drawing-n', help="format names as <drawing>-<layer-index>", action='store_true') formatting_group.add_argument('-l', '--lower-case', help="make file names lower case", action='store_true') formatting_group.add_argument('--allow-spaces', help="does not replace spaces by dashes", action='store_true') args = parser.parse_args() formatter = args.format_drawing_n and drawing_number() or ( args.format_drawing_layer and drawing_layer() or drawing_number_layer()) formatter = args.allow_spaces and formatter.with_spaces( ) or formatter.without_spaces() formatter = args.lower_case and formatter.lower_case() or formatter mode = 'split' + args.stacked repo = SvgRepo() output_repo = args.png and PngRepo() or repo drawing = repo.read(args.concepts_svg_file) for new_drawing in getattr(drawing, mode)(format_name_as(formatter)): output_repo.save(new_drawing, location_of(args.concepts_svg_file))