# Path: distance_scripts/_common.py
# def get_cache_filename(filename):
#     return os.path.join(CACHE_PATH, filename)
# 
# def handle_pipeerror(func):
#     def result(*args, **kw):
#         try:
#             return func(*args, **kw)
#         except BrokenPipeError:
#             return 1
#     result.__name__ = func.__name__
#     result.__doc__ = func.__doc__
#     result.__wrapped__ = func
#     return result


import sys
import argparse
import sqlite3
import re
from ._common import get_cache_filename, handle_pipeerror



def format_bytes(data):
    return ' '.join(b.__format__('02x') for b in data)


def format_col(col):
    if isinstance(col, bytes):
        return format_bytes(col)
    else:
        return repr(col)


@handle_pipeerror
def main():
    parser = argparse.ArgumentParser(
        description=__doc__)
    parser.add_argument("--db", help="map database filename.")
    parser.add_argument("--stdin-paths", action='store_true',
                        help="filter by path read from stdin.")
    parser.add_argument("--cols", help='comma-separated list of columns')
    parser.add_argument("--ids", action='store_true',
                        help="print IDs of matching levels.")
    parser.add_argument("--where", nargs='*', metavar=('COND', 'ARG'),
                        help="specify WHERE clause.")
    parser.add_argument("--order-by", help="specify ORDER BY clause.")
    args = parser.parse_args()

    if not args.db:

# Path: distance_scripts/_common.py
# def get_cache_filename(filename):
#     return os.path.join(CACHE_PATH, filename)
# 
# def handle_pipeerror(func):
#     def result(*args, **kw):
#         try:
#             return func(*args, **kw)
#         except BrokenPipeError:
#             return 1
#     result.__name__ = func.__name__
#     result.__doc__ = func.__doc__
#     result.__wrapped__ = func
#     return result


# Path: distance_scripts/querymaps.py
import sys
import argparse
import sqlite3
import re
from ._common import get_cache_filename, handle_pipeerror




def format_bytes(data):
    return ' '.join(b.__format__('02x') for b in data)


def format_col(col):
    if isinstance(col, bytes):
        return format_bytes(col)
    else:
        return repr(col)


@handle_pipeerror
def main():
    parser = argparse.ArgumentParser(
        description=__doc__)
    parser.add_argument("--db", help="map database filename.")
    parser.add_argument("--stdin-paths", action='store_true',
                        help="filter by path read from stdin.")
    parser.add_argument("--cols", help='comma-separated list of columns')
    parser.add_argument("--ids", action='store_true',
                        help="print IDs of matching levels.")
    parser.add_argument("--where", nargs='*', metavar=('COND', 'ARG'),
                        help="specify WHERE clause.")
    parser.add_argument("--order-by", help="specify ORDER BY clause.")
    args = parser.parse_args()

    if not args.db:

        args.db = get_cache_filename('data.db')