view python/applyrealhard.py @ 741:9681a0bd74d6

add utility for slicing video files
author Jeff Hammel <k0scist@gmail.com>
date Sun, 28 Jun 2015 11:56:13 -0700
parents c4432bd3cb9b
children
line wrap: on
line source

#!/usr/bin/env python

# XXX STUB

"""
http://code.google.com/p/python-patch/
"""

import difflib
import optparse
import os
import subprocess
import sys
from which import which

here = os.path.dirname(os.path.realpath(__file__))

wiggle = which('wiggle')

def find(directory, pattern):
    # TODO: -> python
    return [i for i in subprocess.check_output(['find', directory, '-iname', pattern]).splitlines() if i.strip()]

def rejects(directory):
    """all rejects in directory"""
    # TODO: not call out to find
    return find(directory, '*.rej')

def main(args=sys.argv[1:]):

    # parse command line args
    usage = '%prog [options]'
    parser = optparse.OptionParser(usage=usage, description=__doc__)
    parser.add_option('-d', '--directory', default=os.getcwd())
    options, args = parser.parse_args(args)

    # sanity check
    if not wiggle:
        parser.error("Need wiggle")

    # get rejects
    rej = rejects(options.directory)
    if not rej:
        parser.error("No rejects")
    print 'rej:\n%s\n' % '\n'.join([' %s' % r for r in rej])

    # get the originals
    orig = []
    for r in rej:
        # find the corresponding file
        o = r.rsplit('.rej')[0]
        if not os.path.exists(o):
            parser.error("%s not found")
        orig.append(o)

    # try to wiggle them

if __name__ == '__main__':
    main()