# Path: format_sql/parser.py
# class InvalidSQL(Exception):
#     pass
# 
# Path: format_sql/shortcuts.py
# def format_sql(s, debug=False):
#     tokens = list(tokenize(s))
#     if debug:
#         print_non_data('Tokens: %s' % tokens)
#     parsed = list(parse(tokens))
#     if debug:
#         print_non_data('Statements: %s' % parsed)
#     styled = style(parsed)
#     if debug:
#         print_non_data('Output: %s' % styled)
#     return styled
# 
# Path: format_sql/util.py
# def print_data(msg):
#     print(msg)
# 
# def print_non_data(msg):
#     print(msg, file=sys.stderr)


import os
import re
import sys
from argparse import ArgumentParser
from glob import glob
from format_sql.parser import InvalidSQL
from format_sql.shortcuts import format_sql
from format_sql.util import print_data, print_non_data

    return args


def _get_filenames(paths, recursive):
    filenames = set()
    for path in paths:
        path = os.path.abspath(path)
        if os.path.isfile(path):
            filenames.add(path)
        elif os.path.isdir(path):
            if recursive:
                for dirpath, dirnames, fnames in os.walk(path):
                    filenames.update(os.path.join(dirpath, fn)
                                     for fn in fnames)
            else:
                if not path.endswith('/'):
                    path += '/'
                filenames.update(glob('%s*' % path))
    return filenames


def main(args=sys.argv[1:]):
    args = _get_args(args)
    filenames = _get_filenames(args.paths, args.recursive)

    if args.types:
        filenames = filter(lambda fn: fn.endswith(tuple(args.types)), filenames)

    for filename in filenames:

# Path: format_sql/parser.py
# class InvalidSQL(Exception):
#     pass
# 
# Path: format_sql/shortcuts.py
# def format_sql(s, debug=False):
#     tokens = list(tokenize(s))
#     if debug:
#         print_non_data('Tokens: %s' % tokens)
#     parsed = list(parse(tokens))
#     if debug:
#         print_non_data('Statements: %s' % parsed)
#     styled = style(parsed)
#     if debug:
#         print_non_data('Output: %s' % styled)
#     return styled
# 
# Path: format_sql/util.py
# def print_data(msg):
#     print(msg)
# 
# def print_non_data(msg):
#     print(msg, file=sys.stderr)


# Path: format_sql/main.py
import os
import re
import sys
from argparse import ArgumentParser
from glob import glob
from format_sql.parser import InvalidSQL
from format_sql.shortcuts import format_sql
from format_sql.util import print_data, print_non_data


    return args


def _get_filenames(paths, recursive):
    filenames = set()
    for path in paths:
        path = os.path.abspath(path)
        if os.path.isfile(path):
            filenames.add(path)
        elif os.path.isdir(path):
            if recursive:
                for dirpath, dirnames, fnames in os.walk(path):
                    filenames.update(os.path.join(dirpath, fn)
                                     for fn in fnames)
            else:
                if not path.endswith('/'):
                    path += '/'
                filenames.update(glob('%s*' % path))
    return filenames


def main(args=sys.argv[1:]):
    args = _get_args(args)
    filenames = _get_filenames(args.paths, args.recursive)

    if args.types:
        filenames = filter(lambda fn: fn.endswith(tuple(args.types)), filenames)

    for filename in filenames:

        print_non_data(filename)