def parse_args(args=None):
    """Parses arguments, returns (options, args)."""

    if args is None:
        args = sys.argv

    parser = ArgumentParser(description='Barcode scanner based on GStreamer, '
                            'zbar, and gtk.')
    log_levels = ('critical', 'error', 'warning', 'info', 'debug', 'notset')

    parser.add_argument('-l', '--log-level', type=str, choices=log_levels,
                        default='info')
    parser.add_argument('-d', '--device-name', type=str, help='GStreamer video'
                        ' device name')
    parser.add_argument('-w', '--max-width', type=int,
                        help='Maximum video width')
    parser.add_argument('-f', '--max-fps', type=float, help='Maximum video '
                        'frame rate (frames/second)')
    parser.add_argument('schema', type=str, help='jsonschema schema')

    args = parser.parse_args()
    if hasattr(args, 'log_level'):
        args.log_level = getattr(logging, args.log_level.upper())
    return args