#!/usr/bin/env python
##############################################################################
#
# Normalize a Directory Tree Structure
#
##############################################################################

"""
Normalize Tree

This is used to clean up directories that are typically created either by
hand (without knowledge of odd characters in paths), or by automated scripts
that tend to "pack" a lot of information into a file name that may have
unusual formatting.

Call the script using the `--help` argument for usage information.

A simple, complete tree normalization is done with:
    ./ntree.py -fr path/to/odd\ directory\ name

By default, this does *not* attempt to rename files.  Use `-f` to also
normalize file names.

By default, this does *not* attempt to rename the given directory (allowing
you to use it from inside the "current" directory).  Use `-r` to also
normalize the given directory name (may not work if you are "in" that
directory).
"""


import os
import re
import sys


__version__ = '0.0.0'


#=============================================================================
def mktest( path ):
    """
    Builds a test directory structure inside the given path.

    @param path The parent of the new test directory
    """

    # simple tree structure for testing purposes
    tree = {
        'root' : {
            'branch0' : { 'leaf0a.ext' : None, 'leaf0b.ext' : None },
            'branch1' : { 'leaf1a.ext' : None },
            'branch2' : {},
        }
    }

    # messes up a file or directory name, but is still valid
    def mung( name ):