view python/find_duplicate_files.py @ 801:bea4dd61ae45

cleanup
author Jeff Hammel <k0scist@gmail.com>
date Fri, 28 Oct 2016 16:14:10 -0700
parents dbd2562cb03e
children aa9a3850ed56
line wrap: on
line source

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
find duplicate files in a directory
"""

# imports
import argparse
import os
import subprocess
import sys


class DuplicateFilesParser(argparse.ArgumentParser):
    """CLI option parser"""

    def __init__(self, **kwargs):
        kwargs.setdefault('description', __doc__)
        argparse.ArgumentParser.__init__(self, **kwargs)
        self.add_argument('directory')
        self.options = None

    def parse_args(self, *args, **kw):
        options = argparse.ArgumentParser.parse_args(self, *args, **kw)
        self.validate(options)
        self.options = options
        return options

    def validate(self, options):
        """validate options"""
        if not os.path.isdir(options.directory):
            self.error("Not a directory: {}".format(options.directory))


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

    # parse command line options
    parser = DuplicateFilesParser()
    options = parser.parse_args(args)

    # get all files
    raise NotImplementedError('TODO') # -> record TODO items

if __name__ == '__main__':
    main()