|
3 | 3 | from __future__ import print_function |
4 | 4 |
|
5 | 5 | import os |
6 | | -import sys |
7 | 6 |
|
8 | 7 | import barcode |
9 | 8 |
|
@@ -42,61 +41,74 @@ def list_types(args, parser=None): |
42 | 41 | def create_barcode(args, parser): |
43 | 42 | args.type = args.type.upper() |
44 | 43 | if args.type != 'SVG' and args.type not in IMG_FORMATS: |
45 | | - parser.error('Unknown type {type}. Try list action for available ' |
46 | | - 'types.'.format(type=args.type)) |
| 44 | + parser.error( |
| 45 | + 'Unknown type {type}. Try list action for available ' |
| 46 | + 'types.'.format(type=args.type) |
| 47 | + ) |
47 | 48 | args.barcode = args.barcode.lower() |
48 | 49 | if args.barcode not in barcode.PROVIDED_BARCODES: |
49 | | - parser.error('Unknown barcode {bc}. Try list action for available ' |
50 | | - 'barcodes.'.format(bc=args.barcode)) |
| 50 | + parser.error( |
| 51 | + 'Unknown barcode {bc}. Try list action for available ' |
| 52 | + 'barcodes.'.format(bc=args.barcode) |
| 53 | + ) |
51 | 54 | if args.type != 'SVG': |
52 | 55 | opts = dict(format=args.type) |
53 | 56 | writer = ImageWriter() |
54 | 57 | else: |
55 | 58 | opts = dict(compress=args.compress) |
56 | 59 | writer = SVGWriter() |
57 | 60 | out = os.path.normpath(os.path.abspath(args.output)) |
58 | | - name = barcode.generate(args.barcode, args.code, writer, out, opts) |
| 61 | + name = barcode.generate(args.barcode, args.code, writer, out, opts, |
| 62 | + args.text) |
59 | 63 | print('New barcode saved as {0}.'.format(name)) |
60 | 64 |
|
61 | 65 |
|
62 | 66 | def main(): |
63 | 67 | msg = [] |
64 | 68 | if ImageWriter is None: |
65 | | - msg.append('Image output disabled (PIL not found), --type option ' |
66 | | - 'disabled.') |
| 69 | + msg.append( |
| 70 | + 'Image output disabled (PIL not found), --type option disabled.' |
| 71 | + ) |
67 | 72 | else: |
68 | | - msg.append('Image output enabled, use --type option to give image ' |
69 | | - 'format (png, jpeg, ...).') |
| 73 | + msg.append( |
| 74 | + 'Image output enabled, use --type option to give image ' |
| 75 | + 'format (png, jpeg, ...).' |
| 76 | + ) |
70 | 77 | if QtCore is None: |
71 | 78 | msg.append('PyQt not found, gui action disabled.') |
72 | 79 | else: |
73 | 80 | msg.append('PyQt found. Use gui action to get a simple GUI.') |
74 | | - parser = ArgumentParser(description=barcode.__description__, |
75 | | - epilog=' '.join(msg)) |
| 81 | + parser = ArgumentParser( |
| 82 | + description=barcode.__description__, epilog=' '.join(msg) |
| 83 | + ) |
76 | 84 | parser.add_argument('-v', '--version', action='version', |
77 | | - version='%(prog)s ' + barcode.__release__) |
| 85 | + version='%(prog)s ' + barcode.__release__) |
78 | 86 | subparsers = parser.add_subparsers(title='Actions') |
79 | 87 | create_parser = subparsers.add_parser('create', help='Create a barcode ' |
80 | | - 'with the given options.') |
| 88 | + 'with the given options.') |
81 | 89 | create_parser.add_argument('code', help='Code to render as barcode.') |
82 | 90 | create_parser.add_argument('output', help='Filename for output ' |
83 | | - 'without extension, e. g. mybarcode.') |
84 | | - create_parser.add_argument('-c', '--compress', action='store_true', |
85 | | - help='Compress output, only recognized if type is svg.') |
| 91 | + 'without extension, e. g. mybarcode.') |
| 92 | + create_parser.add_argument( |
| 93 | + '-c', '--compress', action='store_true', |
| 94 | + help='Compress output, only recognized if type is svg.' |
| 95 | + ) |
86 | 96 | create_parser.add_argument('-b', '--barcode', help='Barcode to use ' |
87 | | - '[default: %(default)s].') |
| 97 | + '[default: %(default)s].') |
| 98 | + create_parser.add_argument('--text', help='Text to show under the ' |
| 99 | + 'barcode.') |
88 | 100 | if ImageWriter is not None: |
89 | 101 | create_parser.add_argument('-t', '--type', help='Type of output ' |
90 | | - '[default: %(default)s].') |
| 102 | + '[default: %(default)s].') |
91 | 103 | list_parser = subparsers.add_parser('list', help='List available ' |
92 | | - 'image and code types.') |
| 104 | + 'image and code types.') |
93 | 105 | list_parser.set_defaults(func=list_types) |
94 | 106 | if QtCore is not None: |
95 | 107 | gui_parser = subparsers.add_parser('gui', help='Opens a simple ' |
96 | | - 'PyQt GUI to create barcodes.') |
| 108 | + 'PyQt GUI to create barcodes.') |
97 | 109 | gui_parser.set_defaults(func=open_gui) |
98 | 110 | create_parser.set_defaults(type='svg', compress=False, func=create_barcode, |
99 | | - barcode='code39') |
| 111 | + barcode='code39', text=None) |
100 | 112 | args = parser.parse_args() |
101 | 113 | args.func(args, parser) |
102 | 114 |
|
|
0 commit comments