def cat(args):
    p = OptionParser(cat.__doc__.format(page_range_help=PAGE_RANGE_HELP))
    p.add_option("--nosort", default=False, action="store_true",
                 help="Do not sort file names")
    p.set_outfile()
    p.set_verbose(help="Show page ranges as they are being read")
    opts, args = p.parse_args(args)

    if len(args) < 1:
        sys.exit(not p.print_help())

    outfile = opts.outfile
    if outfile in args:
        args.remove(outfile)

    if not opts.nosort:
        args = natsorted(args)

    filename_page_ranges = parse_filename_page_ranges(args)
    verbose = opts.verbose
    fw = must_open(outfile, "wb")

    merger = PdfFileMerger()
    in_fs = {}
    try:
        for (filename, page_range) in filename_page_ranges:
            if verbose:
                print >> sys.stderr, filename, page_range
            if filename not in in_fs:
                in_fs[filename] = open(filename, "rb")
            merger.append(in_fs[filename], pages=page_range)
    except:
        print >> sys.stderr, traceback.format_exc()
        print >> sys.stderr, "Error while reading " + filename
        sys.exit(1)
    merger.write(fw)
    fw.close()
%prog cat *.pdf -o output.pdf
dataset/ETHPy150Open tanghaibao/jcvi/formats/pdf.py/cat