def main():
    parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('input', help='Relative or absolute path of the input PDF file')
    parser.add_argument('-o', '--out', help='Relative or absolute path of the output PDF file')
    parser.add_argument('-c', '--compress', type=int, help='Compression level from 0 to 4')
    parser.add_argument('-b', '--backup', action='store_true', help='Backup the old PDF file')
    parser.add_argument('--open', action='store_true', default=False, help='Open PDF after compression')
    args = parser.parse_args()
    if (not args.compress):
        args.compress = 2
    if (not args.out):
        args.out = 'temp.pdf'
    compress(args.input, args.out, power=args.compress)
    if (args.out == 'temp.pdf'):
        if args.backup:
            shutil.copyfile(args.input, args.input.replace('.pdf', '_BACKUP.pdf'))
        shutil.copyfile(args.out, args.input)
        os.remove(args.out)
    if args.open:
        if ((args.out == 'temp.pdf') and args.backup):
            subprocess.call(['open', args.input])
        else:
            subprocess.call(['open', args.out])
def main():
    parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('input', help='Relative or absolute path of the input PDF file')
    parser.add_argument('-o', '--out', help='Relative or absolute path of the output PDF file')
    parser.add_argument('-c', '--compress', type=int, help='Compression level from 0 to 4')
    parser.add_argument('-b', '--backup', action='store_true', help='Backup the old PDF file')
    parser.add_argument('--open', action='store_true', default=False, help='Open PDF after compression')
    args = parser.parse_args()
    if (not args.compress):
        args.compress = 2
    if (not args.out):
        args.out = 'temp.pdf'
    compress(args.input, args.out, power=args.compress)
    if (args.out == 'temp.pdf'):
        if args.backup:
            shutil.copyfile(args.input, args.input.replace('.pdf', '_BACKUP.pdf'))
        shutil.copyfile(args.out, args.input)
        os.remove(args.out)
    if args.open:
        if ((args.out == 'temp.pdf') and args.backup):
            subprocess.call(['open', args.input])
        else:
            subprocess.call(['open', args.out])