mirror of
				https://github.com/python-escpos/python-escpos
				synced 2025-10-23 09:30:00 +00:00 
			
		
		
		
	Fix converting of passed bool values properly
This commit is contained in:
		@@ -18,6 +18,13 @@ import sys
 | 
				
			|||||||
import six
 | 
					import six
 | 
				
			||||||
from . import config
 | 
					from . import config
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Must be defined before it's used in DEMO_FUNCTIONS
 | 
				
			||||||
 | 
					def str_to_bool(string):
 | 
				
			||||||
 | 
					    """ Used as a type in argparse so that we get back a proper
 | 
				
			||||||
 | 
					    bool instead of always True
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    return string.lower() in ('y', 'yes', '1', 'true')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# A list of functions that work better with a newline to be sent after them.
 | 
					# A list of functions that work better with a newline to be sent after them.
 | 
				
			||||||
REQUIRES_NEWLINE = ('qr', 'barcode', 'text', 'block_text')
 | 
					REQUIRES_NEWLINE = ('qr', 'barcode', 'text', 'block_text')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -128,7 +135,7 @@ ESCPOS_COMMANDS = [
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                'option_strings': ('--align_ct',),
 | 
					                'option_strings': ('--align_ct',),
 | 
				
			||||||
                'help': 'Align barcode center',
 | 
					                'help': 'Align barcode center',
 | 
				
			||||||
                'type': bool,
 | 
					                'type': str_to_bool,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                'option_strings': ('--function_type',),
 | 
					                'option_strings': ('--function_type',),
 | 
				
			||||||
@@ -249,7 +256,7 @@ ESCPOS_COMMANDS = [
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                'option_strings': ('--histeq',),
 | 
					                'option_strings': ('--histeq',),
 | 
				
			||||||
                'help': 'Equalize the histrogram',
 | 
					                'help': 'Equalize the histrogram',
 | 
				
			||||||
                'type': bool,
 | 
					                'type': str_to_bool,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                'option_strings': ('--bandsize',),
 | 
					                'option_strings': ('--bandsize',),
 | 
				
			||||||
@@ -316,17 +323,17 @@ ESCPOS_COMMANDS = [
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                'option_strings': ('--invert',),
 | 
					                'option_strings': ('--invert',),
 | 
				
			||||||
                'help': 'White on black printing',
 | 
					                'help': 'White on black printing',
 | 
				
			||||||
                'type': bool,
 | 
					                'type': str_to_bool,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                'option_strings': ('--smooth',),
 | 
					                'option_strings': ('--smooth',),
 | 
				
			||||||
                'help': 'Text smoothing. Effective on >:  4x4 text',
 | 
					                'help': 'Text smoothing. Effective on >:  4x4 text',
 | 
				
			||||||
                'type': bool,
 | 
					                'type': str_to_bool,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                'option_strings': ('--flip',),
 | 
					                'option_strings': ('--flip',),
 | 
				
			||||||
                'help': 'Text smoothing. Effective on >:  4x4 text',
 | 
					                'help': 'Text smoothing. Effective on >:  4x4 text',
 | 
				
			||||||
                'type': bool,
 | 
					                'type': str_to_bool,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
        ],
 | 
					        ],
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@@ -381,7 +388,7 @@ ESCPOS_COMMANDS = [
 | 
				
			|||||||
            {
 | 
					            {
 | 
				
			||||||
                'option_strings': ('--enable',),
 | 
					                'option_strings': ('--enable',),
 | 
				
			||||||
                'help': 'Feed button enabled',
 | 
					                'help': 'Feed button enabled',
 | 
				
			||||||
                'type': bool,
 | 
					                'type': str_to_bool,
 | 
				
			||||||
                'required': True,
 | 
					                'required': True,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
        ],
 | 
					        ],
 | 
				
			||||||
@@ -418,6 +425,8 @@ def main():
 | 
				
			|||||||
        'file. See documentation for details.',
 | 
					        'file. See documentation for details.',
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    parser.register('type', 'bool', str_to_bool)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Allow config file location to be passed
 | 
					    # Allow config file location to be passed
 | 
				
			||||||
    parser.add_argument(
 | 
					    parser.add_argument(
 | 
				
			||||||
        '-c', '--config',
 | 
					        '-c', '--config',
 | 
				
			||||||
@@ -469,7 +478,7 @@ def main():
 | 
				
			|||||||
    if not args_dict:
 | 
					    if not args_dict:
 | 
				
			||||||
        parser.print_help()
 | 
					        parser.print_help()
 | 
				
			||||||
        sys.exit()
 | 
					        sys.exit()
 | 
				
			||||||
    command_arguments = dict([k, v] for k, v in six.iteritems(args_dict) if v)
 | 
					    command_arguments = dict([k, v] for k, v in six.iteritems(args_dict) if v is not None)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # If there was a config path passed, grab it
 | 
					    # If there was a config path passed, grab it
 | 
				
			||||||
    config_path = command_arguments.pop('config', None)
 | 
					    config_path = command_arguments.pop('config', None)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user