#!/usr/bin/env python3
#
# (c) 2017-2020 Fetal-Neonatal Neuroimaging & Developmental Science Center
#                     Boston Children's Hospital
#
#                http://childrenshospital.org/FNNDSC/
#                         dev@babyMRI.org
#

import  sys, os
sys.path.insert(1, os.path.join(os.path.dirname(__file__), '..'))

import  socket
from    argparse                import RawTextHelpFormatter
from    argparse                import ArgumentParser

import  pudb
from    pfmisc import Colors, pfmisc, pfmisc2, local_ip_address
from    pfmisc import C_snode

str_defIP = local_ip_address()
str_version = "2.2.10"
str_desc = Colors.CYAN + r"""


        __           _          
       / _|         (_)         
 _ __ | |_ _ __ ___  _ ___  ___ 
| '_ \|  _| '_ ` _ \| / __|/ __|
| |_) | | | | | | | | \__ \ (__ 
| .__/|_| |_| |_| |_|_|___/\___|
| |                             
|_|                             


                              Path-File-misc

                Miscellaneous utilities for the pf* family.

                              -- version """ + \
             Colors.YELLOW + str_version + Colors.CYAN + """ --

    'pfmisc' is a simple example script of how to use the various family
    of miscellaneous help utilties (typically the debug utility) in misc
    settings.

""" + Colors.NO_COLOUR

def tree_build():
    aTree   = C_snode.C_stree()
    aTree.cd('/')
    aTree.mkcd('a')
    aTree.mknode(['b', 'c'])
    aTree.cd('b')
    aTree.touch('file1', 10)
    aTree.touch('file2', "Rudolph Pienaar")
    aTree.touch('file3', ['this', 'is', 'a', 'list'])
    aTree.touch('file4', ('this', 'is', 'a', 'tuple'))
    aTree.touch('file5', {'name': 'rudolph', 'address': '505 Washington'})

    aTree.mknode(['d', 'e'])
    aTree.cd('d')
    aTree.mknode(['h', 'i'])
    aTree.cd('/a/b/e')
    aTree.mknode(['j', 'k'])
    aTree.cd('/a/c')
    aTree.mknode(['f', 'g'])
    aTree.cd('f')
    aTree.mknode(['l', 'm'])
    aTree.cd('/a/c/g')
    aTree.mknode(['n', 'o'])
    return aTree

parser  = ArgumentParser(description = str_desc, formatter_class = RawTextHelpFormatter)

parser.add_argument(
    '--test',
    help    = 'if specified, perform internal tests',
    dest    = 'b_test',
    action  = 'store_true',
    default = False
)
parser.add_argument(
    '--version',
    help    = 'if specified, print version number',
    dest    = 'b_version',
    action  = 'store_true',
    default = False
)

args            = parser.parse_args()

if args.b_version:
    print("Version: %s" % str_version)
    sys.exit(1)

print(str_desc)

T = tree_build()
print("T = %s" % T)

d_t = {
    "root" : {
        "dir1" : {
            "one":  "First",
            "two":  "Second"
        }
    }
}
dT              = C_snode.C_stree()
dT.initFromDict(d_t)
print("dT = %s" % dT)

example         = pfmisc()
example2        = pfmisc2()

print("*********************** using classes from module file 'pfmisc.py' *****")
example.demo()

print("\n")
print("*********************** using classes from module file 'pfmisc2.py' *****")
example2.demo()

